-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
443 lines (379 loc) · 15 KB
/
CMakeLists.txt
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# If you want built-in precompiled header support
# then make sure you have cmake 3.16 or higher.
#
# Minimum required is 3.15 due to use of multiple values in
# generator expressions.
cmake_minimum_required( VERSION 3.15 )
# Don't allow in-source builds...no real reason, just
# keeping those source trees nice and tidy. :-)
# (This can be removed if it becomes an issue.)
if( "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}" )
message( FATAL_ERROR
"In-source builds not allowed.\n"
"Create a new directory and run cmake from there, i.e.:\n"
" mkdir build\n"
" cd build\n"
" cmake ..\n"
"You will need to delete CMakeCache.txt and CMakeFiles from this directory to clean up."
)
endif()
# Just a couple of convenience variables
set( topdir "${CMAKE_SOURCE_DIR}" )
set( libsrc "${topdir}/lib-src" )
# Default build type is Debug
if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
set( CMAKE_BUILD_TYPE "Debug" )
endif()
# Ignore COMPILE_DEFINITIONS_<Config> properties
cmake_policy( SET CMP0043 NEW )
# Link libraries by full path even in implicit directories.
cmake_policy( SET CMP0060 NEW )
# ``INTERPROCEDURAL_OPTIMIZATION`` is enforced when enabled.
cmake_policy( SET CMP0069 NEW )
# ``FindOpenGL`` prefers GLVND by default when available.
cmake_policy( SET CMP0072 NEW )
# Include file check macros honor ``CMAKE_REQUIRED_LIBRARIES``.
cmake_policy( SET CMP0075 NEW )
# Definitions that must happen before the project() command
if( APPLE )
# Generate schema files
set( CMAKE_XCODE_GENERATE_SCHEME ON )
# Define the OSX compatibility parameters
set( CMAKE_OSX_ARCHITECTURES x86_64 CACHE INTERNAL "" )
set( CMAKE_OSX_DEPLOYMENT_TARGET 10.7 CACHE INTERNAL "" )
set( CMAKE_OSX_SYSROOT macosx CACHE INTERNAL "" )
set( CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" CACHE INTERNAL "" )
# This prevents a link error when building with the 10.9 or older SDKs
set( CMAKE_XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME OFF )
# Shouldn't cmake do this???
string( APPEND CMAKE_CXX_FLAGS " -stdlib=libc++" )
endif()
# Add our module path
set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake-proxies/cmake-modules)
# This "is a good thing" but greatly increases link time on Linux
#set( CMAKE_INTERPROCEDURAL_OPTIMIZATION ON )
#set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON )
#set( CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF )
# Set the required C++ standard
set( CMAKE_CXX_STANDARD 14 )
set( CMAKE_CXX_STANDARD_REQUIRED ON )
# Use ccache if available
find_program( CCACHE_PROGRAM ccache )
mark_as_advanced( FORCE CCACHE_PROGRAM )
if( CCACHE_PROGRAM )
set_property( GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}" )
endif()
# Our very own project
project( Audacity )
# Load our functions/macros
include( AudacityFunctions )
# Pull all the modules we'll need
include( CheckCXXCompilerFlag )
include( CheckIncludeFile )
include( CheckIncludeFiles )
include( CheckLibraryExists )
include( CheckSymbolExists )
include( CheckTypeSize )
include( CMakeDependentOption )
include( CMakeDetermineASM_NASMCompiler )
include( CMakePushCheckState )
include( GNUInstallDirs )
include( TestBigEndian )
# Determine 32-bit or 64-bit target
if( CMAKE_C_COMPILER_ID MATCHES "MSVC" AND CMAKE_VS_PLATFORM_NAME MATCHES "Win64|x64" )
set( IS_64BIT ON )
elseif( NOT CMAKE_SIZEOF_VOID_P STREQUAL "4" )
set( IS_64BIT ON )
endif()
message( STATUS "Build Info:" )
message( STATUS " Host System: ${CMAKE_HOST_SYSTEM}" )
message( STATUS " Host System Name: ${CMAKE_HOST_SYSTEM_NAME}" )
message( STATUS " Host System Processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}" )
message( STATUS " Host System Version: ${CMAKE_HOST_SYSTEM_VERSION}" )
if( IS_64BIT )
message( STATUS " Host System Architecture: 64-bit" )
else()
message( STATUS " Host System Architecture: 32-bit" )
endif()
message( STATUS )
message( STATUS " Compiler: ${CMAKE_CXX_COMPILER}" )
message( STATUS " Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}" )
message( STATUS " Compiler Standard: ${CMAKE_CXX_STANDARD}" )
message( STATUS " Compiler Standard Required: ${CMAKE_CXX_STANDARD_REQUIRED}" )
message( STATUS " Compiler Extensions: ${CMAKE_CXX_EXTENSIONS}" )
message( STATUS )
if( CMAKE_GENERATOR MATCHES "Visual Studio" )
message( STATUS " MSVC Version: ${MSVC_VERSION}" )
message( STATUS " MSVC Toolset: ${MSVC_TOOLSET_VERSION}" )
message( STATUS )
elseif( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
if( CMAKE_GENERATOR MATCHES "Xcode" )
message( STATUS " Xcode Version: ${XCODE_VERSION}" )
endif()
message( STATUS " MacOS SDK: ${CMAKE_OSX_SYSROOT}" )
message( STATUS )
endif()
# Try to get the current commit information
set( GIT_COMMIT_SHORT "unknown" )
set( GIT_COMMIT_LONG "unknown" )
set( GIT_COMMIT_TIME "unknown" )
find_package( Git QUIET )
if( GIT_FOUND )
execute_process(
COMMAND
${GIT_EXECUTABLE} show -s "--format=%h;%H;%cd"
WORKING_DIRECTORY
${topdir}
OUTPUT_VARIABLE
git_output
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if( git_output )
list( GET git_output 0 GIT_COMMIT_SHORT )
list( GET git_output 1 GIT_COMMIT_LONG )
list( GET git_output 2 GIT_COMMIT_TIME )
endif()
endif()
message( STATUS " Current Commit: ${GIT_COMMIT_SHORT}" )
message( STATUS )
# Define option() prefix
set( _OPT "audacity_" )
# Organize subdirectories/targets into folders for the IDEs
set_property( GLOBAL PROPERTY USE_FOLDERS ON )
if( CMAKE_GENERATOR MATCHES "Visual Studio" )
# Make sure Audacity is the startup project
set_directory_properties(
PROPERTIES
VS_STARTUP_PROJECT "${CMAKE_PROJECT_NAME}"
)
# Build using multiple processors
foreach( config ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER "${config}" config )
string( APPEND CMAKE_C_FLAGS_${config} " /MP" )
string( APPEND CMAKE_CXX_FLAGS_${config} " /MP" )
endforeach()
# Define system library information, but we'll do the install
set( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP YES )
set( CMAKE_INSTALL_UCRT_LIBRARIES NO )
set( CMAKE_INSTALL_MFC_LIBRARIES NO )
set( CMAKE_INSTALL_OPENMP_LIBRARIES NO )
include( InstallRequiredSystemLibraries )
endif()
# Where the final product is stored
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
# Define the non-install and executable paths
if( CMAKE_CONFIGURATION_TYPES )
set( _DESTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}" )
else()
set( _DESTDIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}" )
endif()
set( _DEST "${_DESTDIR}" )
set( _PREFIX "${CMAKE_INSTALL_PREFIX}" )
set( _LIBDIR "${CMAKE_INSTALL_LIBDIR}" )
set( _DATADIR "${CMAKE_INSTALL_DATADIR}" )
set( _PKGLIB "${_LIBDIR}/audacity" )
set( _PKGDATA "${_DATADIR}/audacity/" )
set( _MANDIR "${CMAKE_INSTALL_MANDIR}" )
set( _MODDIR "${_DEST}/modules" )
set( _EXEDIR "${_DEST}" )
# Setup RPATH handling
set( CMAKE_BUILD_RPATH "${_DEST}/${_PKGLIB}" )
set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
set( CMAKE_INSTALL_RPATH "${_PREFIX}/${_PKGLIB}" )
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE )
# Adjust them for the Mac
if( CMAKE_SYSTEM_NAME MATCHES "Darwin" )
set( _APPDIR "Audacity.app/Contents" )
set( _DEST "${_DESTDIR}/${_APPDIR}" )
set( _EXEDIR "${_DEST}/MacOS" )
set( _MODDIR "${_DEST}/modules" )
set( _PKGLIB "${_DEST}/Frameworks" )
set( CMAKE_MACOSX_RPATH OFF )
endif()
# Add the math library (if found) to the list of required libraries
check_library_exists( m pow "" HAVE_LIBM )
if( HAVE_LIBM )
list( APPEND CMAKE_REQUIRED_LIBRARIES -lm )
endif()
check_library_exists( atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC )
if( HAVE_LIBATOMIC )
list( APPEND CMAKE_REQUIRED_LIBRARIES -latomic )
endif()
# Add the dynamic linker library (if needed) to the list of required libraries
list( APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS} )
# Make sure they're used during the link steps
set( CMAKE_LINK_INTERFACE_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} )
# Various common checks whose results are used by the different targets
test_big_endian( WORDS_BIGENDIAN )
# Check for compiler flags
set( MMX_FLAG "" CACHE INTERNAL "" )
set( SSE_FLAG "" CACHE INTERNAL "" )
if( CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang|GNU" )
check_cxx_compiler_flag( "-mmmx" HAVE_MMX )
if( HAVE_MMX AND NOT IS_64BIT )
set( MMX_FLAG "-mmmx" CACHE INTERNAL "" )
endif()
check_cxx_compiler_flag( "-msse" HAVE_SSE )
if( HAVE_SSE AND NOT IS_64BIT )
set( SSE_FLAG "-msse" CACHE INTERNAL "" )
endif()
check_cxx_compiler_flag( "-msse2" HAVE_SSE2 )
if( HAVE_SSE2 AND NOT IS_64BIT )
set( SSE_FLAG "-msse2" CACHE INTERNAL "" )
endif()
elseif( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
set( HAVE_MMX ON )
set( HAVE_SSE ON )
set( HAVE_SSE2 ON )
if( NOT IS_64BIT )
set( SSE_FLAG "/arch:SSE2" )
endif()
endif()
check_include_files( "float.h;stdarg.h;stdlib.h;string.h" STDC_HEADERS )
check_include_file( "assert.h" HAVE_ASSERT_H )
check_include_file( "errno.h" HAVE_ERRNO_H )
check_include_file( "fcntl.h" HAVE_FCNTL_H )
check_include_file( "fenv.h" HAVE_FENV_H )
check_include_file( "inttypes.h" HAVE_INTTYPES_H )
check_include_file( "limits.h" HAVE_LIMITS_H )
if( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
check_include_file( "stdlib.h" HAVE_MALLOC_H )
check_include_file( "sys/endian.h" HAVE_ENDIAN_H )
else()
check_include_file( "malloc.h" HAVE_MALLOC_H )
check_include_file( "byteswap.h" HAVE_BYTESWAP_H )
endif()
check_include_file( "memory.h" HAVE_MEMORY_H )
check_include_file( "stdbool.h" HAVE_STDBOOL_H )
check_include_file( "stdint.h" HAVE_STDINT_H )
check_include_file( "stdlib.h" HAVE_STDLIB_H )
check_include_file( "string.h" HAVE_STRING_H )
check_include_file( "strings.h" HAVE_STRINGS_H )
check_include_file( "unistd.h" HAVE_UNISTD_H )
check_include_file( "xmmintrin.h" HAVE_XMMINTRIN_H )
check_include_file( "sys/param.h" HAVE_SYS_PARAM_H )
check_include_file( "sys/stat.h" HAVE_SYS_STAT_H )
check_include_file( "sys/types.h" HAVE_SYS_TYPES_H )
check_include_file( "sys/wait.h" HAVE_SYS_WAIT_H )
check_symbol_exists( bcopy "strings.h" HAVE_BCOPY )
check_symbol_exists( fileno "stdio.h" HAVE_FILENO )
check_symbol_exists( flock "sys/file.h" HAVE_FLOCK )
check_symbol_exists( fork "unistd.h" HAVE_FORK )
check_symbol_exists( fsync "unistd.h" HAVE_FSYNC )
check_symbol_exists( ftruncate "unistd.h" HAVE_FTRUNCATE )
check_symbol_exists( getpagesize "unistd.h" HAVE_GETPAGESIZE )
check_symbol_exists( gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY )
check_symbol_exists( gmtime "time.h" HAVE_GMTIME )
check_symbol_exists( gmtime_r "time.h" HAVE_GMTIME_R )
check_symbol_exists( lrint "math.h" HAVE_LRINT )
check_symbol_exists( lrintf "math.h" HAVE_LRINTF )
check_symbol_exists( lround "math.h" HAVE_LROUND )
check_symbol_exists( lstat "sys/stat.h" HAVE_LSTAT )
check_symbol_exists( memcpy "string.h" HAVE_MEMCPY )
check_symbol_exists( memmove "string.h" HAVE_MEMMOVE )
check_symbol_exists( mlock "sys/mman.h" HAVE_MLOCK )
check_symbol_exists( pipe "unistd.h" HAVE_PIPE )
check_symbol_exists( posix_fadvise "fcntl.h" HAVE_POSIX_FADVISE )
check_symbol_exists( posix_memalign "stdlib.h" HAVE_POSIX_MEMALIGN )
check_symbol_exists( strchr "string.h" HAVE_STRCHR )
check_symbol_exists( waitpid "sys/wait.h" HAVE_WAITPID )
check_type_size( "int8_t" SIZEOF_INT8 LANGUAGE C )
check_type_size( "int16_t" SIZEOF_INT16 LANGUAGE C )
check_type_size( "uint16_t" SIZEOF_UINT16 LANGUAGE C )
check_type_size( "u_int16_t" SIZEOF_U_INT16 LANGUAGE C )
check_type_size( "int32_t" SIZEOF_INT32 LANGUAGE C )
check_type_size( "uint32_t" SIZEOF_UINT32 LANGUAGE C )
check_type_size( "u_int32_t" SIZEOF_U_INT32 LANGUAGE C )
check_type_size( "int64_t" SIZEOF_INT64 LANGUAGE C )
check_type_size( "short" SIZEOF_SHORT LANGUAGE C )
check_type_size( "unsigned short" SIZEOF_UNSIGNED_SHORT LANGUAGE C )
check_type_size( "int" SIZEOF_INT LANGUAGE C )
check_type_size( "unsigned int" SIZEOF_UNSIGNED_INT LANGUAGE C )
check_type_size( "long" SIZEOF_LONG LANGUAGE C )
check_type_size( "unsigned long" SIZEOF_UNSIGNED_LONG LANGUAGE C )
check_type_size( "long long" SIZEOF_LONG_LONG LANGUAGE C )
check_type_size( "unsigned long long" SIZEOF_UNSIGNED_LONG_LONG LANGUAGE C )
check_type_size( "float" SIZEOF_FLOAT LANGUAGE C )
check_type_size( "double" SIZEOF_DOUBLE LANGUAGE C )
check_type_size( "long double" SIZEOF_LONG_DOUBLE LANGUAGE C )
check_type_size( "loff_t" SIZEOF_LOFF LANGUAGE C )
check_type_size( "off_t" SIZEOF_OFF LANGUAGE C )
check_type_size( "off64_t" SIZEOF_OFF64 LANGUAGE C )
check_type_size( "size_t" SIZEOF_SIZE LANGUAGE C )
check_type_size( "wchar_t" SIZEOF_WCHAR LANGUAGE C )
check_type_size( "void*" SIZEOF_POINTER LANGUAGE C )
# We'll be using it if it's available
find_package( PkgConfig QUIET )
# Mostly just to make the CMP0072 policy happy
find_package( OpenGL QUIET )
# Precreate the lib and lib64 directories so we can make then the same
if( NOT EXISTS "${CMAKE_BINARY_DIR}/lib" )
file( MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/lib" )
endif()
# Only create on systems that need it, effectively excluding Windows where links
# may not work due to insufficient privileges
if( NOT CMAKE_INSTALL_LIBDIR STREQUAL "lib" AND NOT EXISTS "${CMAKE_BINARY_DIR}/lib64" )
file( CREATE_LINK "${CMAKE_BINARY_DIR}/lib" "${CMAKE_BINARY_DIR}/lib64" SYMBOLIC )
endif()
# Define Audacity's name
if( CMAKE_SYSTEM_NAME MATCHES "Darwin|Windows" )
set( AUDACITY_NAME "Audacity" )
else()
set( AUDACITY_NAME "audacity" )
endif()
# Extract the Audacity version information
file(
STRINGS
${topdir}/src/Audacity.h output
REGEX
"^#define +AUDACITY_(VERSION|RELEASE|REVISION|MODLEVEL|BUILD_LEVEL) +"
)
# And store as variables
foreach( line ${output} )
string( REGEX MATCHALL "[A-Za-z0-9_]+" line "${line}" )
list( GET line 1 name )
list( GET line 2 value )
set( ${name} ${value} )
endforeach()
# Create short and full version strings
set( AUDACITY_DIST_VERSION ${AUDACITY_VERSION}.${AUDACITY_RELEASE}.${AUDACITY_REVISION} )
set( AUDACITY_INFO_VERSION ${AUDACITY_VERSION}.${AUDACITY_RELEASE}.${AUDACITY_REVISION}.${AUDACITY_MODLEVEL} )
# Define the version suffix (duplicates what happens in src/Audacity.h)
string( TIMESTAMP __TDATE__ "%Y%m%d" )
if( AUDACITY_BUILD_LEVEL EQUAL 0 )
set( AUDACITY_SUFFIX "-alpha-${__TDATE__}" )
elseif( AUDACITY_BUILD_LEVEL EQUAL 1 )
set( AUDACITY_SUFFIX "-beta-${__TDATE__}" )
else()
set( AUDACITY_SUFFIX "" )
endif()
# Python is used for the manual and (possibly) message catalogs
find_package( Python3 )
if( Python3_FOUND )
set( PYTHON "${Python3_EXECUTABLE}" )
elseif( CMAKE_SYSTEM_NAME MATCHES "Windows" )
nuget_package( pkgdir "python3" "3.7.7" )
file( TO_NATIVE_PATH "${pkgdir}/tools/python.exe" PYTHON )
endif()
# Add our children
add_subdirectory( "cmake-proxies" )
add_subdirectory( "help" )
add_subdirectory( "images" )
add_subdirectory( "locale" )
add_subdirectory( "modules" )
add_subdirectory( "nyquist" )
add_subdirectory( "plug-ins" )
add_subdirectory( "src" )
add_subdirectory( "scripts" )
# Uncomment what follows for symbol values.
#[[
get_cmake_property( _variableNames VARIABLES )
foreach( _variableName ${_variableNames} )
message( STATUS "${_variableName}=${${_variableName}}" )
endforeach()
#]]
#[[
include( PrintProperties )
print_properties( TARGET "wxWidgets" )
#]]