forked from john-preston/openal-soft
-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
1710 lines (1538 loc) · 58.3 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
# CMake build file list for OpenAL
cmake_minimum_required(VERSION 3.0.2)
if(APPLE)
# The workaround for try_compile failing with code signing
# since cmake-3.18.2, not required
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}
"CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
"CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
# Fix compile failure with armv7 deployment target >= 11.0, xcode clang
# will report:
# error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
# iOS 10 is the maximum deployment target for 32-bit targets
# If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
# deployment target
if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
FORCE)
endif()
endif()
endif()
project(OpenAL)
if(COMMAND CMAKE_POLICY)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0005 NEW)
if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW)
endif(POLICY CMP0020)
if(POLICY CMP0042)
cmake_policy(SET CMP0042 NEW)
endif(POLICY CMP0042)
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif(POLICY CMP0054)
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif(POLICY CMP0075)
endif(COMMAND CMAKE_POLICY)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()
if(NOT CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
"Library postfix for debug builds. Normally left blank."
FORCE)
endif()
set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckStructHasMember)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
find_package(PkgConfig)
option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
option(ALSOFT_UTILS "Build utility programs" ON)
option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
option(ALSOFT_EXAMPLES "Build example programs" ON)
option(ALSOFT_INSTALL "Install main library" ON)
option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
if(DEFINED SHARE_INSTALL_DIR)
message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
endif()
if(DEFINED LIB_SUFFIX)
message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
endif()
if(DEFINED ALSOFT_CONFIG)
message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
endif()
if(DEFINED ALSOFT_HRTF_DEFS)
message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
endif()
if(DEFINED ALSOFT_AMBDEC_PRESETS)
message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
endif()
set(CPP_DEFS ) # C pre-processor, not C++
set(INC_PATHS )
set(C_FLAGS )
set(LINKER_FLAGS )
set(EXTRA_LIBS )
if(WIN32)
set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
if(MINGW)
set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
endif()
option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
if(MINGW)
option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
endif()
elseif(APPLE)
option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
endif()
# QNX's gcc do not uses /usr/include and /usr/lib pathes by default
if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
set(INC_PATHS ${INC_PATHS} /usr/include)
set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
endif()
# When the library is built for static linking, apps should define
# AL_LIBTYPE_STATIC when including the AL headers.
if(NOT LIBTYPE)
set(LIBTYPE SHARED)
endif()
set(LIB_MAJOR_VERSION "1")
set(LIB_MINOR_VERSION "21")
set(LIB_REVISION "1")
set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
set(EXPORT_DECL "")
# Require C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Prefer C11, but support C99 and C90 too.
set(CMAKE_C_STANDARD 11)
if(NOT WIN32)
# Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
if(NOT HAVE_POSIX_MEMALIGN_POSIX)
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
else()
set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
endif()
endif()
unset(OLD_REQUIRED_FLAGS)
endif()
# C99 has restrict, but C++ does not, so we can only utilize __restrict.
check_cxx_source_compiles("int *__restrict foo;
int main() { return 0; }" HAVE___RESTRICT)
if(HAVE___RESTRICT)
set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
else()
set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
endif()
# Some systems may need libatomic for atomic functions to work
set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
check_cxx_source_compiles("#include <atomic>
std::atomic<int> foo{0};
int main() { return foo.fetch_add(2); }"
HAVE_LIBATOMIC)
if(NOT HAVE_LIBATOMIC)
set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
else()
set(EXTRA_LIBS atomic ${EXTRA_LIBS})
endif()
unset(OLD_REQUIRED_LIBRARIES)
# Include liblog for Android logging
check_library_exists(log __android_log_print "" HAVE_LIBLOG)
if(HAVE_LIBLOG)
set(EXTRA_LIBS log ${EXTRA_LIBS})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
endif()
if(MSVC)
set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
if(HAVE_PERMISSIVE_SWITCH)
set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
endif()
set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324 /wd5030)
# Remove /W3, which is added by default, since we set /W4. Some build
# generators with MSVC complain about both /W3 and /W4 being specified.
foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
if(${flag_var} MATCHES "/W3")
string(REGEX REPLACE "/W3" "" ${flag_var} "${${flag_var}}")
endif()
endforeach()
if(NOT DXSDK_DIR)
string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
else()
string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
endif()
if(DXSDK_DIR)
message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
endif()
option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
if(FORCE_STATIC_VCRT)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif()
endforeach(flag_var)
endif()
else()
set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
-Wpedantic
$<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
if(ALSOFT_WERROR)
set(C_FLAGS ${C_FLAGS} -Werror)
endif()
# We want RelWithDebInfo to actually include debug stuff (define _DEBUG
# instead of NDEBUG)
foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "-DNDEBUG")
string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
endif()
endforeach()
check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
if(HAVE_FNO_MATH_ERRNO)
set(C_FLAGS ${C_FLAGS} -fno-math-errno)
endif()
option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
if(ALSOFT_STATIC_LIBGCC)
set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
unset(OLD_REQUIRED_LIBRARIES)
if(NOT HAVE_STATIC_LIBGCC_SWITCH)
message(FATAL_ERROR "Cannot static link libgcc")
endif()
set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
endif()
option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
if(ALSOFT_STATIC_STDCXX)
set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
unset(OLD_REQUIRED_LIBRARIES)
if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
message(FATAL_ERROR "Cannot static link libstdc++")
endif()
set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
endif()
if(WIN32)
option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
if(ALSOFT_STATIC_WINPTHREAD)
set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
unset(OLD_REQUIRED_LIBRARIES)
if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
message(FATAL_ERROR "Cannot static link libwinpthread")
endif()
set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
endif()
endif()
endif()
# Set visibility/export options if available
if(WIN32)
if(NOT LIBTYPE STREQUAL "STATIC")
set(EXPORT_DECL "__declspec(dllexport)")
endif()
else()
set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
# Yes GCC, really don't accept visibility modes you don't support
set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
if(HAVE_GCC_PROTECTED_VISIBILITY)
if(NOT LIBTYPE STREQUAL "STATIC")
set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
endif()
else()
check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
if(HAVE_GCC_DEFAULT_VISIBILITY)
if(NOT LIBTYPE STREQUAL "STATIC")
set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
endif()
endif()
endif()
if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
if(HAVE_VISIBILITY_HIDDEN_SWITCH)
set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
endif()
endif()
set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
endif()
set(SSE2_SWITCH "")
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
if(NOT MSVC)
# Yes GCC, really don't accept command line options you don't support
set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
endif()
check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
if(HAVE_MSSE2_SWITCH)
set(SSE2_SWITCH "-msse2")
endif()
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
unset(OLD_REQUIRED_FLAGS)
check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
check_include_file(arm_neon.h HAVE_ARM_NEON_H)
set(HAVE_SSE 0)
set(HAVE_SSE2 0)
set(HAVE_SSE3 0)
set(HAVE_SSE4_1 0)
set(HAVE_NEON 0)
# Check for SSE support
option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
if(HAVE_XMMINTRIN_H)
option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
if(ALSOFT_CPUEXT_SSE)
set(HAVE_SSE 1)
endif()
endif()
if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
endif()
option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
if(HAVE_EMMINTRIN_H)
option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
set(HAVE_SSE2 1)
endif()
endif()
if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
endif()
option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
if(HAVE_PMMINTRIN_H)
option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
set(HAVE_SSE3 1)
endif()
endif()
if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
endif()
option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
if(HAVE_SMMINTRIN_H)
option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
set(HAVE_SSE4_1 1)
endif()
endif()
if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
endif()
# Check for ARM Neon support
option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
if(HAVE_ARM_NEON_H)
option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
if(ALSOFT_CPUEXT_NEON)
check_c_source_compiles("#include <arm_neon.h>
int main()
{
int32x4_t ret4 = vdupq_n_s32(0);
return vgetq_lane_s32(ret4, 0);
}" HAVE_NEON_INTRINSICS)
if(HAVE_NEON_INTRINSICS)
set(HAVE_NEON 1)
endif()
endif()
endif()
if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
endif()
set(SSE_FLAGS )
set(FPMATH_SET "0")
if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
if(ALSOFT_ENABLE_SSE2_CODEGEN)
if(SSE2_SWITCH OR NOT MSVC)
check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
if(HAVE_MFPMATH_SSE_2)
set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
set(FPMATH_SET 2)
endif()
# SSE depends on a 16-byte aligned stack, and by default, GCC
# assumes the stack is suitably aligned. Older Linux code or other
# OSs don't guarantee this on 32-bit, so externally-callable
# functions need to ensure an aligned stack.
set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
elseif(MSVC)
check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
if(HAVE_ARCH_SSE2)
set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
set(FPMATH_SET 2)
endif()
endif()
endif()
endif()
if(HAVE_SSE2)
set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
foreach(flag_var ${SSE_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
endforeach()
check_c_source_compiles("#include <emmintrin.h>
int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
endif()
check_include_file(malloc.h HAVE_MALLOC_H)
check_include_file(cpuid.h HAVE_CPUID_H)
check_include_file(intrin.h HAVE_INTRIN_H)
check_include_file(guiddef.h HAVE_GUIDDEF_H)
if(NOT HAVE_GUIDDEF_H)
check_include_file(initguid.h HAVE_INITGUID_H)
endif()
# Some systems need libm for some math functions to work
set(MATH_LIB )
check_library_exists(m pow "" HAVE_LIBM)
if(HAVE_LIBM)
set(MATH_LIB ${MATH_LIB} m)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
endif()
# Some systems need to link with -lrt for clock_gettime as used by the common
# eaxmple functions.
set(RT_LIB )
check_library_exists(rt clock_gettime "" HAVE_LIBRT)
if(HAVE_LIBRT)
set(RT_LIB rt)
endif()
# Check for the dlopen API (for dynamicly loading backend libs)
if(ALSOFT_DLOPEN)
check_include_file(dlfcn.h HAVE_DLFCN_H)
check_library_exists(dl dlopen "" HAVE_LIBDL)
if(HAVE_LIBDL)
set(EXTRA_LIBS dl ${EXTRA_LIBS})
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
endif()
endif()
# Check for a cpuid intrinsic
if(HAVE_CPUID_H)
check_c_source_compiles("#include <cpuid.h>
int main()
{
unsigned int eax, ebx, ecx, edx;
return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
}" HAVE_GCC_GET_CPUID)
endif()
if(HAVE_INTRIN_H)
check_c_source_compiles("#include <intrin.h>
int main()
{
int regs[4];
__cpuid(regs, 0);
return regs[0];
}" HAVE_CPUID_INTRINSIC)
endif()
check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
if(NOT WIN32)
# We need pthreads outside of Windows, for semaphores. It's also used to
# set the priority and name of threads, when possible.
check_include_file(pthread.h HAVE_PTHREAD_H)
if(NOT HAVE_PTHREAD_H)
message(FATAL_ERROR "PThreads is required for non-Windows builds!")
endif()
check_c_compiler_flag(-pthread HAVE_PTHREAD)
if(HAVE_PTHREAD)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
set(C_FLAGS ${C_FLAGS} -pthread)
set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
endif()
check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
# Some systems need pthread_np.h to get pthread_setname_np
check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
if(HAVE_PTHREAD_NP_H)
check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
if(NOT HAVE_PTHREAD_SETNAME_NP)
check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
else()
check_c_source_compiles("
#include <pthread.h>
#include <pthread_np.h>
int main()
{
pthread_setname_np(\"testname\");
return 0;
}"
PTHREAD_SETNAME_NP_ONE_PARAM
)
check_c_source_compiles("
#include <pthread.h>
#include <pthread_np.h>
int main()
{
pthread_setname_np(pthread_self(), \"%s\", \"testname\");
return 0;
}"
PTHREAD_SETNAME_NP_THREE_PARAMS
)
endif()
else()
check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
if(NOT HAVE_PTHREAD_SETNAME_NP)
check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
else()
check_c_source_compiles("
#include <pthread.h>
int main()
{
pthread_setname_np(\"testname\");
return 0;
}"
PTHREAD_SETNAME_NP_ONE_PARAM
)
check_c_source_compiles("
#include <pthread.h>
int main()
{
pthread_setname_np(pthread_self(), \"%s\", \"testname\");
return 0;
}"
PTHREAD_SETNAME_NP_THREE_PARAMS
)
endif()
endif()
endif()
check_symbol_exists(getopt unistd.h HAVE_GETOPT)
# Common sources used by both the OpenAL implementation library, the OpenAL
# router, and certain tools and examples.
set(COMMON_OBJS
common/albit.h
common/albyte.h
common/alcomplex.cpp
common/alcomplex.h
common/aldeque.h
common/alfstream.cpp
common/alfstream.h
common/almalloc.cpp
common/almalloc.h
common/alnumeric.h
common/aloptional.h
common/alspan.h
common/alstring.cpp
common/alstring.h
common/atomic.h
common/comptr.h
common/dynload.cpp
common/dynload.h
common/intrusive_ptr.h
common/math_defs.h
common/opthelpers.h
common/phase_shifter.h
common/polyphase_resampler.cpp
common/polyphase_resampler.h
common/pragmadefs.h
common/ringbuffer.cpp
common/ringbuffer.h
common/strutils.cpp
common/strutils.h
common/threads.cpp
common/threads.h
common/vecmat.h
common/vector.h)
# Core library routines
set(CORE_OBJS
core/ambdec.cpp
core/ambdec.h
core/ambidefs.cpp
core/ambidefs.h
core/async_event.h
core/bformatdec.cpp
core/bformatdec.h
core/bs2b.cpp
core/bs2b.h
core/bsinc_defs.h
core/bsinc_tables.cpp
core/bsinc_tables.h
core/bufferline.h
core/buffer_storage.cpp
core/buffer_storage.h
core/context.cpp
core/context.h
core/converter.cpp
core/converter.h
core/cpu_caps.cpp
core/cpu_caps.h
core/devformat.cpp
core/devformat.h
core/device.cpp
core/device.h
core/except.cpp
core/except.h
core/filters/biquad.h
core/filters/biquad.cpp
core/filters/nfc.cpp
core/filters/nfc.h
core/filters/splitter.cpp
core/filters/splitter.h
core/fmt_traits.cpp
core/fmt_traits.h
core/fpu_ctrl.cpp
core/fpu_ctrl.h
core/front_stablizer.h
core/helpers.cpp
core/helpers.h
core/hrtf.cpp
core/hrtf.h
core/logging.cpp
core/logging.h
core/mastering.cpp
core/mastering.h
core/mixer.cpp
core/mixer.h
core/resampler_limits.h
core/uhjfilter.cpp
core/uhjfilter.h
core/uiddefs.cpp
core/voice.cpp
core/voice.h
core/voice_change.h)
set(HAVE_RTKIT 0)
option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
find_package(DBus1 QUIET)
if(DBus1_FOUND)
option(ALSOFT_RTKIT "Enable RTKit support" ON)
if(ALSOFT_RTKIT)
set(HAVE_RTKIT 1)
set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h core/rtkit.cpp core/rtkit.h)
if(WIN32 OR HAVE_DLFCN_H)
set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
else()
set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
endif()
endif()
else()
set(MISSING_VARS "")
if(NOT DBus1_INCLUDE_DIRS)
set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
endif()
if(NOT DBus1_LIBRARIES)
set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
endif()
message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
unset(MISSING_VARS)
endif()
if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
message(FATAL_ERROR "Failed to enabled required RTKit support")
endif()
# Default mixers, always available
set(CORE_OBJS ${CORE_OBJS}
core/mixer/defs.h
core/mixer/hrtfbase.h
core/mixer/hrtfdefs.h
core/mixer/mixer_c.cpp)
# AL and related routines
set(OPENAL_OBJS
al/auxeffectslot.cpp
al/auxeffectslot.h
al/buffer.cpp
al/buffer.h
al/effect.cpp
al/effect.h
al/effects/autowah.cpp
al/effects/chorus.cpp
al/effects/compressor.cpp
al/effects/convolution.cpp
al/effects/dedicated.cpp
al/effects/distortion.cpp
al/effects/echo.cpp
al/effects/effects.h
al/effects/equalizer.cpp
al/effects/fshifter.cpp
al/effects/modulator.cpp
al/effects/null.cpp
al/effects/pshifter.cpp
al/effects/reverb.cpp
al/effects/vmorpher.cpp
al/error.cpp
al/event.cpp
al/event.h
al/extension.cpp
al/filter.cpp
al/filter.h
al/listener.cpp
al/listener.h
al/source.cpp
al/source.h
al/state.cpp)
# ALC and related routines
set(ALC_OBJS
alc/alc.cpp
alc/alu.cpp
alc/alu.h
alc/alconfig.cpp
alc/alconfig.h
alc/context.cpp
alc/context.h
alc/device.cpp
alc/device.h
alc/effectslot.cpp
alc/effectslot.h
alc/effects/base.h
alc/effects/autowah.cpp
alc/effects/chorus.cpp
alc/effects/compressor.cpp
alc/effects/convolution.cpp
alc/effects/dedicated.cpp
alc/effects/distortion.cpp
alc/effects/echo.cpp
alc/effects/equalizer.cpp
alc/effects/fshifter.cpp
alc/effects/modulator.cpp
alc/effects/null.cpp
alc/effects/pshifter.cpp
alc/effects/reverb.cpp
alc/effects/vmorpher.cpp
alc/inprogext.h
alc/panning.cpp)
# Include SIMD mixers
set(CPU_EXTS "Default")
if(HAVE_SSE)
set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp)
set(CPU_EXTS "${CPU_EXTS}, SSE")
endif()
if(HAVE_SSE2)
set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
set(CPU_EXTS "${CPU_EXTS}, SSE2")
endif()
if(HAVE_SSE3)
set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
set(CPU_EXTS "${CPU_EXTS}, SSE3")
endif()
if(HAVE_SSE4_1)
set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
endif()
if(HAVE_NEON)
set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp)
set(CPU_EXTS "${CPU_EXTS}, Neon")
endif()
set(HAVE_ALSA 0)
set(HAVE_OSS 0)
set(HAVE_PIPEWIRE 0)
set(HAVE_SOLARIS 0)
set(HAVE_SNDIO 0)
set(HAVE_DSOUND 0)
set(HAVE_WASAPI 0)
set(HAVE_WINMM 0)
set(HAVE_PORTAUDIO 0)
set(HAVE_PULSEAUDIO 0)
set(HAVE_COREAUDIO 0)
set(HAVE_OPENSL 0)
set(HAVE_OBOE 0)
set(HAVE_WAVE 0)
set(HAVE_SDL2 0)
if(WIN32 OR HAVE_DLFCN_H)
set(IS_LINKED "")
macro(ADD_BACKEND_LIBS _LIBS)
endmacro()
else()
set(IS_LINKED " (linked)")
macro(ADD_BACKEND_LIBS _LIBS)
set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
endmacro()
endif()
set(BACKENDS "")
set(ALC_OBJS ${ALC_OBJS}
alc/backends/base.cpp
alc/backends/base.h
# Default backends, always available
alc/backends/loopback.cpp
alc/backends/loopback.h
alc/backends/null.cpp
alc/backends/null.h
)
# Check ALSA backend
option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
find_package(ALSA)
if(ALSA_FOUND)
option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
if(ALSOFT_BACKEND_ALSA)
set(HAVE_ALSA 1)
set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
add_backend_libs(${ALSA_LIBRARIES})
set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
endif()
endif()
if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
message(FATAL_ERROR "Failed to enabled required ALSA backend")
endif()
# Check OSS backend
option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
find_package(OSS)
if(OSS_FOUND)
option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
if(ALSOFT_BACKEND_OSS)
set(HAVE_OSS 1)
set(BACKENDS "${BACKENDS} OSS,")
set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
if(OSS_LIBRARIES)
set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
endif()
set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
endif()
endif()
if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
message(FATAL_ERROR "Failed to enabled required OSS backend")
endif()
# Check PipeWire backend
option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
if(PkgConfig_FOUND)
pkg_check_modules(PIPEWIRE libpipewire-0.3)
if(PIPEWIRE_FOUND)
option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
if(ALSOFT_BACKEND_PIPEWIRE)
set(HAVE_PIPEWIRE 1)
set(BACKENDS "${BACKENDS} PipeWire,")
set(ALC_OBJS ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
endif()
endif()
endif()
if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
message(FATAL_ERROR "Failed to enabled required PipeWire backend")
endif()
# Check Solaris backend
option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
find_package(AudioIO)
if(AUDIOIO_FOUND)
option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
if(ALSOFT_BACKEND_SOLARIS)
set(HAVE_SOLARIS 1)
set(BACKENDS "${BACKENDS} Solaris,")
set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
endif()
endif()
if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
message(FATAL_ERROR "Failed to enabled required Solaris backend")
endif()
# Check SndIO backend
option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
find_package(SoundIO)
if(SOUNDIO_FOUND)
option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
if(ALSOFT_BACKEND_SNDIO)
set(HAVE_SNDIO 1)
set(BACKENDS "${BACKENDS} SndIO (linked),")
set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
endif()
endif()
if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
message(FATAL_ERROR "Failed to enabled required SndIO backend")
endif()
# Check Windows-only backends
option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
if(WIN32)
# Check MMSystem backend
option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
if(ALSOFT_BACKEND_WINMM)
set(HAVE_WINMM 1)
set(BACKENDS "${BACKENDS} WinMM,")
set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
# There doesn't seem to be good way to search for winmm.lib for MSVC.
# find_library doesn't find it without being told to look in a specific
# place in the WindowsSDK, but it links anyway. If there ends up being
# Windows targets without this, another means to detect it is needed.
set(EXTRA_LIBS winmm ${EXTRA_LIBS})
endif()
# Check DSound backend
check_include_file(dsound.h HAVE_DSOUND_H)
if(DXSDK_DIR)
find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
DOC "The DirectSound include directory")
endif()
if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
if(ALSOFT_BACKEND_DSOUND)
set(HAVE_DSOUND 1)
set(BACKENDS "${BACKENDS} DirectSound,")
set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
if(NOT HAVE_DSOUND_H)
set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
endif()
endif()
endif()