File: CMakeLists.txt

package info (click to toggle)
svxlink 15.11-2
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 14,296 kB
  • ctags: 7,558
  • sloc: cpp: 48,996; tcl: 3,273; ansic: 2,831; sh: 1,054; perl: 335; ruby: 160; makefile: 96
file content (318 lines) | stat: -rw-r--r-- 11,344 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
##############################################################################
# SvxLink - A Multi Purpose Voice Services System for Ham Radio Use
# Copyright (C) 2003-2013 Tobias Blomberg / SM0SVX
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##############################################################################

##############################################################################
# Project setup
##############################################################################
cmake_minimum_required(VERSION 2.8)
project(svxlink C CXX)
#enable_testing()

# The path to the project global include directory
set(PROJECT_INCLUDE_DIR ${PROJECT_BINARY_DIR}/include)

# Where to put library files
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

# Where to put executable files
set(RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

# Add project local CMake module directory
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Optional parts
option(USE_QT "Build Qt applications and libs" ON)
option(BUILD_STATIC_LIBS "Build static libraries in addition to dynamic" ON)

# The sample rate used internally in SvxLink
if(NOT DEFINED INTERNAL_SAMPLE_RATE)
  set(INTERNAL_SAMPLE_RATE 16000)
endif(NOT DEFINED INTERNAL_SAMPLE_RATE)
add_definitions(-DINTERNAL_SAMPLE_RATE=${INTERNAL_SAMPLE_RATE})

# Set up include directories
include_directories(
  ${PROJECT_INCLUDE_DIR}
  ${CMAKE_BINARY_DIR}
)

set(CMAKE_VERBOSE_MAKEFILE on)

##############################################################################
# Install targets properties setup
##############################################################################

# Set up standard GNU installation directories
include(GNUInstallDirs)

set(SYSCONF_INSTALL_DIR /etc)
set(LOCAL_STATE_DIR /var)

# Where to install include files
if(NOT DEFINED INCLUDE_INSTALL_DIR)
  #set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include)
  set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR})
endif(NOT DEFINED INCLUDE_INSTALL_DIR)

# Where to install libraries
if(NOT DEFINED LIB_INSTALL_DIR)
  #set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
  set(LIB_INSTALL_DIR ${CMAKE_INSTALL_FULL_LIBDIR})
endif(NOT DEFINED LIB_INSTALL_DIR)

# The config directory (normally /etc)
if(NOT DEFINED SYSCONF_INSTALL_DIR)
  #set(SYSCONF_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/etc)
  set(SYSCONF_INSTALL_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR})
endif(NOT DEFINED SYSCONF_INSTALL_DIR)

# Architecture independent files directory (normally /usr/share)
if(NOT DEFINED SHARE_INSTALL_PREFIX)
  #set(SHARE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/share)
  set(SHARE_INSTALL_PREFIX ${CMAKE_INSTALL_FULL_DATADIR})
endif(NOT DEFINED SHARE_INSTALL_PREFIX)

# Local state directory (normally /var)
if(NOT DEFINED LOCAL_STATE_DIR)
  #set(LOCAL_STATE_DIR ${CMAKE_INSTALL_PREFIX}/var)
  set(LOCAL_STATE_DIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR})
endif(NOT DEFINED LOCAL_STATE_DIR)

# Where to install executables
if(NOT DEFINED BIN_INSTALL_DIR)
  #set(BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
  set(BIN_INSTALL_DIR ${CMAKE_INSTALL_FULL_BINDIR})
endif(NOT DEFINED BIN_INSTALL_DIR)

# Where to install manual pages
if(NOT DEFINED MAN_INSTALL_DIR)
  #set(MAN_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/man)
  set(MAN_INSTALL_DIR ${CMAKE_INSTALL_FULL_MANDIR})
endif(NOT DEFINED MAN_INSTALL_DIR)

# Where to install documentation
if(NOT DEFINED DOC_INSTALL_DIR)
  #set(DOC_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/doc/svxlink)
  set(DOC_INSTALL_DIR ${CMAKE_INSTALL_FULL_DOCDIR})
endif(NOT DEFINED DOC_INSTALL_DIR)

# Where to install startup scripts
if(NOT DEFINED INIT_D_INSTALL_DIR)
  set(INIT_D_INSTALL_DIR ${SYSCONF_INSTALL_DIR}/init.d)
endif(NOT DEFINED INIT_D_INSTALL_DIR)

# Where to install SvxLink config files
if(NOT DEFINED SVX_SYSCONF_INSTALL_DIR)
  set(SVX_SYSCONF_INSTALL_DIR ${SYSCONF_INSTALL_DIR}/svxlink)
endif(NOT DEFINED SVX_SYSCONF_INSTALL_DIR)

# Where to install SvxLink spool files
if(NOT DEFINED SVX_SPOOL_INSTALL_DIR)
  set(SVX_SPOOL_INSTALL_DIR ${LOCAL_STATE_DIR}/spool/svxlink)
endif(NOT DEFINED SVX_SPOOL_INSTALL_DIR)

# Where to install SvxLink architecture independent files
if(NOT DEFINED SVX_SHARE_INSTALL_DIR)
  set(SVX_SHARE_INSTALL_DIR ${SHARE_INSTALL_PREFIX}/svxlink)
endif(NOT DEFINED SVX_SHARE_INSTALL_DIR)

# Where to install include files
if(NOT DEFINED SVX_INCLUDE_INSTALL_DIR)
  set(SVX_INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/svxlink)
endif(NOT DEFINED SVX_INCLUDE_INSTALL_DIR)

# Where to install SvxLink modules
if(NOT DEFINED SVX_MODULE_INSTALL_DIR)
  set(SVX_MODULE_INSTALL_DIR ${LIB_INSTALL_DIR}/svxlink)
endif(NOT DEFINED SVX_MODULE_INSTALL_DIR)


##############################################################################
# Functions
##############################################################################

# Create an include file under the global include directory
function(expinc filename)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${filename}
    ${PROJECT_INCLUDE_DIR}/${filename}
    COPYONLY
    )
endfunction(expinc)

# Add a target for building a version/xyz.h file
#
#   add_version_target(name [depends_var])
#
# The name of the version variable should be VER_name and the versions file
# will be named versions/name.h.
# If depends_var is given it will be set to a list of dependencies that the
# target using the versions file should add to its dependency list.
function(add_version_target name)
  set(depends_var ${ARGV1})
  if(DEFINED depends_var)
    set(${depends_var} ${${depends_var}}
      "${PROJECT_INCLUDE_DIR}/version/${name}.h"
      PARENT_SCOPE
      )
  endif(DEFINED depends_var)

  if(VER_${name})
    set(VERSION ${VER_${name}})
  else(VER_${name})
    set(VERSION "?.?.?")
  endif(VER_${name})

  add_custom_command(
    OUTPUT ${PROJECT_INCLUDE_DIR}/version/${name}.h
    WORKING_DIRECTORY ${PROJECT_INCLUDE_DIR}
    COMMAND ${CMAKE_COMMAND} -DVER_NAME=${name} -DVER_VALUE=${VERSION} 
                     -P ${CMAKE_SOURCE_DIR}/cmake/create_version_include.cmake
    DEPENDS ${CMAKE_SOURCE_DIR}/versions
            ${CMAKE_SOURCE_DIR}/cmake/create_version_include.cmake
  )
endfunction(add_version_target)

# Read a versions file and set up CMake variables for each entry
function(read_versions_file filename)
  message(STATUS "Reading versions file...")
  file(STRINGS ${filename} versions REGEX .*=.*)
  foreach(version ${versions})
    string(REGEX REPLACE \(.*\)=\(.*\) "VER_\\1;\\2" version ${version})
    set(${version} PARENT_SCOPE)
    if(version MATCHES ^VER_LIB)
      list(GET version 0 varname)
      list(GET version 1 varvalue)
      string(REGEX MATCH [0-9]+\\.[0-9]+ ${varname}_SOVERSION ${varvalue})
      set(${varname}_SOVERSION ${${varname}_SOVERSION} PARENT_SCOPE)
    endif(version MATCHES ^VER_LIB)
  endforeach(version)
endfunction(read_versions_file)

# Create a post install target to change the owner of an installed file.
# If DO_INSTALL_CHOWN is set to YES, the owner will be changed during
# installation.
# If DO_INSTALL_CHOWN is unset, the DESTDIR environment variable will be
# examined. If it is set, no chown operations will be performed since we are
# probably not running as a user with administrative rights. If DESTDIR is
# unset, chown operations are performed.
function(install_chown filename owner)
  if(owner)
    set(chown_commands "
      set(CHOWN_TOOL ${CHOWN_TOOL})
      if(NOT CHOWN_TOOL)
        MESSAGE(FATAL_ERROR \"Unable to find the 'chown' utility\")
      endif(NOT CHOWN_TOOL)
      set(full_filename \"\$ENV{DESTDIR}${filename}\")
      message(STATUS \"Setting owner of \${full_filename} to ${owner}...\")
      execute_process(
        COMMAND ${CHOWN_TOOL} ${owner} \"\${full_filename}\"
        RESULT_VARIABLE cmd_result
        )
      if(NOT \${cmd_result} EQUAL 0)
        MESSAGE(FATAL_ERROR
          \"Error while changing owner of file \${full_filename}\"
          )
      endif(NOT \${cmd_result} EQUAL 0)
      ")
    if(DEFINED DO_INSTALL_CHOWN)
      if(DO_INSTALL_CHOWN)
        install(CODE "${chown_commands}")
      endif(DO_INSTALL_CHOWN)
    else(DEFINED DO_INSTALL_CHOWN)
      install(CODE "
        if(\"\$ENV{DESTDIR}\" STREQUAL \"\")
          ${chown_commands}
        endif(\"\$ENV{DESTDIR}\" STREQUAL \"\")
        ")
    endif(DEFINED DO_INSTALL_CHOWN)
  endif(owner)
endfunction(install_chown)

# Create the given directory during installation
#   install_mkdir(directory [owner])
function(install_mkdir dir)
  set(owner ${ARGV1})
  get_filename_component(parent ${dir} PATH)
  file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}${dir})
  install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}${dir} DESTINATION ${parent})
  install_chown(${dir} "${owner}")
endfunction(install_mkdir)

# Before installing the file, check if it exists. If it does, don't
# overwrite it.
#   install_if_not_exists(source_file destination_directory)
function(install_if_not_exists src dest)
  if(NOT IS_ABSOLUTE "${src}")
    set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
  endif()
  get_filename_component(src_name "${src}" NAME)
  if (NOT IS_ABSOLUTE "${dest}")
    set(dest "${CMAKE_INSTALL_PREFIX}/${dest}")
  endif()
  install(CODE "
    if(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\")
      #file(INSTALL \"${src}\" DESTINATION \"${dest}\")
      message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\")
      execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\"
                      \"\$ENV{DESTDIR}${dest}/${src_name}\"
                      RESULT_VARIABLE copy_result
                      ERROR_VARIABLE error_output)
      if(copy_result)
        message(FATAL_ERROR \${error_output})
      endif()
    else()
      message(STATUS \"Skipping  : \$ENV{DESTDIR}${dest}/${src_name}\")
    endif()
  ")
endfunction(install_if_not_exists)


##############################################################################
# Main execution starts here
##############################################################################

# Load the versions file and define version variables
read_versions_file(${PROJECT_SOURCE_DIR}/versions)

configure_file(${CMAKE_SOURCE_DIR}/config.h.in
  ${CMAKE_BINARY_DIR}/config.h
  @ONLY
  )

# Find the Sigc++ library
find_package(SIGC2 REQUIRED)
include_directories(${SIGC2_INCLUDE_DIRS})
add_definitions(${SIGC2_DEFINITIONS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIGC2_CXX_FLAGS}")
set(LIBS ${LIBS} ${SIGC2_LIBRARIES})

# Find the chown utility
include(FindCHOWN)

# Add directories to build
add_subdirectory(async)
add_subdirectory(misc)
add_subdirectory(echolib)
add_subdirectory(locationinfo)
add_subdirectory(svxlink)
if(USE_QT)
  add_subdirectory(qtel)
endif(USE_QT)
add_subdirectory(doc)