Replace a couple for_each uses to workaround a MSVC 2019 bug
[openal-soft.git] / CMakeLists.txt
blob12a2416d9675510b91ca50fa88193ee906f18505
1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.13)
4 enable_testing()
6 if(APPLE)
7     # The workaround for try_compile failing with code signing
8     # since cmake-3.18.2, not required
9     set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
10         ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}
11         "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
12         "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
13     set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
14     set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
15 endif()
17 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
18     # Fix compile failure with armv7 deployment target >= 11.0, xcode clang
19     # will report:
20     # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
21     # iOS 10 is the maximum deployment target for 32-bit targets
22     # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
23     # deployment target
24     if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
25         if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
26             OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
27             message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
28             set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
29                 FORCE)
30         endif()
31     endif()
32 elseif(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
33     set(ALSOFT_UWP TRUE)
34 endif()
36 if(COMMAND CMAKE_POLICY)
37     cmake_policy(SET CMP0003 NEW)
38     cmake_policy(SET CMP0005 NEW)
39     if(POLICY CMP0020)
40         cmake_policy(SET CMP0020 NEW)
41     endif(POLICY CMP0020)
42     if(POLICY CMP0042)
43         cmake_policy(SET CMP0042 NEW)
44     endif(POLICY CMP0042)
45     if(POLICY CMP0054)
46         cmake_policy(SET CMP0054 NEW)
47     endif(POLICY CMP0054)
48     if(POLICY CMP0058)
49         cmake_policy(SET CMP0058 NEW)
50     endif(POLICY CMP0058)
51     if(POLICY CMP0063)
52         cmake_policy(SET CMP0063 NEW)
53     endif(POLICY CMP0063)
54     if(POLICY CMP0075)
55         cmake_policy(SET CMP0075 NEW)
56     endif(POLICY CMP0075)
57     if(POLICY CMP0092)
58         cmake_policy(SET CMP0092 NEW)
59     endif(POLICY CMP0092)
60     if(POLICY CMP0117)
61         cmake_policy(SET CMP0117 NEW)
62     endif(POLICY CMP0117)
63 endif(COMMAND CMAKE_POLICY)
65 project(OpenAL)
67 if(NOT CMAKE_BUILD_TYPE)
68     set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
69         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
70         FORCE)
71 endif()
72 if(NOT CMAKE_DEBUG_POSTFIX)
73     set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
74         "Library postfix for debug builds. Normally left blank."
75         FORCE)
76 endif()
78 set(DEFAULT_TARGET_PROPS
79     # Require C++17.
80     CXX_STANDARD 17
81     CXX_STANDARD_REQUIRED TRUE
82     # Prefer C11, but support C99 and earlier when possible.
83     C_STANDARD 11)
85 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
87 include(CheckFunctionExists)
88 include(CheckLibraryExists)
89 include(CheckIncludeFile)
90 include(CheckIncludeFiles)
91 include(CheckSymbolExists)
92 include(CheckCCompilerFlag)
93 include(CheckCXXCompilerFlag)
94 include(CheckCSourceCompiles)
95 include(CheckCXXSourceCompiles)
96 include(CheckStructHasMember)
97 include(CMakePackageConfigHelpers)
98 include(GNUInstallDirs)
100 find_package(PkgConfig)
101 find_package(SDL2 QUIET)
104 option(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
106 option(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
108 option(ALSOFT_UTILS "Build utility programs"  ON)
109 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
111 option(ALSOFT_EXAMPLES  "Build example programs"  ON)
112 option(ALSOFT_TESTS "Build test programs"  OFF)
114 option(ALSOFT_INSTALL "Install main library" ON)
115 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
116 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
117 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
118 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
119 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
120 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
122 option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
124 option(ALSOFT_SEARCH_INSTALL_DATADIR "Search the installation data directory" OFF)
125 if(ALSOFT_SEARCH_INSTALL_DATADIR)
126     set(ALSOFT_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
127 endif()
129 if(DEFINED SHARE_INSTALL_DIR)
130     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
131     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
132 endif()
134 if(DEFINED LIB_SUFFIX)
135     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
136 endif()
137 if(DEFINED ALSOFT_CONFIG)
138     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
139 endif()
140 if(DEFINED ALSOFT_HRTF_DEFS)
141     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
142 endif()
143 if(DEFINED ALSOFT_AMBDEC_PRESETS)
144     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
145 endif()
148 set(CPP_DEFS ) # C pre-processor, not C++
149 set(INC_PATHS )
150 set(C_FLAGS )
151 set(LINKER_FLAGS )
152 set(LINKER_FLAGS_DEBUG )
153 set(LINKER_FLAGS_RELEASE )
154 set(EXTRA_LIBS )
156 if(WIN32)
157     set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
158     if(MINGW)
159         set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
160     endif()
162     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
163     if(MINGW)
164         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
165     endif()
166 elseif(APPLE)
167     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
168 endif()
171 # QNX's gcc do not uses /usr/include and /usr/lib paths by default
172 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
173     set(INC_PATHS ${INC_PATHS} /usr/include)
174     set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
175 endif()
177 # When the library is built for static linking, apps should define
178 # AL_LIBTYPE_STATIC when including the AL headers.
179 if(NOT LIBTYPE)
180     set(LIBTYPE SHARED)
181 endif()
183 set(LIB_MAJOR_VERSION "1")
184 set(LIB_MINOR_VERSION "23")
185 set(LIB_REVISION "1")
186 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
187 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
189 set(EXPORT_DECL "")
192 # Some systems erroneously require the __STDC_FORMAT_MACROS macro to be defined
193 # to get the fixed-width integer type formatter macros.
194 check_cxx_source_compiles("#include <cinttypes>
195 #include <cstdio>
196 int main()
198     int64_t i64{};
199     std::printf(\"%\" PRId64, i64);
201 HAVE_STDC_FORMAT_MACROS)
202 if(NOT HAVE_STDC_FORMAT_MACROS)
203     set(CPP_DEFS ${CPP_DEFS} __STDC_FORMAT_MACROS)
204 endif()
206 # Some systems may need libatomic for atomic functions to work
207 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
208 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
209 check_cxx_source_compiles("#include <atomic>
210 std::atomic<int> foo{0};
211 int main() { return foo.fetch_add(2); }"
212 HAVE_LIBATOMIC)
213 if(NOT HAVE_LIBATOMIC)
214     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
215 else()
216     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
217 endif()
218 unset(OLD_REQUIRED_LIBRARIES)
220 if(ANDROID)
221     # Include liblog for Android logging
222     check_library_exists(log __android_log_print "" HAVE_LIBLOG)
223     if(HAVE_LIBLOG)
224         set(EXTRA_LIBS log ${EXTRA_LIBS})
225         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
226     endif()
227 endif()
229 if(MSVC)
230     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
231     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
232     if(HAVE_PERMISSIVE_SWITCH)
233         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
234     endif()
235     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030 /wd5051)
237     if(NOT DXSDK_DIR)
238         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
239     else()
240         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
241     endif()
242     if(DXSDK_DIR)
243         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
244     endif()
246     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
247     if(FORCE_STATIC_VCRT)
248         foreach(flag_var
249                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
250                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
251                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
252                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
253             if(${flag_var} MATCHES "/MD")
254                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
255             endif()
256         endforeach(flag_var)
257     endif()
258 else()
259     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
260         -Wpedantic
261         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
263     check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
264     if(HAVE_WNO_CXX20_ATTR_EXT)
265         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
266     else()
267         check_cxx_compiler_flag(-Wno-c++20-extensions HAVE_WNO_CXX20_EXT)
268         if(HAVE_WNO_CXX20_EXT)
269             set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-extensions>)
270         endif()
271     endif()
273     check_cxx_compiler_flag(-Wno-interference-size HAVE_WNO_INTERFERENCE_SIZE)
274     if(HAVE_WNO_INTERFERENCE_SIZE)
275         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>)
276     endif()
278     if(ALSOFT_WERROR)
279         set(C_FLAGS ${C_FLAGS} -Werror)
280     endif()
282     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
283     # instead of NDEBUG)
284     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
285         if(${flag_var} MATCHES "-DNDEBUG")
286             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
287         endif()
288     endforeach()
290     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
291     if(HAVE_FNO_MATH_ERRNO)
292         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
293     endif()
295     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
296     if(ALSOFT_STATIC_LIBGCC)
297         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
298         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
299         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
300         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
301         unset(OLD_REQUIRED_LIBRARIES)
303         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
304             message(FATAL_ERROR "Cannot static link libgcc")
305         endif()
306         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
307     endif()
309     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
310     if(ALSOFT_STATIC_STDCXX)
311         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
312         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-static-libstdc++")
313         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
314         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
315         unset(OLD_REQUIRED_LIBRARIES)
317         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
318             message(FATAL_ERROR "Cannot static link libstdc++")
319         endif()
320         set(LINKER_FLAGS ${LINKER_FLAGS} "-static-libstdc++")
321     endif()
323     if(WIN32)
324         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
325         if(ALSOFT_STATIC_WINPTHREAD)
326             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
327             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state")
328             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
329             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
330             unset(OLD_REQUIRED_LIBRARIES)
332             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
333                 message(FATAL_ERROR "Cannot static link libwinpthread")
334             endif()
335             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state")
336         endif()
337     endif()
338 endif()
340 # Set visibility/export options if available
341 if(NOT LIBTYPE STREQUAL "STATIC")
342     if(WIN32)
343         set(EXPORT_DECL "__declspec(dllexport)")
344     else()
345         set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
346         # Yes GCC, really don't accept visibility modes you don't support
347         set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
349         check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
350                                 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
351         if(HAVE_GCC_PROTECTED_VISIBILITY)
352             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
353         else()
354             check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
355                                     int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
356             if(HAVE_GCC_DEFAULT_VISIBILITY)
357                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
358             endif()
359         endif()
360         if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
361             set(CMAKE_C_VISIBILITY_PRESET hidden)
362             set(CMAKE_CXX_VISIBILITY_PRESET hidden)
363         endif()
365         set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
366     endif()
367 endif()
370 set(SSE2_SWITCH "")
372 if(NOT MSVC)
373     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
374     # Yes GCC, really don't accept command line options you don't support
375     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
376     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
377     if(HAVE_MSSE2_SWITCH)
378         set(SSE2_SWITCH "-msse2")
379     endif()
380     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
381     unset(OLD_REQUIRED_FLAGS)
382 endif()
384 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
385 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
386 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
387 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
388 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
390 set(HAVE_SSE        0)
391 set(HAVE_SSE2       0)
392 set(HAVE_SSE3       0)
393 set(HAVE_SSE4_1     0)
394 set(HAVE_NEON       0)
396 # Check for SSE support
397 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
398 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
399 if(ALSOFT_CPUEXT_SSE AND HAVE_XMMINTRIN_H)
400     set(HAVE_SSE 1)
401 endif()
402 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
403     message(FATAL_ERROR "Failed to enable required SSE CPU extensions")
404 endif()
406 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
407 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
408 if(ALSOFT_CPUEXT_SSE2 AND HAVE_SSE AND HAVE_EMMINTRIN_H)
409     set(HAVE_SSE2 1)
410 endif()
411 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
412     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
413 endif()
415 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
416 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
417 if(ALSOFT_CPUEXT_SSE3 AND HAVE_SSE2 AND HAVE_PMMINTRIN_H)
418     set(HAVE_SSE3 1)
419 endif()
420 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
421     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
422 endif()
424 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
425 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
426 if(ALSOFT_CPUEXT_SSE4_1 AND HAVE_SSE3 AND HAVE_SMMINTRIN_H)
427     set(HAVE_SSE4_1 1)
428 endif()
429 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
430     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
431 endif()
433 # Check for ARM Neon support
434 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
435 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
436 if(ALSOFT_CPUEXT_NEON AND HAVE_ARM_NEON_H)
437     check_c_source_compiles("#include <arm_neon.h>
438         int main()
439         {
440             int32x4_t ret4 = vdupq_n_s32(0);
441             return vgetq_lane_s32(ret4, 0);
442         }" HAVE_NEON_INTRINSICS)
443     if(HAVE_NEON_INTRINSICS)
444         set(HAVE_NEON 1)
445     endif()
446 endif()
447 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
448     message(FATAL_ERROR "Failed to enable required ARM NEON CPU extensions")
449 endif()
452 set(ALSOFT_FORCE_ALIGN )
453 set(SSE_FLAGS )
454 set(FPMATH_SET "0")
455 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
456     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
457     if(ALSOFT_ENABLE_SSE2_CODEGEN)
458         if(MSVC)
459             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
460             if(HAVE_ARCH_SSE2)
461                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
462                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
463                 set(FPMATH_SET 2)
464             endif()
465         elseif(SSE2_SWITCH)
466             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
467             if(HAVE_MFPMATH_SSE_2)
468                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
469                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
470                 set(FPMATH_SET 2)
471             endif()
472             # SSE depends on a 16-byte aligned stack, and by default, GCC
473             # assumes the stack is suitably aligned. Older Linux code or other
474             # OSs don't guarantee this on 32-bit, so externally-callable
475             # functions need to ensure an aligned stack.
476             set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
477             set(ALSOFT_FORCE_ALIGN "__attribute__((force_align_arg_pointer))")
478         endif()
479     endif()
480 endif()
482 if(HAVE_SSE2)
483     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
484     foreach(flag_var ${SSE_FLAGS})
485         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
486     endforeach()
488     check_c_source_compiles("#include <emmintrin.h>
489         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
491     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
492 endif()
495 check_include_file(cpuid.h HAVE_CPUID_H)
496 check_include_file(intrin.h HAVE_INTRIN_H)
497 check_include_file(guiddef.h HAVE_GUIDDEF_H)
499 # Some systems need libm for some math functions to work
500 set(MATH_LIB )
501 check_library_exists(m pow "" HAVE_LIBM)
502 if(HAVE_LIBM)
503     set(MATH_LIB ${MATH_LIB} m)
504     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
505 endif()
507 # Some systems need to link with -lrt for clock_gettime as used by the common
508 # eaxmple functions.
509 set(RT_LIB )
510 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
511 if(HAVE_LIBRT)
512     set(RT_LIB rt)
513 endif()
515 # Check for the dlopen API (for dynamically loading backend libs)
516 if(ALSOFT_DLOPEN)
517     check_include_file(dlfcn.h HAVE_DLFCN_H)
518     check_library_exists(dl dlopen "" HAVE_LIBDL)
519     if(HAVE_LIBDL)
520         set(EXTRA_LIBS dl ${EXTRA_LIBS})
521         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
522     endif()
523 endif()
525 # Check for a cpuid intrinsic
526 if(HAVE_CPUID_H)
527     check_c_source_compiles("#include <cpuid.h>
528         int main()
529         {
530             unsigned int eax, ebx, ecx, edx;
531             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
532         }" HAVE_GCC_GET_CPUID)
533 endif()
534 if(HAVE_INTRIN_H)
535     check_c_source_compiles("#include <intrin.h>
536         int main()
537         {
538             int regs[4];
539             __cpuid(regs, 0);
540             return regs[0];
541         }" HAVE_CPUID_INTRINSIC)
542 endif()
544 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
546 if(NOT WIN32)
547     # We need pthreads outside of Windows, for semaphores. It's also used to
548     # set the priority and name of threads, when possible.
549     check_include_file(pthread.h HAVE_PTHREAD_H)
550     if(NOT HAVE_PTHREAD_H)
551         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
552     endif()
554     check_c_compiler_flag(-pthread HAVE_PTHREAD)
555     if(HAVE_PTHREAD)
556         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
557         set(C_FLAGS ${C_FLAGS} -pthread)
558         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
559     endif()
561     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
563     # Some systems need pthread_np.h to get pthread_setname_np
564     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
565     if(HAVE_PTHREAD_NP_H)
566         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
567         if(NOT HAVE_PTHREAD_SETNAME_NP)
568             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
569         endif()
570     else()
571         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
572         if(NOT HAVE_PTHREAD_SETNAME_NP)
573             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
574         endif()
575     endif()
576 endif()
579 # Common sources used by both the OpenAL implementation library, the OpenAL
580 # router, and certain tools and examples.
581 set(COMMON_OBJS
582     common/alassert.cpp
583     common/alassert.h
584     common/albit.h
585     common/alcomplex.cpp
586     common/alcomplex.h
587     common/almalloc.h
588     common/alnumbers.h
589     common/alnumeric.h
590     common/alsem.cpp
591     common/alsem.h
592     common/alspan.h
593     common/alstring.cpp
594     common/alstring.h
595     common/althrd_setname.cpp
596     common/althrd_setname.h
597     common/althreads.h
598     common/altraits.h
599     common/atomic.h
600     common/comptr.h
601     common/dynload.cpp
602     common/dynload.h
603     common/flexarray.h
604     common/intrusive_ptr.h
605     common/opthelpers.h
606     common/pffft.cpp
607     common/pffft.h
608     common/phase_shifter.h
609     common/polyphase_resampler.cpp
610     common/polyphase_resampler.h
611     common/pragmadefs.h
612     common/ringbuffer.cpp
613     common/ringbuffer.h
614     common/strutils.cpp
615     common/strutils.h
616     common/vecmat.h
617     common/vector.h)
619 # Core library routines
620 set(CORE_OBJS
621     core/ambdec.cpp
622     core/ambdec.h
623     core/ambidefs.cpp
624     core/ambidefs.h
625     core/async_event.h
626     core/bformatdec.cpp
627     core/bformatdec.h
628     core/bs2b.cpp
629     core/bs2b.h
630     core/bsinc_defs.h
631     core/bsinc_tables.cpp
632     core/bsinc_tables.h
633     core/bufferline.h
634     core/buffer_storage.cpp
635     core/buffer_storage.h
636     core/context.cpp
637     core/context.h
638     core/converter.cpp
639     core/converter.h
640     core/cpu_caps.cpp
641     core/cpu_caps.h
642     core/cubic_defs.h
643     core/cubic_tables.cpp
644     core/cubic_tables.h
645     core/devformat.cpp
646     core/devformat.h
647     core/device.cpp
648     core/device.h
649     core/effects/base.h
650     core/effectslot.cpp
651     core/effectslot.h
652     core/except.cpp
653     core/except.h
654     core/filters/biquad.h
655     core/filters/biquad.cpp
656     core/filters/nfc.cpp
657     core/filters/nfc.h
658     core/filters/splitter.cpp
659     core/filters/splitter.h
660     core/fmt_traits.cpp
661     core/fmt_traits.h
662     core/fpu_ctrl.cpp
663     core/fpu_ctrl.h
664     core/front_stablizer.h
665     core/helpers.cpp
666     core/helpers.h
667     core/hrtf.cpp
668     core/hrtf.h
669     core/logging.cpp
670     core/logging.h
671     core/mastering.cpp
672     core/mastering.h
673     core/mixer.cpp
674     core/mixer.h
675     core/resampler_limits.h
676     core/storage_formats.cpp
677     core/storage_formats.h
678     core/uhjfilter.cpp
679     core/uhjfilter.h
680     core/uiddefs.cpp
681     core/voice.cpp
682     core/voice.h
683     core/voice_change.h)
685 set(HAVE_RTKIT 0)
686 if(NOT WIN32)
687     option(ALSOFT_RTKIT "Enable RTKit support" ON)
688     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
689     if(ALSOFT_RTKIT)
690         find_package(DBus1 QUIET)
691         if(NOT DBus1_FOUND AND PkgConfig_FOUND)
692             pkg_check_modules(DBUS dbus-1)
693         endif()
694         if(DBus1_FOUND OR DBUS_FOUND)
695             set(HAVE_RTKIT 1)
696             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
697                 core/rtkit.cpp core/rtkit.h)
698             if(NOT DBus1_FOUND)
699                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
700                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
701                 if(NOT HAVE_DLFCN_H)
702                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
703                 endif()
704             elseif(HAVE_DLFCN_H)
705                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
706                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
707             else()
708                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
709             endif()
710         endif()
711     else()
712         set(MISSING_VARS "")
713         if(NOT DBus1_INCLUDE_DIRS)
714             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
715         endif()
716         if(NOT DBus1_LIBRARIES)
717             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
718         endif()
719         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
720         unset(MISSING_VARS)
721     endif()
722 endif()
723 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
724     message(FATAL_ERROR "Failed to enable required RTKit support")
725 endif()
727 # Default mixers, always available
728 set(CORE_OBJS ${CORE_OBJS}
729     core/mixer/defs.h
730     core/mixer/hrtfbase.h
731     core/mixer/hrtfdefs.h
732     core/mixer/mixer_c.cpp)
734 # AL and related routines
735 set(OPENAL_OBJS
736     al/auxeffectslot.cpp
737     al/auxeffectslot.h
738     al/buffer.cpp
739     al/buffer.h
740     al/debug.cpp
741     al/debug.h
742     al/direct_defs.h
743     al/effect.cpp
744     al/effect.h
745     al/effects/autowah.cpp
746     al/effects/chorus.cpp
747     al/effects/compressor.cpp
748     al/effects/convolution.cpp
749     al/effects/dedicated.cpp
750     al/effects/distortion.cpp
751     al/effects/echo.cpp
752     al/effects/effects.cpp
753     al/effects/effects.h
754     al/effects/equalizer.cpp
755     al/effects/fshifter.cpp
756     al/effects/modulator.cpp
757     al/effects/null.cpp
758     al/effects/pshifter.cpp
759     al/effects/reverb.cpp
760     al/effects/vmorpher.cpp
761     al/error.cpp
762     al/error.h
763     al/event.cpp
764     al/event.h
765     al/extension.cpp
766     al/filter.cpp
767     al/filter.h
768     al/listener.cpp
769     al/listener.h
770     al/source.cpp
771     al/source.h
772     al/state.cpp)
774 # ALC and related routines
775 set(ALC_OBJS
776     alc/alc.cpp
777     alc/alu.cpp
778     alc/alu.h
779     alc/alconfig.cpp
780     alc/alconfig.h
781     alc/context.cpp
782     alc/context.h
783     alc/device.cpp
784     alc/device.h
785     alc/effects/base.h
786     alc/effects/autowah.cpp
787     alc/effects/chorus.cpp
788     alc/effects/compressor.cpp
789     alc/effects/convolution.cpp
790     alc/effects/dedicated.cpp
791     alc/effects/distortion.cpp
792     alc/effects/echo.cpp
793     alc/effects/equalizer.cpp
794     alc/effects/fshifter.cpp
795     alc/effects/modulator.cpp
796     alc/effects/null.cpp
797     alc/effects/pshifter.cpp
798     alc/effects/reverb.cpp
799     alc/effects/vmorpher.cpp
800     alc/events.cpp
801     alc/events.h
802     alc/export_list.h
803     alc/inprogext.h
804     alc/panning.cpp)
806 if(ALSOFT_EAX)
807     set(OPENAL_OBJS
808         ${OPENAL_OBJS}
809         al/eax/api.cpp
810         al/eax/api.h
811         al/eax/call.cpp
812         al/eax/call.h
813         al/eax/effect.h
814         al/eax/exception.cpp
815         al/eax/exception.h
816         al/eax/fx_slot_index.cpp
817         al/eax/fx_slot_index.h
818         al/eax/fx_slots.cpp
819         al/eax/fx_slots.h
820         al/eax/globals.h
821         al/eax/utils.cpp
822         al/eax/utils.h
823         al/eax/x_ram.h
824     )
825 endif()
827 # Include SIMD mixers
828 set(CPU_EXTS "Default")
829 if(HAVE_SSE)
830     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
831     set(CPU_EXTS "${CPU_EXTS}, SSE")
832 endif()
833 if(HAVE_SSE2)
834     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
835     set(CPU_EXTS "${CPU_EXTS}, SSE2")
836 endif()
837 if(HAVE_SSE3)
838     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
839     set(CPU_EXTS "${CPU_EXTS}, SSE3")
840 endif()
841 if(HAVE_SSE4_1)
842     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
843     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
844 endif()
845 if(HAVE_NEON)
846     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
847     set(CPU_EXTS "${CPU_EXTS}, Neon")
848 endif()
851 set(HAVE_ALSA       0)
852 set(HAVE_OSS        0)
853 set(HAVE_PIPEWIRE   0)
854 set(HAVE_SOLARIS    0)
855 set(HAVE_SNDIO      0)
856 set(HAVE_DSOUND     0)
857 set(HAVE_WASAPI     0)
858 set(HAVE_WINMM      0)
859 set(HAVE_PORTAUDIO  0)
860 set(HAVE_PULSEAUDIO 0)
861 set(HAVE_COREAUDIO  0)
862 set(HAVE_OPENSL     0)
863 set(HAVE_OBOE       0)
864 set(HAVE_WAVE       0)
865 set(HAVE_SDL2       0)
867 if(WIN32 OR HAVE_DLFCN_H)
868     set(IS_LINKED "")
869     macro(ADD_BACKEND_LIBS _LIBS)
870     endmacro()
871 else()
872     set(IS_LINKED " (linked)")
873     macro(ADD_BACKEND_LIBS _LIBS)
874         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
875     endmacro()
876 endif()
878 set(BACKENDS "")
879 set(ALC_OBJS  ${ALC_OBJS}
880     alc/backends/base.cpp
881     alc/backends/base.h
882     # Default backends, always available
883     alc/backends/loopback.cpp
884     alc/backends/loopback.h
885     alc/backends/null.cpp
886     alc/backends/null.h
889 # Check PipeWire backend
890 option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
891 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
892 if(ALSOFT_BACKEND_PIPEWIRE AND PkgConfig_FOUND)
893     pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
894     if(PIPEWIRE_FOUND)
895         set(HAVE_PIPEWIRE 1)
896         set(BACKENDS  "${BACKENDS} PipeWire${IS_LINKED},")
897         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
898         add_backend_libs(${PIPEWIRE_LIBRARIES})
899         set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
900     endif()
901 endif()
902 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
903     message(FATAL_ERROR "Failed to enable required PipeWire backend")
904 endif()
906 # Check PulseAudio backend
907 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
908 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
909 if(ALSOFT_BACKEND_PULSEAUDIO)
910     find_package(PulseAudio)
911     if(PULSEAUDIO_FOUND)
912         set(HAVE_PULSEAUDIO 1)
913         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
914         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
915         add_backend_libs(${PULSEAUDIO_LIBRARY})
916         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIR})
917     endif()
918 endif()
919 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
920     message(FATAL_ERROR "Failed to enable required PulseAudio backend")
921 endif()
923 if(NOT WIN32)
924     # Check ALSA backend
925     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
926     option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
927     if(ALSOFT_BACKEND_ALSA)
928         find_package(ALSA)
929         if(ALSA_FOUND)
930             set(HAVE_ALSA 1)
931             set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
932             set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
933             add_backend_libs(${ALSA_LIBRARIES})
934             set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
935         endif()
936     endif()
938     # Check OSS backend
939     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
940     option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
941     if(ALSOFT_BACKEND_OSS)
942         find_package(OSS)
943         if(OSS_FOUND)
944             set(HAVE_OSS 1)
945             set(BACKENDS  "${BACKENDS} OSS,")
946             set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
947             if(OSS_LIBRARIES)
948                 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
949             endif()
950             set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
951         endif()
952     endif()
954     # Check Solaris backend
955     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
956     option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
957     if(ALSOFT_BACKEND_SOLARIS)
958         find_package(AudioIO)
959         if(AUDIOIO_FOUND)
960             set(HAVE_SOLARIS 1)
961             set(BACKENDS  "${BACKENDS} Solaris,")
962             set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
963             set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
964         endif()
965     endif()
967     # Check SndIO backend (disabled by default on non-BSDs)
968     if(BSD)
969         option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
970     else()
971         option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" OFF)
972     endif()
973     option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
974     if(ALSOFT_BACKEND_SNDIO)
975         find_package(SndIO)
976         if(SNDIO_FOUND)
977             set(HAVE_SNDIO 1)
978             set(BACKENDS  "${BACKENDS} SndIO (linked),")
979             set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
980             set(EXTRA_LIBS ${SNDIO_LIBRARIES} ${EXTRA_LIBS})
981             set(INC_PATHS ${INC_PATHS} ${SNDIO_INCLUDE_DIRS})
982         endif()
983     endif()
984 endif()
985 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
986     message(FATAL_ERROR "Failed to enable required ALSA backend")
987 endif()
988 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
989     message(FATAL_ERROR "Failed to enable required OSS backend")
990 endif()
991 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
992     message(FATAL_ERROR "Failed to enable required Solaris backend")
993 endif()
994 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
995     message(FATAL_ERROR "Failed to enable required SndIO backend")
996 endif()
998 # Check Windows-only backends
999 if(WIN32)
1000     if (NOT ALSOFT_UWP)
1001         # Check MMSystem backend
1002         option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
1003         option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
1004         if(ALSOFT_BACKEND_WINMM)
1005             set(HAVE_WINMM 1)
1006             set(BACKENDS "${BACKENDS} WinMM,")
1007             set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
1008             # There doesn't seem to be good way to search for winmm.lib for MSVC.
1009             # find_library doesn't find it without being told to look in a specific
1010             # place in the WindowsSDK, but it links anyway. If there ends up being
1011             # Windows targets without this, another means to detect it is needed.
1012             set(EXTRA_LIBS winmm ${EXTRA_LIBS})
1013         endif()
1015         # Check DSound backend
1016         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1017         option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1018         if(ALSOFT_BACKEND_DSOUND)
1019             check_include_file(dsound.h HAVE_DSOUND_H)
1020             if(DXSDK_DIR)
1021                 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
1022                     PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
1023                     DOC "The DirectSound include directory")
1024             endif()
1025             if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1026                 set(HAVE_DSOUND 1)
1027                 set(BACKENDS "${BACKENDS} DirectSound,")
1028                 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1030                 if(NOT HAVE_DSOUND_H)
1031                     set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1032                 endif()
1033             endif()
1034         endif()
1035     endif()
1037     # Check for WASAPI backend
1038     option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1039     option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1040     if(ALSOFT_BACKEND_WASAPI)
1041         check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1042         if(HAVE_MMDEVICEAPI_H)
1043             set(HAVE_WASAPI 1)
1044             set(BACKENDS  "${BACKENDS} WASAPI,")
1045             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1046         endif()
1047     endif()
1048 endif()
1049 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1050     message(FATAL_ERROR "Failed to enable required WinMM backend")
1051 endif()
1052 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1053     message(FATAL_ERROR "Failed to enable required DSound backend")
1054 endif()
1055 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1056     message(FATAL_ERROR "Failed to enable required WASAPI backend")
1057 endif()
1059 # Check JACK backend
1060 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1061 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1062 if(ALSOFT_BACKEND_JACK)
1063     find_package(JACK)
1064     if(JACK_FOUND)
1065         set(HAVE_JACK 1)
1066         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1067         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1068         add_backend_libs(${JACK_LIBRARIES})
1069         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1070     endif()
1071 endif()
1072 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1073     message(FATAL_ERROR "Failed to enable required JACK backend")
1074 endif()
1076 # Check CoreAudio backend
1077 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1078 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1079 if(ALSOFT_BACKEND_COREAUDIO)
1080     find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1081     find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1082     if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1083         set(HAVE_COREAUDIO 1)
1084         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1085         set(BACKENDS  "${BACKENDS} CoreAudio,")
1087         set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1088         if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1089             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1090             if(COREFOUNDATION_FRAMEWORK)
1091                 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1092             endif()
1093         else()
1094             set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1095         endif()
1097         # Some versions of OSX may need the AudioToolbox framework. Add it if
1098         # it's found.
1099         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1100         if(AUDIOTOOLBOX_LIBRARY)
1101             set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1102         endif()
1104         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1105     endif()
1106 endif()
1107 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1108     message(FATAL_ERROR "Failed to enable required CoreAudio backend")
1109 endif()
1111 # Check for Oboe (Android) backend
1112 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1113 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1114 if(ALSOFT_BACKEND_OBOE)
1115     set(OBOE_TARGET )
1116     if(ANDROID)
1117         set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1118         if(OBOE_SOURCE)
1119             add_subdirectory(${OBOE_SOURCE} ./oboe EXCLUDE_FROM_ALL)
1120             set(OBOE_TARGET oboe)
1121         else()
1122             find_package(oboe CONFIG)
1123             if(NOT TARGET oboe::oboe)
1124                 find_package(Oboe)
1125             endif()
1126             if(TARGET oboe::oboe)
1127                 set(OBOE_TARGET "oboe::oboe")
1128             endif()
1129         endif()
1130     endif()
1132     if(OBOE_TARGET)
1133         set(HAVE_OBOE 1)
1134         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1135         set(BACKENDS  "${BACKENDS} Oboe,")
1136         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1137     endif()
1138 endif()
1139 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1140     message(FATAL_ERROR "Failed to enable required Oboe backend")
1141 endif()
1143 # Check for OpenSL (Android) backend
1144 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1145 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1146 if(ALSOFT_BACKEND_OPENSL)
1147     find_package(OpenSL)
1148     if(OPENSL_FOUND)
1149         set(HAVE_OPENSL 1)
1150         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1151         set(BACKENDS  "${BACKENDS} OpenSL,")
1152         set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1153         set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1154     endif()
1155 endif()
1156 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1157     message(FATAL_ERROR "Failed to enable required OpenSL backend")
1158 endif()
1160 # Check PortAudio backend
1161 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1162 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1163 if(ALSOFT_BACKEND_PORTAUDIO)
1164     find_package(PortAudio)
1165     if(PORTAUDIO_FOUND)
1166         set(HAVE_PORTAUDIO 1)
1167         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1168         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1169         add_backend_libs(${PORTAUDIO_LIBRARIES})
1170         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1171     endif()
1172 endif()
1173 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1174     message(FATAL_ERROR "Failed to enable required PortAudio backend")
1175 endif()
1177 # Check for SDL2 backend
1178 # Off by default, since it adds a runtime dependency
1179 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1180 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1181 if(ALSOFT_BACKEND_SDL2)
1182     if(SDL2_FOUND)
1183         set(HAVE_SDL2 1)
1184         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1185         set(BACKENDS  "${BACKENDS} SDL2,")
1186         set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1187     else()
1188         message(STATUS "Could NOT find SDL2")
1189     endif()
1190 endif()
1191 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1192     message(FATAL_ERROR "Failed to enable required SDL2 backend")
1193 endif()
1195 # Optionally enable the Wave Writer backend
1196 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1197 if(ALSOFT_BACKEND_WAVE)
1198     set(HAVE_WAVE 1)
1199     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1200     set(BACKENDS  "${BACKENDS} WaveFile,")
1201 endif()
1203 # This is always available
1204 set(BACKENDS  "${BACKENDS} Null")
1207 find_package(Git)
1208 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1209     set(GIT_DIR "${OpenAL_SOURCE_DIR}/.git")
1211     # Check if this is a submodule, if it is then find the .git directory
1212     if(NOT IS_DIRECTORY "${OpenAL_SOURCE_DIR}/.git")
1213         file(READ ${GIT_DIR} submodule)
1214         string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE ${submodule})
1215         string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
1216         get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
1217         get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
1218     endif()
1220     # Get the current working branch and its latest abbreviated commit hash
1221     add_custom_command(OUTPUT "${OpenAL_BINARY_DIR}/version_witness.txt"
1222         BYPRODUCTS "${OpenAL_BINARY_DIR}/version.h"
1223         COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1224             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1225             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1226         COMMAND ${CMAKE_COMMAND} -E touch "${OpenAL_BINARY_DIR}/version_witness.txt"
1227         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1228         MAIN_DEPENDENCY "${OpenAL_SOURCE_DIR}/version.h.in"
1229         DEPENDS "${GIT_DIR}/index" "${OpenAL_SOURCE_DIR}/version.cmake"
1230         VERBATIM
1231     )
1233     add_custom_target(build_version DEPENDS "${OpenAL_BINARY_DIR}/version_witness.txt")
1234 else()
1235     set(GIT_BRANCH "UNKNOWN")
1236     set(GIT_COMMIT_HASH "unknown")
1237     configure_file(
1238         "${OpenAL_SOURCE_DIR}/version.h.in"
1239         "${OpenAL_BINARY_DIR}/version.h")
1240 endif()
1243 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1244 if(ALSOFT_EMBED_HRTF_DATA)
1245     macro(make_hrtf_header FILENAME VARNAME)
1246         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1247         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.txt")
1249         add_custom_command(OUTPUT "${outfile}"
1250             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1251                 -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1252             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1253             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1254             VERBATIM
1255         )
1256         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1257     endmacro()
1259     make_hrtf_header("Default HRTF.mhr" "default_hrtf")
1260 endif()
1263 if(ALSOFT_UTILS)
1264     find_package(MySOFA)
1265     if(NOT ALSOFT_NO_CONFIG_UTIL)
1266         find_package(Qt5Widgets QUIET)
1267         if(NOT Qt5Widgets_FOUND)
1268             message(STATUS "Could NOT find Qt5Widgets")
1269         endif()
1270     endif()
1271 endif()
1272 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1273     find_package(SndFile)
1274     if(SDL2_FOUND)
1275         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1276     endif()
1277 endif()
1279 if(NOT WIN32)
1280     set(LIBNAME "openal")
1281 else()
1282     set(LIBNAME "OpenAL32")
1283 endif()
1285 # Needed for openal.pc.in
1286 set(prefix ${CMAKE_INSTALL_PREFIX})
1287 set(exec_prefix "\${prefix}")
1288 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1289 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1290 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1291 set(PACKAGE_VERSION "${LIB_VERSION}")
1292 set(PKG_CONFIG_CFLAGS )
1293 set(PKG_CONFIG_PRIVATE_LIBS )
1294 if(LIBTYPE STREQUAL "STATIC")
1295     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1296     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1297         # If this is already a linker flag, or is a full path+file, add it
1298         # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1299         # it's a name intended to be dressed as -lname.
1300         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1301             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1302         elseif(FLAG MATCHES "^SDL2::SDL2")
1303             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1304         else()
1305             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1306         endif()
1307     endforeach()
1308 endif()
1310 # End configuration
1311 configure_file(
1312     "${OpenAL_SOURCE_DIR}/config.h.in"
1313     "${OpenAL_BINARY_DIR}/config.h")
1314 configure_file(
1315     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1316     "${OpenAL_BINARY_DIR}/openal.pc"
1317     @ONLY)
1320 add_library(alcommon STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1321 target_include_directories(alcommon PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include
1322     PUBLIC ${OpenAL_SOURCE_DIR}/common)
1323 target_compile_definitions(alcommon PRIVATE ${CPP_DEFS})
1324 target_compile_options(alcommon PRIVATE ${C_FLAGS})
1325 set_target_properties(alcommon PROPERTIES ${DEFAULT_TARGET_PROPS} POSITION_INDEPENDENT_CODE TRUE)
1328 unset(HAS_ROUTER)
1329 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1331 # Build main library
1332 if(LIBTYPE STREQUAL "STATIC")
1333     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1334     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1335     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1337     if(WIN32)
1338         # This option is for static linking OpenAL Soft into another project
1339         # that already defines the IDs. It is up to that project to ensure all
1340         # required IDs are defined.
1341         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1342         if(ALSOFT_NO_UID_DEFS)
1343             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1344         endif()
1345     endif()
1346 else()
1347     set(RC_CONFIG resources/openal32.rc)
1348     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1349         add_library(OpenAL SHARED
1350             resources/router.rc
1351             router/router.cpp
1352             router/router.h
1353             router/alc.cpp
1354             router/al.cpp
1355         )
1356         target_compile_definitions(OpenAL
1357             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1358             "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1359         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1360         target_link_libraries(OpenAL PRIVATE alcommon ${LINKER_FLAGS})
1361         target_include_directories(OpenAL
1362           PUBLIC
1363             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1364             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1365           PRIVATE
1366             ${OpenAL_SOURCE_DIR}/common
1367             ${OpenAL_BINARY_DIR}
1368         )
1369         set_target_properties(OpenAL PROPERTIES ${DEFAULT_TARGET_PROPS} PREFIX ""
1370             OUTPUT_NAME ${LIBNAME})
1371         if(TARGET build_version)
1372             add_dependencies(OpenAL build_version)
1373         endif()
1374         set(HAS_ROUTER 1)
1376         set(LIBNAME "soft_oal")
1377         set(IMPL_TARGET soft_oal)
1378         set(RC_CONFIG resources/soft_oal.rc)
1379     endif()
1381     # !important: for osx framework public header works, the headers must be in
1382     # the project
1383     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h
1384         include/AL/efx-presets.h)
1386     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1387         ${TARGET_PUBLIC_HEADERS})
1388     if(WIN32)
1389         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1390     endif()
1391     target_link_libraries(${IMPL_TARGET} PRIVATE alcommon ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1393     if(ALSOFT_UWP)
1394         set(ALSOFT_CPPWINRT_VERSION "2.0.230706.1" CACHE STRING "The soft-oal default cppwinrt version")
1395         
1396         find_program(NUGET_EXE NAMES nuget)
1397         if(NOT NUGET_EXE)
1398             message("NUGET.EXE not found.")
1399             message(FATAL_ERROR "Please install this executable, and run CMake again.")
1400         endif()
1402         exec_program(${NUGET_EXE}
1403             ARGS install "Microsoft.Windows.CppWinRT" -Version ${ALSOFT_CPPWINRT_VERSION} -ExcludeVersion -OutputDirectory "\"${CMAKE_BINARY_DIR}/packages\"")
1405         set_target_properties(${IMPL_TARGET} PROPERTIES
1406             VS_PROJECT_IMPORT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.props
1407         )
1408         target_link_libraries(${IMPL_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.targets)
1409     endif()
1411     if(NOT WIN32 AND NOT APPLE)
1412         # FIXME: This doesn't put a dependency on the version script. Changing
1413         # the version script will not cause a relink as it should.
1414         target_link_options(${IMPL_TARGET} PRIVATE
1415             "-Wl,--version-script=${OpenAL_SOURCE_DIR}/libopenal.version")
1416     endif()
1418     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1419         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1420         set(LIBNAME "soft_oal")
1421         if(GIT_FOUND)
1422             execute_process(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1423                 TIMEOUT 5
1424                 OUTPUT_VARIABLE BUNDLE_VERSION
1425                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1426         else()
1427             set(BUNDLE_VERSION 1)
1428         endif()
1430         # Build: Fix rpath in iOS shared libraries
1431         # If this flag is not set, the final dylib binary ld path will be
1432         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1433         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1434         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1435             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1436         endif()
1438         set_target_properties(${IMPL_TARGET} PROPERTIES
1439             FRAMEWORK TRUE
1440             FRAMEWORK_VERSION C
1441             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1442             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1443             MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1444             MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1445             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1446             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1447             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1448             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1449             MACOSX_RPATH TRUE)
1450     endif()
1451 endif()
1453 target_include_directories(${IMPL_TARGET}
1454   PUBLIC
1455     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1456   INTERFACE
1457     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1458     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1459     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1460   PRIVATE
1461     ${INC_PATHS}
1462     ${OpenAL_BINARY_DIR}
1463     ${OpenAL_SOURCE_DIR}
1464     ${OpenAL_SOURCE_DIR}/common
1467 set_target_properties(${IMPL_TARGET} PROPERTIES ${DEFAULT_TARGET_PROPS}
1468     OUTPUT_NAME ${LIBNAME}
1469     VERSION ${LIB_VERSION}
1470     SOVERSION ${LIB_MAJOR_VERSION}
1472 target_compile_definitions(${IMPL_TARGET}
1473     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES $<$<BOOL:${ALSOFT_EAX}>:ALSOFT_EAX>
1474     "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1475 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1477 if(TARGET build_version)
1478     add_dependencies(${IMPL_TARGET} build_version)
1479 endif()
1481 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1482     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1483     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1484         message(STATUS "")
1485         if(NOT SED_EXECUTABLE)
1486             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1487         endif()
1488         if(NOT CMAKE_DLLTOOL)
1489             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1490         endif()
1491     else()
1492         target_link_options(OpenAL PRIVATE "-Wl,--output-def,${PROJECT_BINARY_DIR}/OpenAL32.def")
1493         add_custom_command(TARGET OpenAL POST_BUILD
1494             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1495             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1496             # Technically OpenAL32.def was created by the build, but cmake
1497             # doesn't recognize it due to -Wl,--output-def,OpenAL32.def being
1498             # manually specified. But declaring the file here allows it to be
1499             # properly cleaned, e.g. during make clean.
1500             BYPRODUCTS OpenAL32.def OpenAL32.lib
1501             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1502             VERBATIM
1503         )
1504     endif()
1505 endif()
1507 if(HAS_ROUTER)
1508     message(STATUS "")
1509     message(STATUS "Building DLL router")
1510 endif()
1512 message(STATUS "")
1513 message(STATUS "Building OpenAL with support for the following backends:")
1514 message(STATUS "   ${BACKENDS}")
1515 message(STATUS "")
1516 message(STATUS "Building with support for CPU extensions:")
1517 message(STATUS "    ${CPU_EXTS}")
1518 message(STATUS "")
1519 if(FPMATH_SET)
1520     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1521     message(STATUS "")
1522 endif()
1523 if(ALSOFT_UWP)
1524     message(STATUS "Building with UWP support")
1525     message(STATUS "")
1526 endif()
1527 if(ALSOFT_EAX)
1528     message(STATUS "Building with legacy EAX extension support")
1529     message(STATUS "")
1530 endif()
1532 if(ALSOFT_EMBED_HRTF_DATA)
1533     message(STATUS "Embedding HRTF datasets")
1534     message(STATUS "")
1535 endif()
1537 # An alias for sub-project builds
1538 add_library(OpenAL::OpenAL ALIAS OpenAL)
1540 # Install main library
1541 if(ALSOFT_INSTALL)
1542     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1543         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1544     install(TARGETS OpenAL EXPORT OpenAL
1545         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1546         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1547         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1548         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1549         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1550     export(TARGETS OpenAL
1551         NAMESPACE OpenAL::
1552         FILE OpenALTargets.cmake)
1553     install(EXPORT OpenAL
1554         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1555         NAMESPACE OpenAL::
1556         FILE OpenALTargets.cmake)
1557     install(DIRECTORY include/AL
1558         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1559     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1560         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1561     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1562         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1563     if(TARGET soft_oal)
1564         install(TARGETS soft_oal
1565             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1566     endif()
1567     message(STATUS "Installing library and headers")
1568 else()
1569     message(STATUS "NOT installing library and headers")
1570 endif()
1572 if(ALSOFT_INSTALL_CONFIG)
1573     install(FILES alsoftrc.sample
1574         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1575     message(STATUS "Installing sample configuration")
1576 endif()
1578 if(ALSOFT_INSTALL_HRTF_DATA)
1579     install(DIRECTORY hrtf
1580         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1581     message(STATUS "Installing HRTF data files")
1582 endif()
1584 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1585     install(DIRECTORY presets
1586         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1587     message(STATUS "Installing AmbDec presets")
1588 endif()
1589 message(STATUS "")
1591 set(UNICODE_FLAG )
1592 if(MINGW)
1593     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1594 endif()
1595 set(EXTRA_INSTALLS )
1596 if(ALSOFT_UTILS)
1597     add_executable(openal-info utils/openal-info.c)
1598     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1599     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1600     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1601     set_target_properties(openal-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1602     if(ALSOFT_INSTALL_EXAMPLES)
1603         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1604     endif()
1606     if(SNDFILE_FOUND)
1607         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1608         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1609         target_include_directories(uhjdecoder
1610             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1611         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1612         target_link_libraries(uhjdecoder PUBLIC alcommon
1613             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1614         set_target_properties(uhjdecoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1616         add_executable(uhjencoder utils/uhjencoder.cpp)
1617         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1618         target_include_directories(uhjencoder
1619             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1620         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1621         target_link_libraries(uhjencoder PUBLIC alcommon
1622             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1623         set_target_properties(uhjencoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1624     endif()
1626     if(MYSOFA_FOUND)
1627         set(SOFA_SUPPORT_SRCS
1628             utils/sofa-support.cpp
1629             utils/sofa-support.h)
1630         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1631         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1632         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1633         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1634         target_link_libraries(sofa-support PUBLIC alcommon MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1635         set_target_properties(sofa-support PROPERTIES ${DEFAULT_TARGET_PROPS})
1637         set(MAKEMHR_SRCS
1638             utils/makemhr/loaddef.cpp
1639             utils/makemhr/loaddef.h
1640             utils/makemhr/loadsofa.cpp
1641             utils/makemhr/loadsofa.h
1642             utils/makemhr/makemhr.cpp
1643             utils/makemhr/makemhr.h)
1644         add_executable(makemhr ${MAKEMHR_SRCS})
1645         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1646         target_include_directories(makemhr
1647             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1648         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1649         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1650         set_target_properties(makemhr PROPERTIES ${DEFAULT_TARGET_PROPS})
1651         if(ALSOFT_INSTALL_EXAMPLES)
1652             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1653         endif()
1655         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1656         add_executable(sofa-info ${SOFAINFO_SRCS})
1657         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1658         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1659         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1660         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1661         set_target_properties(sofa-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1662     endif()
1663     message(STATUS "Building utility programs")
1665     if(NOT ALSOFT_NO_CONFIG_UTIL)
1666         add_subdirectory(utils/alsoft-config)
1667     endif()
1668     message(STATUS "")
1669 endif()
1672 # Add a static library with common functions used by multiple example targets
1673 add_library(al-excommon STATIC EXCLUDE_FROM_ALL
1674     examples/common/alhelpers.c
1675     examples/common/alhelpers.h)
1676 target_compile_definitions(al-excommon PUBLIC ${CPP_DEFS})
1677 target_include_directories(al-excommon PUBLIC ${OpenAL_SOURCE_DIR}/common)
1678 target_compile_options(al-excommon PUBLIC ${C_FLAGS})
1679 target_link_libraries(al-excommon PUBLIC OpenAL PRIVATE ${RT_LIB})
1680 set_target_properties(al-excommon PROPERTIES ${DEFAULT_TARGET_PROPS})
1682 if(ALSOFT_EXAMPLES)
1683     add_executable(altonegen examples/altonegen.c)
1684     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} al-excommon ${UNICODE_FLAG})
1685     set_target_properties(altonegen PROPERTIES ${DEFAULT_TARGET_PROPS})
1687     add_executable(alrecord examples/alrecord.c)
1688     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} al-excommon ${UNICODE_FLAG})
1689     set_target_properties(alrecord PROPERTIES ${DEFAULT_TARGET_PROPS})
1691     add_executable(allafplay examples/allafplay.cpp)
1692     target_link_libraries(allafplay PRIVATE ${LINKER_FLAGS} alcommon al-excommon ${UNICODE_FLAG})
1693     set_target_properties(allafplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1695     if(ALSOFT_INSTALL_EXAMPLES)
1696         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord allafplay)
1697     endif()
1699     message(STATUS "Building example programs")
1701     if(SNDFILE_FOUND)
1702         add_executable(alplay examples/alplay.c)
1703         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon
1704             ${UNICODE_FLAG})
1705         set_target_properties(alplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1707         add_executable(alstream examples/alstream.c)
1708         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon
1709             ${UNICODE_FLAG})
1710         set_target_properties(alstream PROPERTIES ${DEFAULT_TARGET_PROPS})
1712         add_executable(alreverb examples/alreverb.c)
1713         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon
1714             ${UNICODE_FLAG})
1715         set_target_properties(alreverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1717         add_executable(almultireverb examples/almultireverb.c)
1718         target_link_libraries(almultireverb
1719             PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon ${MATH_LIB} ${UNICODE_FLAG})
1720         set_target_properties(almultireverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1722         add_executable(allatency examples/allatency.c)
1723         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon
1724             ${UNICODE_FLAG})
1725         set_target_properties(allatency PROPERTIES ${DEFAULT_TARGET_PROPS})
1727         add_executable(alhrtf examples/alhrtf.c)
1728         target_link_libraries(alhrtf
1729             PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon ${MATH_LIB} ${UNICODE_FLAG})
1730         set_target_properties(alhrtf PROPERTIES ${DEFAULT_TARGET_PROPS})
1732         add_executable(alstreamcb examples/alstreamcb.cpp)
1733         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon
1734             ${UNICODE_FLAG})
1735         set_target_properties(alstreamcb PROPERTIES ${DEFAULT_TARGET_PROPS})
1737         add_executable(aldirect examples/aldirect.cpp)
1738         target_link_libraries(aldirect PRIVATE ${LINKER_FLAGS} SndFile::SndFile al-excommon
1739             ${UNICODE_FLAG})
1740         set_target_properties(aldirect PROPERTIES ${DEFAULT_TARGET_PROPS})
1742         add_executable(alconvolve examples/alconvolve.c)
1743         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} alcommon SndFile::SndFile
1744             al-excommon ${UNICODE_FLAG})
1745         set_target_properties(alconvolve PROPERTIES ${DEFAULT_TARGET_PROPS})
1747         if(ALSOFT_INSTALL_EXAMPLES)
1748             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1749                 alhrtf aldirect)
1750         endif()
1752         message(STATUS "Building SndFile example programs")
1753     endif()
1755     if(SDL2_FOUND)
1756         add_executable(alloopback examples/alloopback.c)
1757         target_link_libraries(alloopback
1758             PRIVATE ${LINKER_FLAGS} SDL2::SDL2 al-excommon ${MATH_LIB})
1759         set_target_properties(alloopback PROPERTIES ${DEFAULT_TARGET_PROPS})
1761         if(ALSOFT_INSTALL_EXAMPLES)
1762             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1763         endif()
1765         message(STATUS "Building SDL example programs")
1767         set(FFVER_OK FALSE)
1768         if(FFMPEG_FOUND)
1769             set(FFVER_OK TRUE)
1770             if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1771                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1772                 set(FFVER_OK FALSE)
1773             endif()
1774             if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1775                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1776                 set(FFVER_OK FALSE)
1777             endif()
1778             if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1779                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1780                 set(FFVER_OK FALSE)
1781             endif()
1782             if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1783                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1784                 set(FFVER_OK FALSE)
1785             endif()
1786             if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1787                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1788                 set(FFVER_OK FALSE)
1789             endif()
1790         endif()
1791         if(FFVER_OK)
1792             add_executable(alffplay examples/alffplay.cpp)
1793             target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1794             target_link_libraries(alffplay
1795                 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} al-excommon)
1796             set_target_properties(alffplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1798             if(ALSOFT_INSTALL_EXAMPLES)
1799                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1800             endif()
1801             message(STATUS "Building SDL+FFmpeg example programs")
1802         endif()
1803     endif()
1804     message(STATUS "")
1805 endif()
1807 if (ALSOFT_TESTS)
1808 add_subdirectory(tests)
1809 endif()
1811 if(EXTRA_INSTALLS)
1812     install(TARGETS ${EXTRA_INSTALLS}
1813         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1814         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1815         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1816         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1817 endif()