forked from csound/csound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
1590 lines (1357 loc) · 47.1 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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (APPLE)
cmake_minimum_required(VERSION 3.28)
else()
cmake_minimum_required(VERSION 3.13.4)
endif()
set (CMAKE_CXX_STANDARD 11)
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0075 NEW)
cmake_policy(SET CMP0091 NEW)
include(cmake/cmake-utilities.cmake)
# silence RPATH cmake warning
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CMAKE_OSX_DEPLOYMENT_TARGET 11)
option(USE_VCPKG "Use VCPKG to download and manage dependencies" OFF)
if (USE_VCPKG)
# Detect correct triplet based on CMake env
if (ANDROID)
if(CMAKE_TARGET_ARCHITECTURE STREQUAL "arm")
set(VCPKG_TARGET_TRIPLET "arm-android")
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
elseif(CMAKE_TARGET_ARCHITECTURE STREQUAL "arm64")
set(VCPKG_TARGET_TRIPLET "arm64-android")
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
elseif(CMAKE_TARGET_ARCHITECTURE STREQUAL "x86")
set(VCPKG_TARGET_TRIPLET "x86-android")
set(CMAKE_ANDROID_ARCH_ABI x86)
elseif(CMAKE_TARGET_ARCHITECTURE STREQUAL "x64")
set(VCPKG_TARGET_TRIPLET "x64-android")
set(CMAKE_ANDROID_ARCH_ABI x86_64)
endif()
set(CMAKE_SYSTEM_VERSION 21)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platform/android/android.cmake)
elseif (OSXCROSS_TARGET)
if (IOS)
if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
set(VCPKG_TARGET_TRIPLET "x64-ioscross")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platform/ioscross/ios-x64.cmake)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(VCPKG_TARGET_TRIPLET "arm64-ioscross")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platform/ioscross/ios-arm64.cmake)
endif()
else()
if(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
set(VCPKG_TARGET_TRIPLET "x64-osxcross")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platform/osxcross/osx-x64.cmake)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(VCPKG_TARGET_TRIPLET "arm64-osxcross")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platform/osxcross/osx-arm64.cmake)
endif()
endif()
elseif (CMAKE_SYSTEM_NAME STREQUAL "MinGW" AND UNIX)
set(VCPKG_TARGET_TRIPLET "x64-mingw-static")
set(VCPKG_INSTALL_OPTIONS "--allow-unsupported")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/toolchains/mingw.cmake)
set(VCPKG_CMAKE_SYSTEM_NAME MinGW)
set(VCPKG_TARGET_ARCHITECTURE x64)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(VCPKG_TARGET_TRIPLET "wasm32-emscripten")
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/platform/wasm/wasm32.cmake)
set(VCPKG_CMAKE_SYSTEM_NAME Emscripten)
elseif (WIN32)
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
elseif(APPLE)
execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH)
if (ARCH STREQUAL "arm64\n")
set(VCPKG_TARGET_TRIPLET "arm64-osx")
else()
set(VCPKG_TARGET_TRIPLET "x64-osx")
endif()
elseif (UNIX)
set(VCPKG_TARGET_TRIPLET "x64-linux")
endif()
set(VCPKG_FEATURE_FLAGS versions)
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
set(VCPKG_OVERLAY_TRIPLETS ${CMAKE_CURRENT_SOURCE_DIR}/platform/vcpkg/triplets)
set(VCPKG_OVERLAY_PORTS ${CMAKE_CURRENT_SOURCE_DIR}/platform/vcpkg/ports)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
endif()
message(STATUS "VCPKG_TARGET_TRIPLET: ${VCPKG_TARGET_TRIPLET}")
message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
project(Csound)
enable_testing()
set(libcsound_private_include_dirs "")
set(libcsound_public_include_dirs "")
SET(BUILD_SHARED_LIBS ON)
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_COMPILER_IS_CLANG 1)
endif()
message(STATUS "Csound directory: ${CMAKE_HOME_DIRECTORY}")
# Project definitions
set(CS_VERSION "7")
set(CS_SUBVER "0")
set(CS_PATCHLEVEL "0")
set(APIVERSION "${CS_VERSION}.${CS_SUBVER}")
message(STATUS "Csound version: ${CS_VERSION}.${CS_SUBVER}.${CS_PATCHLEVEL}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README.md.in ${CMAKE_CURRENT_SOURCE_DIR}/README.md)
set(MACOSX_FRAMEWORK_BUNDLE_VERSION "${CS_VERSION}.${CS_SUBVER}.${CS_PATCHLEVEL}")
set(MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${CS_VERSION}.${CS_SUBVER}.${CS_PATCHLEVEL}")
set(MACOSX_FRAMEWORK_IDENTIFIER "CSND")
# Relative install paths
set(EXECUTABLE_INSTALL_DIR "bin")
set(LOCALE_INSTALL_DIR "share/locale")
set(HEADER_INSTALL_DIR "include/csound")
set(SAMPLES_INSTALL_DIR "/samples")
if(OSXCROSS_TARGET)
set(CS_FRAMEWORK_DEST "${CMAKE_INSTALL_PREFIX}/Library/Frameworks" CACHE PATH "Csound framework path")
else()
set(CS_FRAMEWORK_DEST "$ENV{HOME}/Library/Frameworks" CACHE PATH "Csound framework path")
endif()
set(CS_OPCODE_DIR "" CACHE PATH "opcodedir path")
if(APPLE)
set(CMAKE_INSTALL_RPATH ${CS_FRAMEWORK_DEST})
endif()
include(TestBigEndian)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(CMakeParseArguments)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CMakePushCheckState)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules/)
list(APPEND CMAKE_PREFIX_PATH /usr /usr/local /opt/local /sw)
message(STATUS "CMake module path: ${CMAKE_MODULE_PATH}")
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
elseif(EXISTS "/usr/local/bin/bison")
message(STATUS "Bison in /usr/local/bin")
set(BISON_EXECUTABLE "/usr/local/bin/bison")
endif()
execute_process(
COMMAND brew --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
elseif(EXISTS "/usr/local/bin/flex")
message(STATUS "Flex in /usr/local/bin")
set(FLEX_EXECUTABLE "/usr/local/bin/flex")
endif()
endif()
### COMPILER OPTIMIZATION FLAGS
option(USE_COMPILER_OPTIMIZATIONS "Use the default Csound compiler optimization flags" ON)
if(USE_COMPILER_OPTIMIZATIONS)
include(cmake/CompilerOptimizations.cmake)
endif()
## USER OPTIONS ##
# Optional targets, they should all default to ON (check_deps will disable them if not possible to build)
option(USE_DOUBLE "Set to use double-precision floating point for audio samples." ON)
option(USE_LIBSNDFILE "Use libsndfile for sndfile IO, if available" ON)
option(BUILD_PERFTHREAD_CLASS "Include the Csound performance thread support (C++) " ON)
option(BUILD_UTILITIES "Build stand-alone executables for utilities that can also be used with -U" ON)
option(NEW_PARSER_DEBUG "Enable tracing of new parser" OFF)
option(BUILD_MULTI_CORE "Enable building for multicore system" ON)
option(FAIL_MISSING "Fail when a required external dependency is not present (useful for packagers)" OFF)
option(USE_GETTEXT "Use the Gettext internationalization library" ON)
option(BUILD_STATIC_LIBRARY "Also build a static version of the csound library" OFF)
option(USE_LRINT "Use lrint/lrintf for converting floating point values to integers." ON)
option(USE_CURL "Use CURL library" ON)
option(BUILD_RELEASE "Build for release" ON)
option(BUILD_INSTALLER "Build installer" OFF)
option(BUILD_TESTS "Build tests" OFF)
option(LEXER_DEBUG "Build lexer with debug option" OFF)
option(USE_GIT_COMMIT "Show the git commit in version information" ON)
option(REQUIRE_PTHREADS "For non-Windows systems, set whether Csound will use threads or not" ON)
option(BUILD_DOCS "Build documentation (requires doxygen)" OFF)
option(DEBUG_ERROR_ON_WARNING "For a debug build, error on a compiler# warning" OFF)
option(BARE_METAL "To configure for bare metal build" OFF)
option(CUSTOM_MALLOC "Use custom malloc in bare metal builds" OFF)
option(BUILD_PLUGINS "Build external opcodes as plugins" OFF)
option(BUILD_WITH_LTO "Build with link-time optimisations" OFF)
option(USE_SHORT_TABLE_LENGTH "Build with original max table length 2^24" OFF)
# secret rabbit code
if (USE_VCPKG)
find_package(SampleRate CONFIG REQUIRED)
assign_bool(SampleRate_FOUND TARGET SampleRate::samplerate)
else()
find_package(SampleRate MODULE)
endif()
if(SampleRate_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_SRC")
message(STATUS "Using Secret Rabbit Code")
endif()
if(USE_SHORT_TABLE_LENGTH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSHORT_TABLE_LENGTH")
message(STATUS "Using short max table length")
endif()
# Include this after the install path definitions so we can override them here.
# Also after function definitions so we can use them there
# Also after user options so that the default values don't overwrite the custom files values
find_file(CUSTOM_CMAKE "Custom.cmake" HINTS ${CMAKE_HOME_DIRECTORY})
if(CUSTOM_CMAKE)
message(STATUS "Including Custom.cmake file: ${CUSTOM_CMAKE}")
include(${CUSTOM_CMAKE})
else()
message(STATUS "Not using Custom.cmake file.")
endif()
if(BUILD_WITH_LTO)
set(CSOUNDLIB_SHARED_LINK_OPTIONS -flto -Werror=odr
-Werror=lto-type-mismatch -Werror=strict-aliasing)
message(STATUS "Building with link-time optimisations")
else()
set(CSOUNDLIB_SHARED_LINK_OPTIONS "")
message(STATUS "Not building with link-time optimisations")
endif()
if(BARE_METAL)
message(STATUS "Building for bare metal")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBARE_METAL")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBARE_METAL")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_CSOUND_SERVER")
if(CUSTOM_MALLOC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCUSTOM_MALLOC")
# the default is for STM32H7: -DMALLOC_BASE=0xC0000000
endif()
endif()
# in Release configuration, set NDEBUG
if(${CMAKE_BUILD_TYPE} MATCHES "Release")
message(STATUS "Building for release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNDEBUG")
elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug")
message(STATUS "Building for debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBETA")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBETA")
endif()
# set -Werror if in Debug configuration
if(NOT MSVC AND NOT WASM)
#ifdef BARE_METAL
set(CMAKE_CXX_FLAGS_RELEASE "-Os")
set(CMAKE_C_FLAGS_RELEASE "-Os")
#else
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_C_FLAGS_RELEASE "-O3")
#endif
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
if (DEBUG_ERROR_ON_WARNING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
if(APPLE)
if(OSXCROSS_TARGET)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshorten-64-to-32 -Wpointer-sign")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshorten-64-to-32 -Wpointer-sign")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshorten-64-to-32 -Wpointer-sign -fsanitize=address")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshorten-64-to-32 -Wpointer-sign -fsanitize=address")
endif()
endif()
endif()
endif()
if(APPLE)
#list(APPEND CMAKE_REQUIRED_INCLUDES "time.h")
CHECK_FUNCTION_EXISTS(clock_gettime CLOCK_GETTIME)
if(${CLOCK_GETTIME})
message(STATUS "clock_gettime() found")
set(CMAKE_C_FLAGS "-DHAVE_CLOCK_GETTIME ${CMAKE_C_FLAGS}")
else()
message(STATUS "clock_gettime() not found")
endif()
endif()
if(OSXCROSS_TARGET)
set(CMAKE_C_FLAGS "-I${OSXCROSS_SDK}/usr/include ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-I${OSXCROSS_SDK}/usr/include ${CMAKE_CXX_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${CMAKE_OSX_SYSROOT}/usr/lib")
endif()
# library installation directories
option(USE_LIB64 "Set to on to set installation directory for libraries to lib64" OFF)
if(USE_LIB64)
set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib64")
add_definitions("-DLIB64")
elseif(NOT DEFINED LIBRARY_INSTALL_DIR)
set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib")
endif()
message(STATUS "LIBRARY INSTALL DIR: ${LIBRARY_INSTALL_DIR}")
if(USE_DOUBLE)
message(STATUS "Building with 64-bit floats")
set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins64-${APIVERSION}")
else()
message(STATUS "Building with 32-bit floats")
set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins-${APIVERSION}")
endif()
if(WIN32 AND NOT MSVC)
if(EXISTS "C:/MinGW/include")
list(APPEND libcsound_private_include_dirs "C:/MinGW/include")
else()
MESSAGE(STATUS "MinGW include dir not found.")
endif()
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--add-stdcall-alias")
endif()
if(WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_MODULE_PREFIX "")
set(CSOUND_WINDOWS_LIBRARIES kernel32 ws2_32)
if(MSVC)
# Experimented with flags but did not make change performance results
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Oi /fp:fast /arch:AVX2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Oi /fp:fast /arch:AVX2")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mstackrealign -static-libgcc -static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign -static-libstdc++ -static-libgcc -static")
set_target_properties(${CSOUNDLIB} PROPERTIES LINK_FLAGS "-static-libstdc++ -static-libgcc -static")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static")
endif()
endif()
set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY_HIDDEN)
check_cxx_compiler_flag(-fvisibility=hidden HAS_CXX_VISIBILITY_HIDDEN)
if (HAS_VISIBILITY_HIDDEN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
endif()
if (HAS_CXX_VISIBILITY_HIDDEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
check_c_compiler_flag(-std=gnu99 HAS_GNU99)
if (HAS_GNU99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
endif()
if (HAS_CXX_VISIBILITY_HIDDEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
if(APPLE)
if(IOS)
message(STATUS "Building for iOS.")
else()
message(STATUS "Building for OSX")
if(BUILD_INSTALLER)
set(CS_FRAMEWORK_DEST "${CMAKE_INSTALL_PREFIX}")
endif()
set(DEFAULT_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/)
if(NOT CMAKE_OSX_SYSROOT AND EXISTS ${DEFAULT_OSX_SYSROOT})
set(CMAKE_OSX_SYSROOT ${DEFAULT_OSX_SYSROOT})
endif()
if(CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT MATCHES ".*OSX10.6.*"
AND (NOT CMAKE_OSX_DEPLOYMENT_TARGET))
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.7)
message(STATUS "OSX: Setting Deployment Target to 10.7")
else()
message(STATUS "OSX: Setting Deployment Target to ${CMAKE_OSX_DEPLOYMENT_TARGET}")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_VECLIB")
if(NOT VECLIB_PATH)
set(VECLIB_PATH "/System/Library/Frameworks/")
endif()
endif()
endif()
# Set plugins install directory
if(USE_DOUBLE)
if(APPLE)
set(CSOUNDLIB "CsoundLib64")
set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64")
else()
set(CSOUNDLIB "csound64")
endif()
else()
if(APPLE)
set(CSOUNDLIB "CsoundLib")
set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes")
else()
set(CSOUNDLIB "csound")
endif()
endif()
# set default user plugin directory
if(CS_OPCODE_DIR STREQUAL "")
if(APPLE)
if(BUILD_INSTALLER)
set(CS_FRAMEWORK_FULL_PATH "/Library/Frameworks/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64")
else()
get_filename_component(CS_FRAMEWORK_FULL_PATH ${PLUGIN_INSTALL_DIR} ABSOLUTE)
endif()
add_definitions("-DCS_DEFAULT_PLUGINDIR=\"${CS_FRAMEWORK_FULL_PATH}\"")
set(DEFAULT_OPCODEDIR "${CS_FRAMEWORK_FULL_PATH}")
# dir relative to $HOME
if(USE_DOUBLE)
set(DEFAULT_USER_PLUGINDIR "Library/csound/${APIVERSION}/plugins64")
else()
set(DEFAULT_USER_PLUGINDIR "Library/csound/${APIVERSION}/plugins")
endif()
add_definitions("-DCS_DEFAULT_USER_PLUGINDIR=\"${DEFAULT_USER_PLUGINDIR}\"")
endif()
else()
add_definitions("-DCS_DEFAULT_PLUGINDIR=\"${CS_OPCODE_DIR}\"")
set(DEFAULT_OPCODEDIR "${CS_OPCODE_DIR}")
endif()
# LINUX definition
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(LINUX YES)
message(STATUS "LINUX operating system found")
else()
set(LINUX NO)
endif()
if(LINUX)
set(DEFAULT_OPCODEDIR "${PLUGIN_INSTALL_DIR}")
add_definitions("-DCS_DEFAULT_PLUGINDIR=\"${DEFAULT_OPCODEDIR}\"")
# dir relative to $HOME
if(USE_DOUBLE)
set(DEFAULT_USER_PLUGINDIR ".local/lib/csound/${APIVERSION}/plugins64")
else()
set(DEFAULT_USER_PLUGINDIR ".local/lib/csound/${APIVERSION}/plugins")
endif()
add_definitions("-DCS_DEFAULT_USER_PLUGINDIR=\"${DEFAULT_USER_PLUGINDIR}\"")
endif()
if(WIN32)
# dir relaive to %LOCALAPPDATA%
if(USE_DOUBLE)
set(DEFAULT_USER_PLUGINDIR "csound/${APIVERSION}/plugins64")
else()
set(DEFAULT_USER_PLUGINDIR "csound/${APIVERSION}/plugin")
endif()
add_definitions("-DCS_DEFAULT_USER_PLUGINDIR=\"${DEFAULT_USER_PLUGINDIR}\"")
endif()
if(BUILD_RELEASE)
add_definitions("-D_CSOUND_RELEASE_")
else()
add_definitions("-DBETA")
endif()
if(APPLE OR LINUX)
message(STATUS "default plugin dir set to ${DEFAULT_OPCODEDIR}")
endif()
set(BUILD_PLUGINS_DIR ${BUILD_DIR})
set(BUILD_BIN_DIR ${BUILD_DIR})
set(BUILD_LIB_DIR ${BUILD_DIR})
message(STATUS "BUILD_BIN_DIR set to ${BUILD_BIN_DIR}.")
message(STATUS "BUILD_LIB_DIR set to ${BUILD_LIB_DIR}.")
message(STATUS "BUILD_PLUGINS_DIR set to ${BUILD_PLUGINS_DIR}.")
# OS specific checks
TEST_BIG_ENDIAN(BIG_ENDIAN)
## HEADER/LIBRARY/OTHER CHECKS ##
# Check if libsndfile is available, if not, disable build
if(USE_LIBSNDFILE)
if(USE_VCPKG)
find_package(SndFile CONFIG REQUIRED)
assign_bool(SndFile_FOUND TARGET SndFile::sndfile)
else()
message(STATUS "looking at ${CMAKE_PREFIX_PATH}")
find_package(SndFile MODULE)
message(STATUS "libsndfile found: ${SndFile_LIBRARY}")
endif()
endif()
check_deps(USE_LIBSNDFILE SndFile_FOUND)
# this makes sure make_plugin() can find headers
list(APPEND libcsound_private_include_dirs ${SndFile_INCLUDE_DIR})
# carry on setting up libsndifle if so
if(USE_LIBSNDFILE)
add_compile_definitions("USE_LIBSNDFILE")
if(NOT USE_VCPKG AND EMSCRIPTEN)
list(APPEND libcsound_private_include_dirs ${Csound_SOURCE_DIR}/emscripten/deps/libsndfile-1.0.25/src/)
endif()
# add to required libraries so we can check for MIDI support
list(APPEND CMAKE_REQUIRED_LIBRARIES SndFile::sndfile)
check_c_source_compiles("#include <sndfile.h>
int main(int argc, char** argv) {
printf(\"SF_FORMAT_MPEG: %d\", SF_FORMAT_MPEG);
return 0;
}" HAVE_SF_FORMAT_MPEG)
option(USE_MP3 "Use MP3 support in libsndfile" ON)
check_deps(USE_MP3 HAVE_SF_FORMAT_MPEG)
if (USE_MP3)
message(STATUS "Using libsndfile MP3 support")
add_compile_definitions("SNDFILE_MP3")
else()
message(STATUS "NOT Using libsndfile MP3 support")
endif()
endif()
find_package(CURL)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
# windows threads aren't supported
assign_bool(NOT_WINDOWS_THREADS NOT CMAKE_USE_WIN32_THREADS_INIT)
check_deps(REQUIRE_PTHREADS Threads_FOUND NOT_WINDOWS_THREADS)
if(REQUIRE_PTHREADS)
list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
endif()
# Now, non required library searches
option(USE_ATOMIC_BUILTIN "Use Atomic Builtins if supported" ON)
if(USE_ATOMIC_BUILTIN)
include(cmake/CheckAtomic.cmake)
if(HAVE_ATOMIC_BUILTIN)
message(STATUS "Using atomic builtins.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_ATOMIC_BUILTIN")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_ATOMIC_BUILTIN")
else()
message(STATUS "Not using atomic builtins - not found")
endif()
else()
message(STATUS "Not using atomic builtins - user disabled")
endif()
find_package(Intl)
find_package(Gettext)
find_library(MATH_LIBRARY m)
if (NOT MATH_LIBRARY)
set(MATH_LIBRARY "")
endif()
if(APPLE)
include(CheckSymbolExists)
check_symbol_exists(lrint math.h FOUND_LRINT)
else()
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_LIBRARIES ${MATH_LIBRARY})
check_function_exists(lrint FOUND_LRINT)
cmake_pop_check_state()
endif()
# MSVC / VCPKG won't find dirent.h by default. Need to add the path explicitly
find_file(DIRENT_H "dirent.h")
if(DIRENT_H)
if(MSVC)
get_filename_component(DIRENT_FOLDER ${DIRENT_H} DIRECTORY)
list(APPEND CMAKE_REQUIRED_INCLUDES ${DIRENT_FOLDER})
endif()
else()
if(MSVC)
message(FATAL_ERROR "Dirent.h not found, Csound will not be able to load dynamic plugins. Cannot continue with project generation")
else()
message(WARNING "Dirent.h not found, Csound will not be able to load dynamic plugins such as real-time audio")
endif()
endif()
set(HEADERS_TO_CHECK
unistd.h io.h fcntl.h stdint.h
sys/time.h sys/types.h termios.h
values.h winsock.h sys/socket.h
dirent.h inttypes.h execinfo.h)
foreach(header ${HEADERS_TO_CHECK})
# Convert to uppercase and replace [./] with _
string(TOUPPER ${header} tmp)
string(REGEX REPLACE [./] "_" upper_header ${tmp})
check_include_file(${header} HAVE_${upper_header})
endforeach()
if (NOT HAVE_INTTYPES_H)
message(FATAL_ERROR "Csound requires inttypes.h")
endif()
if (HAVE_EXECINFO_H)
add_definitions("-DHAVE_EXECINFO")
endif()
check_deps(USE_LRINT FOUND_LRINT)
if(USE_LRINT)
add_definitions("-DUSE_LRINT")
endif()
## Check existence of CURL
if(USE_CURL)
find_package(CURL)
if(CURL_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_CURL")
else()
message(STATUS "Not using CURL for urls - not found.")
endif()
else()
message(STATUS "Not using CURL for urls - disabled.")
endif()
# Flex/Bison for the new parser
find_package(FLEX)
find_package(BISON)
if(NOT FLEX_EXECUTABLE)
message(FATAL_ERROR "Csound requires the flex executable")
endif()
if(NOT BISON_EXECUTABLE)
message(FATAL_ERROR "Csound requires the bison executable")
endif()
## MAIN TARGETS ##
set(libcsound_CFLAGS -D__BUILDING_LIBCSOUND)
list(APPEND libcsound_public_include_dirs
$<BUILD_INTERFACE:${Csound_SOURCE_DIR}>
$<BUILD_INTERFACE:${Csound_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${Csound_SOURCE_DIR}/H>
$<BUILD_INTERFACE:${Csound_SOURCE_DIR}/Engine>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
list(APPEND libcsound_private_include_dirs
${Csound_SOURCE_DIR}
"${Csound_SOURCE_DIR}/util"
)
#checking pthread functions
if(REQUIRE_PTHREADS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_PTHREAD")
if (NOT VCPKG_TARGET_TRIPLET STREQUAL "x64-mingw-static")
check_function_exists(pthread_spin_lock PTHREAD_SPIN_LOCK_EXISTS)
endif()
check_function_exists(pthread_barrier_init PTHREAD_BARRIER_INIT_EXISTS)
if(PTHREAD_SPIN_LOCK_EXISTS)
list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_SPIN_LOCK)
endif()
if(PTHREAD_BARRIER_INIT_EXISTS)
list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_BARRIER_INIT)
endif()
endif()
# get the git hash and pass it to csound
set(git_hash_values "none")
if(USE_GIT_COMMIT)
find_package(Git)
message(STATUS "GIT: ${GIT_EXECUTABLE}")
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "HEAD"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE git_hash_value)
if (git_hash_value)
string(STRIP ${git_hash_value} git_hash_values)
message(STATUS "HASH: ${git_hash_values}")
endif()
endif()
endif()
set_source_files_properties(Top/csound.c PROPERTIES COMPILE_FLAGS -DGIT_HASH_VALUE=${git_hash_values})
# The csound library
set(libcsound_SRCS
Top/csound.c
Top/argdecode.c
Top/csdebug.c
Top/cscore_internal.c
Top/cscorfns.c
Top/csmodule.c
Top/getstring.c
Top/main.c
Top/new_opts.c
Top/one_file.c
Top/opcode.c
Top/threads.c
Top/utility.c
Top/threadsafe.c
Top/server.c
Engine/auxfd.c
Engine/cfgvar.c
Engine/corfiles.c
Engine/entry1.c
Engine/envvar.c
Engine/extract.c
Engine/fgens.c
Engine/insert.c
Engine/srconvert.c
Engine/udo.c
Engine/linevent.c
Engine/memalloc.c
Engine/memfiles.c
Engine/musmon.c
Engine/namedins.c
Engine/rdscor.c
Engine/scsort.c
Engine/scxtract.c
Engine/sort.c
Engine/sread.c
Engine/swritestr.c
Engine/twarp.c
Engine/csound_type_system.c
Engine/csound_standard_types.c
Engine/csound_data_structures.c
Engine/pools.c
Engine/ugen.c
InOut/soundfile.c
InOut/libsnd.c
InOut/libsnd_u.c
InOut/midifile.c
InOut/midirecv.c
InOut/midisend.c
InOut/winascii.c
InOut/windin.c
InOut/window.c
InOut/winEPS.c
InOut/circularbuffer.c
OOps/aops.c
OOps/bus.c
OOps/cmath.c
OOps/complex_ops.c
OOps/diskin2.c
OOps/disprep.c
OOps/dumpf.c
OOps/fftlib.c
OOps/lpred.c
OOps/pffft.c
OOps/goto_ops.c
OOps/midiinterop.c
OOps/midiops.c
OOps/midiops2.c
OOps/midiops3.c
OOps/midiout.c
OOps/mxfft.c
OOps/oscils.c
OOps/pitch0.c
OOps/pstream.c
OOps/pvfileio.c
OOps/pvsanal.c
OOps/random.c
OOps/remote.c
OOps/schedule.c
OOps/sndinfUG.c
OOps/str_ops.c
OOps/ugens1.c
OOps/ugens2.c
OOps/ugens3.c
OOps/ugens4.c
OOps/ugens5.c
OOps/ugens6.c
OOps/ugtabs.c
OOps/ugrw1.c
OOps/vdelay.c
OOps/compile_ops.c
)
set(vbap_ops
Opcodes/vbap.c
)
set(libcsound_static_SRCS ${libcsound_SRCS})
if(WIN32 AND NOT MSVC)
set_source_files_properties(Opcodes/sfont.c PROPERTIES
COMPILE_FLAGS -mno-ms-bitfields)
endif()
if(NOT MSVC)
set_source_files_properties(Opcodes/sfont.c PROPERTIES
COMPILE_FLAGS -Wno-address-of-packed-member)
endif()
set(physmod_SRCS
Opcodes/physutil.c
Opcodes/modal4.c
Opcodes/physmod.c
Opcodes/mandolin.c
Opcodes/singwave.c
Opcodes/fm4op.c
Opcodes/moog1.c
Opcodes/shaker.c
Opcodes/bowedbar.c
)
set(externs_SRCS
Opcodes/babo.c
Opcodes/bilbar.c
Opcodes/compress.c
Opcodes/eqfil.c
Opcodes/Vosim.c
Opcodes/squinewave.c
Opcodes/pinker.c
Opcodes/cpumeter.c
Opcodes/sc_noise.c
Opcodes/afilters.c
Opcodes/wpfilters.c
Opcodes/lufs.c
Opcodes/date.c
Opcodes/system_call.c
Opcodes/serial.c
Opcodes/counter.c
Opcodes/liveconv.c
Opcodes/sterrain.c
Opcodes/gammatone.c
Opcodes/sfont.c
Opcodes/gendy.c
Opcodes/phisem.c
Opcodes/framebuffer.c
Opcodes/cellular.c
Opcodes/exciter.c
Opcodes/buchla.c
Opcodes/select.c
Opcodes/platerev.c
Opcodes/sequencer.c
Opcodes/grain4.c
Opcodes/loscilx.c
Opcodes/minmax.c
Opcodes/pan2.c
Opcodes/vaops.c
Opcodes/ugakbari.c
Opcodes/harmon.c
Opcodes/pitchtrack.c
Opcodes/partikkel.c
Opcodes/shape.c
Opcodes/tabaudio.c
Opcodes/tabsum.c
Opcodes/crossfm.c
Opcodes/pvlock.c
Opcodes/fareyseq.c
Opcodes/modmatrix.c
Opcodes/scoreline.c
Opcodes/ambicode1.c
Opcodes/arrays.c
Opcodes/emugens/emugens.c
Opcodes/emugens/scugens.c
Opcodes/zak.c
Opcodes/paulstretch.c
)
set(newgabops_SRCS
Opcodes/gab/tabmorph.c
Opcodes/gab/hvs.c
Opcodes/gab/newgabopc.c
)
set(gens_SRCS
Opcodes/ftest.c
Opcodes/fareygen.c
Opcodes/quadbezier.c
)
set(pitch_ops_SRCS
Opcodes/pitch.c
Opcodes/spectra.c
)
set(stdopcod_SRCS
Opcodes/ambicode.c
Opcodes/bbcut.c
Opcodes/biquad.c
Opcodes/butter.c
Opcodes/clfilt.c
Opcodes/cross2.c
Opcodes/dam.c
Opcodes/dcblockr.c
Opcodes/filter.c
Opcodes/flanger.c
Opcodes/follow.c
Opcodes/fout.c
Opcodes/freeverb.c
Opcodes/ftconv.c
Opcodes/ftgen.c
Opcodes/gab/gab.c
Opcodes/gab/vectorial.c
Opcodes/grain.c
Opcodes/locsig.c
Opcodes/lowpassr.c
Opcodes/metro.c
Opcodes/newfils.c
Opcodes/nlfilt.c
Opcodes/oscbnk.c
Opcodes/pluck.c
Opcodes/repluck.c
Opcodes/reverbsc.c
Opcodes/seqtime.c
Opcodes/sndloop.c
Opcodes/sndwarp.c
Opcodes/space.c
Opcodes/spat3d.c
Opcodes/syncgrain.c
Opcodes/ugens7.c
Opcodes/ugens9.c
Opcodes/ugensa.c
Opcodes/uggab.c
Opcodes/ugmoss.c
Opcodes/ugnorman.c
Opcodes/ugsc.c
Opcodes/wave-terrain.c
Opcodes/wterrain2.c
Opcodes/stdopcod.c
)
set(sock_ops_SRCS
Opcodes/socksend.c
Opcodes/sockrecv.c
)
set(hrtf_ops_SRCS
Opcodes/hrtfopcodes.c
Opcodes/hrtfearly.c
Opcodes/hrtfreverb.c
Opcodes/hrtferX.c
)
set(cs_pvs_ops_SRCS
Opcodes/ifd.c
Opcodes/partials.c
Opcodes/psynth.c
Opcodes/pvsbasic.c
Opcodes/pvscent.c