Make a couple lambdas static
[openal-soft.git] / CMakeLists.txt
blob4a22b5384234d3dde43c1e98f210ec20405b4195
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     # NOTE: _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR is temporary. When building on
231     # VS 2022 17.10 or newer, but using an older runtime, mutexes can crash
232     # when locked. Ideally the runtime should be updated on the system, but
233     # until the update becomes more widespread, this helps avoid some pain
234     # points.
235     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
236     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
237     if(HAVE_PERMISSIVE_SWITCH)
238         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
239     endif()
240     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030 /wd5051
241         $<$<COMPILE_LANGUAGE:CXX>:/EHsc>)
243     if(NOT DXSDK_DIR)
244         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
245     else()
246         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
247     endif()
248     if(DXSDK_DIR)
249         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
250     endif()
252     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
253     if(FORCE_STATIC_VCRT)
254         foreach(flag_var
255                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
256                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
257                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
258                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
259             if(${flag_var} MATCHES "/MD")
260                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
261             endif()
262         endforeach(flag_var)
263     endif()
264 else()
265     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
266         -Wpedantic
267         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
269     check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
270     if(HAVE_WNO_CXX20_ATTR_EXT)
271         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
272     else()
273         check_cxx_compiler_flag(-Wno-c++20-extensions HAVE_WNO_CXX20_EXT)
274         if(HAVE_WNO_CXX20_EXT)
275             set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-extensions>)
276         endif()
277     endif()
279     check_cxx_compiler_flag(-Wno-interference-size HAVE_WNO_INTERFERENCE_SIZE)
280     if(HAVE_WNO_INTERFERENCE_SIZE)
281         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-interference-size>)
282     endif()
284     if(ALSOFT_WERROR)
285         set(C_FLAGS ${C_FLAGS} -Werror)
286     endif()
288     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
289     if(HAVE_FNO_MATH_ERRNO)
290         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
291     endif()
293     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
294     if(ALSOFT_STATIC_LIBGCC)
295         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
296         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
297         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
298         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
299         unset(OLD_REQUIRED_LIBRARIES)
301         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
302             message(FATAL_ERROR "Cannot static link libgcc")
303         endif()
304         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
305     endif()
307     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
308     if(ALSOFT_STATIC_STDCXX)
309         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
310         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-static-libstdc++")
311         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
312         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
313         unset(OLD_REQUIRED_LIBRARIES)
315         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
316             message(FATAL_ERROR "Cannot static link libstdc++")
317         endif()
318         set(LINKER_FLAGS ${LINKER_FLAGS} "-static-libstdc++")
319     endif()
321     if(WIN32)
322         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
323         if(ALSOFT_STATIC_WINPTHREAD)
324             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
325             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state")
326             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
327             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
328             unset(OLD_REQUIRED_LIBRARIES)
330             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
331                 message(FATAL_ERROR "Cannot static link libwinpthread")
332             endif()
333             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,-lwinpthread,--pop-state")
334         endif()
335     endif()
336 endif()
338 # Set visibility/export options if available
339 if(NOT LIBTYPE STREQUAL "STATIC")
340     if(WIN32)
341         set(EXPORT_DECL "__declspec(dllexport)")
342     else()
343         set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
344         # Yes GCC, really don't accept visibility modes you don't support
345         set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
347         check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
348                                 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
349         if(HAVE_GCC_PROTECTED_VISIBILITY)
350             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
351         else()
352             check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
353                                     int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
354             if(HAVE_GCC_DEFAULT_VISIBILITY)
355                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
356             endif()
357         endif()
358         if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
359             set(CMAKE_C_VISIBILITY_PRESET hidden)
360             set(CMAKE_CXX_VISIBILITY_PRESET hidden)
361         endif()
363         set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
364     endif()
365 endif()
368 set(SSE2_SWITCH "")
370 if(NOT MSVC)
371     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
372     # Yes GCC, really don't accept command line options you don't support
373     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
374     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
375     if(HAVE_MSSE2_SWITCH)
376         set(SSE2_SWITCH "-msse2")
377     endif()
378     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
379     unset(OLD_REQUIRED_FLAGS)
380 endif()
382 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
383 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
384 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
385 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
386 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
388 set(HAVE_SSE        0)
389 set(HAVE_SSE2       0)
390 set(HAVE_SSE3       0)
391 set(HAVE_SSE4_1     0)
392 set(HAVE_NEON       0)
394 # Check for SSE support
395 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
396 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
397 if(ALSOFT_CPUEXT_SSE AND HAVE_XMMINTRIN_H)
398     set(HAVE_SSE 1)
399 endif()
400 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
401     message(FATAL_ERROR "Failed to enable required SSE CPU extensions")
402 endif()
404 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
405 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
406 if(ALSOFT_CPUEXT_SSE2 AND HAVE_SSE AND HAVE_EMMINTRIN_H)
407     set(HAVE_SSE2 1)
408 endif()
409 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
410     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
411 endif()
413 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
414 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
415 if(ALSOFT_CPUEXT_SSE3 AND HAVE_SSE2 AND HAVE_PMMINTRIN_H)
416     set(HAVE_SSE3 1)
417 endif()
418 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
419     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
420 endif()
422 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
423 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
424 if(ALSOFT_CPUEXT_SSE4_1 AND HAVE_SSE3 AND HAVE_SMMINTRIN_H)
425     set(HAVE_SSE4_1 1)
426 endif()
427 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
428     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
429 endif()
431 # Check for ARM Neon support
432 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
433 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
434 if(ALSOFT_CPUEXT_NEON AND HAVE_ARM_NEON_H)
435     check_c_source_compiles("#include <arm_neon.h>
436         int main()
437         {
438             int32x4_t ret4 = vdupq_n_s32(0);
439             return vgetq_lane_s32(ret4, 0);
440         }" HAVE_NEON_INTRINSICS)
441     if(HAVE_NEON_INTRINSICS)
442         set(HAVE_NEON 1)
443     endif()
444 endif()
445 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
446     message(FATAL_ERROR "Failed to enable required ARM NEON CPU extensions")
447 endif()
450 set(ALSOFT_FORCE_ALIGN )
451 set(SSE_FLAGS )
452 set(FPMATH_SET "0")
453 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
454     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
455     if(ALSOFT_ENABLE_SSE2_CODEGEN)
456         if(MSVC)
457             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
458             if(HAVE_ARCH_SSE2)
459                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
460                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
461                 set(FPMATH_SET 2)
462             endif()
463         elseif(SSE2_SWITCH)
464             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
465             if(HAVE_MFPMATH_SSE_2)
466                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
467                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
468                 set(FPMATH_SET 2)
469             endif()
470             # SSE depends on a 16-byte aligned stack, and by default, GCC
471             # assumes the stack is suitably aligned. Older Linux code or other
472             # OSs don't guarantee this on 32-bit, so externally-callable
473             # functions need to ensure an aligned stack.
474             set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
475             set(ALSOFT_FORCE_ALIGN "__attribute__((force_align_arg_pointer))")
476         endif()
477     endif()
478 endif()
480 if(HAVE_SSE2)
481     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
482     foreach(flag_var ${SSE_FLAGS})
483         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
484     endforeach()
486     check_c_source_compiles("#include <emmintrin.h>
487         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
489     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
490 endif()
493 check_include_file(cpuid.h HAVE_CPUID_H)
494 check_include_file(intrin.h HAVE_INTRIN_H)
495 check_include_file(guiddef.h HAVE_GUIDDEF_H)
497 # Some systems need libm for some math functions to work
498 set(MATH_LIB )
499 check_library_exists(m pow "" HAVE_LIBM)
500 if(HAVE_LIBM)
501     set(MATH_LIB ${MATH_LIB} m)
502     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
503 endif()
505 # Some systems need to link with -lrt for clock_gettime as used by the common
506 # eaxmple functions.
507 set(RT_LIB )
508 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
509 if(HAVE_LIBRT)
510     set(RT_LIB rt)
511 endif()
513 # Check for the dlopen API (for dynamically loading backend libs)
514 if(ALSOFT_DLOPEN)
515     check_include_file(dlfcn.h HAVE_DLFCN_H)
516     check_library_exists(dl dlopen "" HAVE_LIBDL)
517     if(HAVE_LIBDL)
518         set(EXTRA_LIBS dl ${EXTRA_LIBS})
519         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
520     endif()
521 endif()
523 # Check for a cpuid intrinsic
524 if(HAVE_CPUID_H)
525     check_c_source_compiles("#include <cpuid.h>
526         int main()
527         {
528             unsigned int eax, ebx, ecx, edx;
529             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
530         }" HAVE_GCC_GET_CPUID)
531 endif()
532 if(HAVE_INTRIN_H)
533     check_c_source_compiles("#include <intrin.h>
534         int main()
535         {
536             int regs[4];
537             __cpuid(regs, 0);
538             return regs[0];
539         }" HAVE_CPUID_INTRINSIC)
540 endif()
542 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
544 if(NOT WIN32)
545     # We need pthreads outside of Windows, for semaphores. It's also used to
546     # set the priority and name of threads, when possible.
547     check_include_file(pthread.h HAVE_PTHREAD_H)
548     if(NOT HAVE_PTHREAD_H)
549         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
550     endif()
552     check_c_compiler_flag(-pthread HAVE_PTHREAD)
553     if(HAVE_PTHREAD)
554         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
555         set(C_FLAGS ${C_FLAGS} -pthread)
556         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
557     endif()
559     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
561     # Some systems need pthread_np.h to get pthread_setname_np
562     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
563     if(HAVE_PTHREAD_NP_H)
564         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
565         if(NOT HAVE_PTHREAD_SETNAME_NP)
566             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
567         endif()
568     else()
569         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
570         if(NOT HAVE_PTHREAD_SETNAME_NP)
571             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
572         endif()
573     endif()
574 endif()
577 # Common sources used by both the OpenAL implementation library, the OpenAL
578 # router, and certain tools and examples.
579 set(COMMON_OBJS
580     common/alassert.cpp
581     common/alassert.h
582     common/albit.h
583     common/alcomplex.cpp
584     common/alcomplex.h
585     common/almalloc.h
586     common/alnumbers.h
587     common/alnumeric.h
588     common/alsem.cpp
589     common/alsem.h
590     common/alspan.h
591     common/alstring.cpp
592     common/alstring.h
593     common/althrd_setname.cpp
594     common/althrd_setname.h
595     common/althreads.h
596     common/altraits.h
597     common/atomic.h
598     common/comptr.h
599     common/dynload.cpp
600     common/dynload.h
601     common/flexarray.h
602     common/intrusive_ptr.h
603     common/opthelpers.h
604     common/pffft.cpp
605     common/pffft.h
606     common/phase_shifter.h
607     common/polyphase_resampler.cpp
608     common/polyphase_resampler.h
609     common/pragmadefs.h
610     common/ringbuffer.cpp
611     common/ringbuffer.h
612     common/strutils.cpp
613     common/strutils.h
614     common/vecmat.h
615     common/vector.h)
617 # Core library routines
618 set(CORE_OBJS
619     core/ambdec.cpp
620     core/ambdec.h
621     core/ambidefs.cpp
622     core/ambidefs.h
623     core/async_event.h
624     core/bformatdec.cpp
625     core/bformatdec.h
626     core/bs2b.cpp
627     core/bs2b.h
628     core/bsinc_defs.h
629     core/bsinc_tables.cpp
630     core/bsinc_tables.h
631     core/bufferline.h
632     core/buffer_storage.cpp
633     core/buffer_storage.h
634     core/context.cpp
635     core/context.h
636     core/converter.cpp
637     core/converter.h
638     core/cpu_caps.cpp
639     core/cpu_caps.h
640     core/cubic_defs.h
641     core/cubic_tables.cpp
642     core/cubic_tables.h
643     core/devformat.cpp
644     core/devformat.h
645     core/device.cpp
646     core/device.h
647     core/effects/base.h
648     core/effectslot.cpp
649     core/effectslot.h
650     core/except.cpp
651     core/except.h
652     core/filters/biquad.h
653     core/filters/biquad.cpp
654     core/filters/nfc.cpp
655     core/filters/nfc.h
656     core/filters/splitter.cpp
657     core/filters/splitter.h
658     core/fmt_traits.cpp
659     core/fmt_traits.h
660     core/fpu_ctrl.cpp
661     core/fpu_ctrl.h
662     core/front_stablizer.h
663     core/helpers.cpp
664     core/helpers.h
665     core/hrtf.cpp
666     core/hrtf.h
667     core/logging.cpp
668     core/logging.h
669     core/mastering.cpp
670     core/mastering.h
671     core/mixer.cpp
672     core/mixer.h
673     core/resampler_limits.h
674     core/storage_formats.cpp
675     core/storage_formats.h
676     core/uhjfilter.cpp
677     core/uhjfilter.h
678     core/uiddefs.cpp
679     core/voice.cpp
680     core/voice.h
681     core/voice_change.h)
683 set(HAVE_RTKIT 0)
684 if(NOT WIN32)
685     option(ALSOFT_RTKIT "Enable RTKit support" ON)
686     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
687     if(ALSOFT_RTKIT)
688         find_package(DBus1 QUIET)
689         if(NOT DBus1_FOUND AND PkgConfig_FOUND)
690             pkg_check_modules(DBUS dbus-1)
691         endif()
692         if(DBus1_FOUND OR DBUS_FOUND)
693             set(HAVE_RTKIT 1)
694             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
695                 core/rtkit.cpp core/rtkit.h)
696             if(NOT DBus1_FOUND)
697                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
698                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
699                 if(NOT HAVE_DLFCN_H)
700                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
701                 endif()
702             elseif(HAVE_DLFCN_H)
703                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
704                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
705             else()
706                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
707             endif()
708         endif()
709     else()
710         set(MISSING_VARS "")
711         if(NOT DBus1_INCLUDE_DIRS)
712             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
713         endif()
714         if(NOT DBus1_LIBRARIES)
715             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
716         endif()
717         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
718         unset(MISSING_VARS)
719     endif()
720 endif()
721 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
722     message(FATAL_ERROR "Failed to enable required RTKit support")
723 endif()
725 # Default mixers, always available
726 set(CORE_OBJS ${CORE_OBJS}
727     core/mixer/defs.h
728     core/mixer/hrtfbase.h
729     core/mixer/hrtfdefs.h
730     core/mixer/mixer_c.cpp)
732 # AL and related routines
733 set(OPENAL_OBJS
734     al/auxeffectslot.cpp
735     al/auxeffectslot.h
736     al/buffer.cpp
737     al/buffer.h
738     al/debug.cpp
739     al/debug.h
740     al/direct_defs.h
741     al/effect.cpp
742     al/effect.h
743     al/effects/autowah.cpp
744     al/effects/chorus.cpp
745     al/effects/compressor.cpp
746     al/effects/convolution.cpp
747     al/effects/dedicated.cpp
748     al/effects/distortion.cpp
749     al/effects/echo.cpp
750     al/effects/effects.cpp
751     al/effects/effects.h
752     al/effects/equalizer.cpp
753     al/effects/fshifter.cpp
754     al/effects/modulator.cpp
755     al/effects/null.cpp
756     al/effects/pshifter.cpp
757     al/effects/reverb.cpp
758     al/effects/vmorpher.cpp
759     al/error.cpp
760     al/error.h
761     al/event.cpp
762     al/event.h
763     al/extension.cpp
764     al/filter.cpp
765     al/filter.h
766     al/listener.cpp
767     al/listener.h
768     al/source.cpp
769     al/source.h
770     al/state.cpp)
772 # ALC and related routines
773 set(ALC_OBJS
774     alc/alc.cpp
775     alc/alu.cpp
776     alc/alu.h
777     alc/alconfig.cpp
778     alc/alconfig.h
779     alc/context.cpp
780     alc/context.h
781     alc/device.cpp
782     alc/device.h
783     alc/effects/base.h
784     alc/effects/autowah.cpp
785     alc/effects/chorus.cpp
786     alc/effects/compressor.cpp
787     alc/effects/convolution.cpp
788     alc/effects/dedicated.cpp
789     alc/effects/distortion.cpp
790     alc/effects/echo.cpp
791     alc/effects/equalizer.cpp
792     alc/effects/fshifter.cpp
793     alc/effects/modulator.cpp
794     alc/effects/null.cpp
795     alc/effects/pshifter.cpp
796     alc/effects/reverb.cpp
797     alc/effects/vmorpher.cpp
798     alc/events.cpp
799     alc/events.h
800     alc/export_list.h
801     alc/inprogext.h
802     alc/panning.cpp)
804 if(ALSOFT_EAX)
805     set(OPENAL_OBJS
806         ${OPENAL_OBJS}
807         al/eax/api.cpp
808         al/eax/api.h
809         al/eax/call.cpp
810         al/eax/call.h
811         al/eax/effect.h
812         al/eax/exception.cpp
813         al/eax/exception.h
814         al/eax/fx_slot_index.cpp
815         al/eax/fx_slot_index.h
816         al/eax/fx_slots.cpp
817         al/eax/fx_slots.h
818         al/eax/globals.h
819         al/eax/utils.cpp
820         al/eax/utils.h
821         al/eax/x_ram.h
822     )
823 endif()
825 # Include SIMD mixers
826 set(CPU_EXTS "Default")
827 if(HAVE_SSE)
828     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
829     set(CPU_EXTS "${CPU_EXTS}, SSE")
830 endif()
831 if(HAVE_SSE2)
832     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
833     set(CPU_EXTS "${CPU_EXTS}, SSE2")
834 endif()
835 if(HAVE_SSE3)
836     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
837     set(CPU_EXTS "${CPU_EXTS}, SSE3")
838 endif()
839 if(HAVE_SSE4_1)
840     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
841     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
842 endif()
843 if(HAVE_NEON)
844     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
845     set(CPU_EXTS "${CPU_EXTS}, Neon")
846 endif()
849 set(HAVE_ALSA       0)
850 set(HAVE_OSS        0)
851 set(HAVE_PIPEWIRE   0)
852 set(HAVE_SOLARIS    0)
853 set(HAVE_SNDIO      0)
854 set(HAVE_DSOUND     0)
855 set(HAVE_WASAPI     0)
856 set(HAVE_WINMM      0)
857 set(HAVE_PORTAUDIO  0)
858 set(HAVE_PULSEAUDIO 0)
859 set(HAVE_COREAUDIO  0)
860 set(HAVE_OPENSL     0)
861 set(HAVE_OBOE       0)
862 set(HAVE_OTHERIO    0)
863 set(HAVE_WAVE       0)
864 set(HAVE_SDL2       0)
866 if(WIN32 OR HAVE_DLFCN_H)
867     set(IS_LINKED "")
868     macro(ADD_BACKEND_LIBS _LIBS)
869     endmacro()
870 else()
871     set(IS_LINKED " (linked)")
872     macro(ADD_BACKEND_LIBS _LIBS)
873         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
874     endmacro()
875 endif()
877 set(BACKENDS "")
878 set(ALC_OBJS  ${ALC_OBJS}
879     alc/backends/base.cpp
880     alc/backends/base.h
881     # Default backends, always available
882     alc/backends/loopback.cpp
883     alc/backends/loopback.h
884     alc/backends/null.cpp
885     alc/backends/null.h
888 # Check PipeWire backend
889 option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
890 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
891 if(ALSOFT_BACKEND_PIPEWIRE AND PkgConfig_FOUND)
892     pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
893     if(PIPEWIRE_FOUND)
894         set(HAVE_PIPEWIRE 1)
895         set(BACKENDS  "${BACKENDS} PipeWire${IS_LINKED},")
896         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
897         add_backend_libs(${PIPEWIRE_LIBRARIES})
898         set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
899     endif()
900 endif()
901 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
902     message(FATAL_ERROR "Failed to enable required PipeWire backend")
903 endif()
905 # Check PulseAudio backend
906 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
907 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
908 if(ALSOFT_BACKEND_PULSEAUDIO)
909     find_package(PulseAudio)
910     if(PULSEAUDIO_FOUND)
911         set(HAVE_PULSEAUDIO 1)
912         set(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
913         set(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
914         add_backend_libs(${PULSEAUDIO_LIBRARY})
915         set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIR})
916     endif()
917 endif()
918 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
919     message(FATAL_ERROR "Failed to enable required PulseAudio backend")
920 endif()
922 if(NOT WIN32)
923     # Check ALSA backend
924     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
925     option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
926     if(ALSOFT_BACKEND_ALSA)
927         find_package(ALSA)
928         if(ALSA_FOUND)
929             set(HAVE_ALSA 1)
930             set(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
931             set(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
932             add_backend_libs(${ALSA_LIBRARIES})
933             set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
934         endif()
935     endif()
937     # Check OSS backend
938     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
939     option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
940     if(ALSOFT_BACKEND_OSS)
941         find_package(OSS)
942         if(OSS_FOUND)
943             set(HAVE_OSS 1)
944             set(BACKENDS  "${BACKENDS} OSS,")
945             set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
946             if(OSS_LIBRARIES)
947                 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
948             endif()
949             set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
950         endif()
951     endif()
953     # Check Solaris backend
954     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
955     option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
956     if(ALSOFT_BACKEND_SOLARIS)
957         find_package(AudioIO)
958         if(AUDIOIO_FOUND)
959             set(HAVE_SOLARIS 1)
960             set(BACKENDS  "${BACKENDS} Solaris,")
961             set(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
962             set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
963         endif()
964     endif()
966     # Check SndIO backend (disabled by default on non-BSDs)
967     if(BSD)
968         option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
969     else()
970         option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" OFF)
971     endif()
972     option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
973     if(ALSOFT_BACKEND_SNDIO)
974         find_package(SndIO)
975         if(SNDIO_FOUND)
976             set(HAVE_SNDIO 1)
977             set(BACKENDS  "${BACKENDS} SndIO (linked),")
978             set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
979             set(EXTRA_LIBS ${SNDIO_LIBRARIES} ${EXTRA_LIBS})
980             set(INC_PATHS ${INC_PATHS} ${SNDIO_INCLUDE_DIRS})
981         endif()
982     endif()
983 endif()
984 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
985     message(FATAL_ERROR "Failed to enable required ALSA backend")
986 endif()
987 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
988     message(FATAL_ERROR "Failed to enable required OSS backend")
989 endif()
990 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
991     message(FATAL_ERROR "Failed to enable required Solaris backend")
992 endif()
993 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
994     message(FATAL_ERROR "Failed to enable required SndIO backend")
995 endif()
997 # Check Windows-only backends
998 if(WIN32)
999     if (NOT ALSOFT_UWP)
1000         # Check MMSystem backend
1001         option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
1002         option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
1003         if(ALSOFT_BACKEND_WINMM)
1004             set(HAVE_WINMM 1)
1005             set(BACKENDS "${BACKENDS} WinMM,")
1006             set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
1007             # There doesn't seem to be good way to search for winmm.lib for MSVC.
1008             # find_library doesn't find it without being told to look in a specific
1009             # place in the WindowsSDK, but it links anyway. If there ends up being
1010             # Windows targets without this, another means to detect it is needed.
1011             set(EXTRA_LIBS winmm ${EXTRA_LIBS})
1012         endif()
1014         # Check DSound backend
1015         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1016         option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1017         if(ALSOFT_BACKEND_DSOUND)
1018             check_include_file(dsound.h HAVE_DSOUND_H)
1019             if(DXSDK_DIR)
1020                 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
1021                     PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
1022                     DOC "The DirectSound include directory")
1023             endif()
1024             if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1025                 set(HAVE_DSOUND 1)
1026                 set(BACKENDS "${BACKENDS} DirectSound,")
1027                 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1029                 if(NOT HAVE_DSOUND_H)
1030                     set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1031                 endif()
1032             endif()
1033         endif()
1034     endif()
1036     # Check for WASAPI backend
1037     option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1038     option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1039     if(ALSOFT_BACKEND_WASAPI)
1040         check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1041         if(HAVE_MMDEVICEAPI_H)
1042             set(HAVE_WASAPI 1)
1043             set(BACKENDS  "${BACKENDS} WASAPI,")
1044             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1046             if(NOT ALSOFT_UWP)
1047                 set(EXTRA_LIBS avrt ${EXTRA_LIBS})
1048             endif()
1049         endif()
1050     endif()
1052     option(ALSOFT_BACKEND_OTHERIO "Enable OtherIO backend" OFF)
1053     option(ALSOFT_REQUIRE_OTHERIO "Require OtherIO backend" OFF)
1054     if(ALSOFT_BACKEND_OTHERIO)
1055         set(HAVE_OTHERIO 1)
1056         set(BACKENDS  "${BACKENDS} OtherIO,")
1057         set(ALC_OBJS  ${ALC_OBJS} alc/backends/otherio.cpp alc/backends/otherio.h)
1058     endif()
1059 endif()
1060 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1061     message(FATAL_ERROR "Failed to enable required WinMM backend")
1062 endif()
1063 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1064     message(FATAL_ERROR "Failed to enable required DSound backend")
1065 endif()
1066 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1067     message(FATAL_ERROR "Failed to enable required WASAPI backend")
1068 endif()
1069 if(ALSOFT_REQUIRE_OTHERIO AND NOT HAVE_OTHERIO)
1070     message(FATAL_ERROR "Failed to enable required OtherIO backend")
1071 endif()
1073 # Check JACK backend
1074 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1075 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1076 if(ALSOFT_BACKEND_JACK)
1077     find_package(JACK)
1078     if(JACK_FOUND)
1079         set(HAVE_JACK 1)
1080         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1081         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1082         add_backend_libs(${JACK_LIBRARIES})
1083         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1084     endif()
1085 endif()
1086 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1087     message(FATAL_ERROR "Failed to enable required JACK backend")
1088 endif()
1090 # Check CoreAudio backend
1091 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1092 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1093 if(ALSOFT_BACKEND_COREAUDIO)
1094     find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1095     find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1096     if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1097         set(HAVE_COREAUDIO 1)
1098         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1099         set(BACKENDS  "${BACKENDS} CoreAudio,")
1101         set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1102         if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1103             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1104             if(COREFOUNDATION_FRAMEWORK)
1105                 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1106             endif()
1107         else()
1108             set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1109         endif()
1111         # Some versions of OSX may need the AudioToolbox framework. Add it if
1112         # it's found.
1113         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1114         if(AUDIOTOOLBOX_LIBRARY)
1115             set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1116         endif()
1118         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1119     endif()
1120 endif()
1121 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1122     message(FATAL_ERROR "Failed to enable required CoreAudio backend")
1123 endif()
1125 # Check for Oboe (Android) backend
1126 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1127 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1128 if(ALSOFT_BACKEND_OBOE)
1129     set(OBOE_TARGET )
1130     if(ANDROID)
1131         set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1132         if(OBOE_SOURCE)
1133             add_subdirectory(${OBOE_SOURCE} ./oboe EXCLUDE_FROM_ALL)
1134             set(OBOE_TARGET oboe)
1135         else()
1136             find_package(oboe CONFIG)
1137             if(NOT TARGET oboe::oboe)
1138                 find_package(Oboe)
1139             endif()
1140             if(TARGET oboe::oboe)
1141                 set(OBOE_TARGET "oboe::oboe")
1142             endif()
1143         endif()
1144     endif()
1146     if(OBOE_TARGET)
1147         set(HAVE_OBOE 1)
1148         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1149         set(BACKENDS  "${BACKENDS} Oboe,")
1150         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1151     endif()
1152 endif()
1153 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1154     message(FATAL_ERROR "Failed to enable required Oboe backend")
1155 endif()
1157 # Check for OpenSL (Android) backend
1158 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1159 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1160 if(ALSOFT_BACKEND_OPENSL)
1161     find_package(OpenSL)
1162     if(OPENSL_FOUND)
1163         set(HAVE_OPENSL 1)
1164         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1165         set(BACKENDS  "${BACKENDS} OpenSL,")
1166         set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1167         set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1168     endif()
1169 endif()
1170 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1171     message(FATAL_ERROR "Failed to enable required OpenSL backend")
1172 endif()
1174 # Check PortAudio backend
1175 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1176 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1177 if(ALSOFT_BACKEND_PORTAUDIO)
1178     find_package(PortAudio)
1179     if(PORTAUDIO_FOUND)
1180         set(HAVE_PORTAUDIO 1)
1181         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1182         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1183         add_backend_libs(${PORTAUDIO_LIBRARIES})
1184         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1185     endif()
1186 endif()
1187 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1188     message(FATAL_ERROR "Failed to enable required PortAudio backend")
1189 endif()
1191 # Check for SDL2 backend
1192 # Off by default, since it adds a runtime dependency
1193 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1194 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1195 if(ALSOFT_BACKEND_SDL2)
1196     if(SDL2_FOUND)
1197         set(HAVE_SDL2 1)
1198         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1199         set(BACKENDS  "${BACKENDS} SDL2,")
1200         set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1201     else()
1202         message(STATUS "Could NOT find SDL2")
1203     endif()
1204 endif()
1205 if(ALSOFT_REQUIRE_SDL2 AND NOT HAVE_SDL2)
1206     message(FATAL_ERROR "Failed to enable required SDL2 backend")
1207 endif()
1209 # Optionally enable the Wave Writer backend
1210 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1211 if(ALSOFT_BACKEND_WAVE)
1212     set(HAVE_WAVE 1)
1213     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1214     set(BACKENDS  "${BACKENDS} WaveFile,")
1215 endif()
1217 # This is always available
1218 set(BACKENDS  "${BACKENDS} Null")
1221 find_package(Git)
1222 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1223     set(GIT_DIR "${OpenAL_SOURCE_DIR}/.git")
1225     # Check if this is a submodule, if it is then find the .git directory
1226     if(NOT IS_DIRECTORY "${OpenAL_SOURCE_DIR}/.git")
1227         file(READ ${GIT_DIR} submodule)
1228         string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE ${submodule})
1229         string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
1230         get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
1231         get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
1232     endif()
1234     # Get the current working branch and its latest abbreviated commit hash
1235     add_custom_command(OUTPUT "${OpenAL_BINARY_DIR}/version_witness.txt"
1236         BYPRODUCTS "${OpenAL_BINARY_DIR}/version.h"
1237         COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1238             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1239             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1240         COMMAND ${CMAKE_COMMAND} -E touch "${OpenAL_BINARY_DIR}/version_witness.txt"
1241         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1242         MAIN_DEPENDENCY "${OpenAL_SOURCE_DIR}/version.h.in"
1243         DEPENDS "${GIT_DIR}/index" "${OpenAL_SOURCE_DIR}/version.cmake"
1244         VERBATIM
1245     )
1247     add_custom_target(alsoft.build_version DEPENDS "${OpenAL_BINARY_DIR}/version_witness.txt")
1248 else()
1249     set(GIT_BRANCH "UNKNOWN")
1250     set(GIT_COMMIT_HASH "unknown")
1251     configure_file(
1252         "${OpenAL_SOURCE_DIR}/version.h.in"
1253         "${OpenAL_BINARY_DIR}/version.h")
1254 endif()
1257 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1258 if(ALSOFT_EMBED_HRTF_DATA)
1259     macro(make_hrtf_header FILENAME VARNAME)
1260         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1261         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.txt")
1263         add_custom_command(OUTPUT "${outfile}"
1264             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1265                 -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1266             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1267             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1268             VERBATIM
1269         )
1270         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1271     endmacro()
1273     make_hrtf_header("Default HRTF.mhr" "default_hrtf")
1274 endif()
1277 if(ALSOFT_UTILS)
1278     find_package(MySOFA)
1279     if(NOT ALSOFT_NO_CONFIG_UTIL)
1280         find_package(Qt5Widgets QUIET)
1281         if(NOT Qt5Widgets_FOUND)
1282             message(STATUS "Could NOT find Qt5Widgets")
1283         endif()
1284     endif()
1285 endif()
1286 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1287     find_package(SndFile)
1288     if(SDL2_FOUND)
1289         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1290     endif()
1291 endif()
1293 if(NOT WIN32)
1294     set(LIBNAME "openal")
1295 else()
1296     set(LIBNAME "OpenAL32")
1297 endif()
1299 # Needed for openal.pc.in
1300 set(prefix ${CMAKE_INSTALL_PREFIX})
1301 set(exec_prefix "\${prefix}")
1302 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1303 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1304 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1305 set(PACKAGE_VERSION "${LIB_VERSION}")
1306 set(PKG_CONFIG_CFLAGS )
1307 set(PKG_CONFIG_PRIVATE_LIBS )
1308 if(LIBTYPE STREQUAL "STATIC")
1309     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1310     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1311         # If this is already a linker flag, or is a full path+file, add it
1312         # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1313         # it's a name intended to be dressed as -lname.
1314         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1315             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1316         elseif(FLAG MATCHES "^SDL2::SDL2")
1317             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1318         else()
1319             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1320         endif()
1321     endforeach()
1322 endif()
1324 # End configuration
1325 configure_file(
1326     "${OpenAL_SOURCE_DIR}/config.h.in"
1327     "${OpenAL_BINARY_DIR}/config.h")
1328 configure_file(
1329     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1330     "${OpenAL_BINARY_DIR}/openal.pc"
1331     @ONLY)
1334 add_library(alsoft.common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1335 target_include_directories(alsoft.common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include
1336     PUBLIC ${OpenAL_SOURCE_DIR}/common)
1337 target_compile_definitions(alsoft.common PRIVATE ${CPP_DEFS})
1338 target_compile_options(alsoft.common PRIVATE ${C_FLAGS})
1339 set_target_properties(alsoft.common PROPERTIES ${DEFAULT_TARGET_PROPS} POSITION_INDEPENDENT_CODE TRUE)
1342 unset(HAS_ROUTER)
1343 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1345 # Build main library
1346 if(LIBTYPE STREQUAL "STATIC")
1347     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1348     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1349     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1351     if(WIN32)
1352         # This option is for static linking OpenAL Soft into another project
1353         # that already defines the IDs. It is up to that project to ensure all
1354         # required IDs are defined.
1355         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1356         if(ALSOFT_NO_UID_DEFS)
1357             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1358         endif()
1359     endif()
1360 else()
1361     set(RC_CONFIG resources/openal32.rc)
1362     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1363         add_library(OpenAL SHARED
1364             resources/router.rc
1365             router/router.cpp
1366             router/router.h
1367             router/alc.cpp
1368             router/al.cpp
1369         )
1370         target_compile_definitions(OpenAL
1371             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1372             "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1373         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1374         target_link_libraries(OpenAL PRIVATE alsoft.common ${LINKER_FLAGS})
1375         target_include_directories(OpenAL
1376           PUBLIC
1377             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1378             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1379           PRIVATE
1380             ${OpenAL_SOURCE_DIR}/common
1381             ${OpenAL_BINARY_DIR}
1382         )
1383         set_target_properties(OpenAL PROPERTIES ${DEFAULT_TARGET_PROPS} PREFIX ""
1384             OUTPUT_NAME ${LIBNAME})
1385         if(TARGET alsoft.build_version)
1386             add_dependencies(OpenAL alsoft.build_version)
1387         endif()
1388         set(HAS_ROUTER 1)
1390         set(LIBNAME "soft_oal")
1391         set(IMPL_TARGET soft_oal)
1392         set(RC_CONFIG resources/soft_oal.rc)
1393     endif()
1395     # !important: for osx framework public header works, the headers must be in
1396     # the project
1397     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h
1398         include/AL/efx-presets.h)
1400     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1401         ${TARGET_PUBLIC_HEADERS})
1402     if(WIN32)
1403         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1404     endif()
1405     target_link_libraries(${IMPL_TARGET} PRIVATE alsoft.common ${LINKER_FLAGS} ${EXTRA_LIBS}
1406         ${MATH_LIB})
1408     if(ALSOFT_UWP)
1409         set(ALSOFT_CPPWINRT_VERSION "2.0.230706.1" CACHE STRING "The soft-oal default cppwinrt version")
1410         
1411         find_program(NUGET_EXE NAMES nuget)
1412         if(NOT NUGET_EXE)
1413             message("NUGET.EXE not found.")
1414             message(FATAL_ERROR "Please install this executable, and run CMake again.")
1415         endif()
1417         exec_program(${NUGET_EXE}
1418             ARGS install "Microsoft.Windows.CppWinRT" -Version ${ALSOFT_CPPWINRT_VERSION} -ExcludeVersion -OutputDirectory "\"${CMAKE_BINARY_DIR}/packages\"")
1420         set_target_properties(${IMPL_TARGET} PROPERTIES
1421             VS_PROJECT_IMPORT ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.props
1422         )
1423         target_link_libraries(${IMPL_TARGET} PRIVATE ${CMAKE_BINARY_DIR}/packages/Microsoft.Windows.CppWinRT/build/native/Microsoft.Windows.CppWinRT.targets)
1424     endif()
1426     if(NOT WIN32 AND NOT APPLE)
1427         # FIXME: This doesn't put a dependency on the version script. Changing
1428         # the version script will not cause a relink as it should.
1429         target_link_options(${IMPL_TARGET} PRIVATE
1430             "-Wl,--version-script=${OpenAL_SOURCE_DIR}/libopenal.version")
1431     endif()
1433     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1434         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1435         set(LIBNAME "soft_oal")
1436         if(GIT_FOUND)
1437             execute_process(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1438                 TIMEOUT 5
1439                 OUTPUT_VARIABLE BUNDLE_VERSION
1440                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1441         else()
1442             set(BUNDLE_VERSION 1)
1443         endif()
1445         # Build: Fix rpath in iOS shared libraries
1446         # If this flag is not set, the final dylib binary ld path will be
1447         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1448         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1449         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1450             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1451         endif()
1453         set_target_properties(${IMPL_TARGET} PROPERTIES
1454             FRAMEWORK TRUE
1455             FRAMEWORK_VERSION C
1456             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1457             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1458             MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1459             MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1460             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1461             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1462             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1463             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1464             MACOSX_RPATH TRUE)
1465     endif()
1466 endif()
1468 target_include_directories(${IMPL_TARGET}
1469   PUBLIC
1470     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1471   INTERFACE
1472     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1473     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1474     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1475   PRIVATE
1476     ${INC_PATHS}
1477     ${OpenAL_BINARY_DIR}
1478     ${OpenAL_SOURCE_DIR}
1479     ${OpenAL_SOURCE_DIR}/common
1482 set_target_properties(${IMPL_TARGET} PROPERTIES ${DEFAULT_TARGET_PROPS}
1483     OUTPUT_NAME ${LIBNAME}
1484     VERSION ${LIB_VERSION}
1485     SOVERSION ${LIB_MAJOR_VERSION}
1487 target_compile_definitions(${IMPL_TARGET}
1488     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES $<$<BOOL:${ALSOFT_EAX}>:ALSOFT_EAX>
1489     "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1490 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1492 if(TARGET alsoft.build_version)
1493     add_dependencies(${IMPL_TARGET} alsoft.build_version)
1494 endif()
1496 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1497     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1498     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1499         message(STATUS "")
1500         if(NOT SED_EXECUTABLE)
1501             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1502         endif()
1503         if(NOT CMAKE_DLLTOOL)
1504             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1505         endif()
1506     else()
1507         target_link_options(OpenAL PRIVATE "-Wl,--output-def,${PROJECT_BINARY_DIR}/OpenAL32.def")
1508         add_custom_command(TARGET OpenAL POST_BUILD
1509             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1510             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1511             # Technically OpenAL32.def was created by the build, but cmake
1512             # doesn't recognize it due to -Wl,--output-def,OpenAL32.def being
1513             # manually specified. But declaring the file here allows it to be
1514             # properly cleaned, e.g. during make clean.
1515             BYPRODUCTS OpenAL32.def OpenAL32.lib
1516             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1517             VERBATIM
1518         )
1519     endif()
1520 endif()
1522 if(HAS_ROUTER)
1523     message(STATUS "")
1524     message(STATUS "Building DLL router")
1525 endif()
1527 message(STATUS "")
1528 message(STATUS "Building OpenAL with support for the following backends:")
1529 message(STATUS "   ${BACKENDS}")
1530 message(STATUS "")
1531 message(STATUS "Building with support for CPU extensions:")
1532 message(STATUS "    ${CPU_EXTS}")
1533 message(STATUS "")
1534 if(FPMATH_SET)
1535     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1536     message(STATUS "")
1537 endif()
1538 if(ALSOFT_UWP)
1539     message(STATUS "Building with UWP support")
1540     message(STATUS "")
1541 endif()
1542 if(ALSOFT_EAX)
1543     message(STATUS "Building with legacy EAX extension support")
1544     message(STATUS "")
1545 endif()
1547 if(ALSOFT_EMBED_HRTF_DATA)
1548     message(STATUS "Embedding HRTF datasets")
1549     message(STATUS "")
1550 endif()
1552 # An alias for sub-project builds
1553 add_library(OpenAL::OpenAL ALIAS OpenAL)
1555 # Install main library
1556 if(ALSOFT_INSTALL)
1557     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1558         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1559     install(TARGETS OpenAL EXPORT OpenAL
1560         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1561         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1562         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1563         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1564         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1565     export(TARGETS OpenAL
1566         NAMESPACE OpenAL::
1567         FILE OpenALTargets.cmake)
1568     install(EXPORT OpenAL
1569         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1570         NAMESPACE OpenAL::
1571         FILE OpenALTargets.cmake)
1572     install(DIRECTORY include/AL
1573         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1574     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1575         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1576     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1577         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1578     if(TARGET soft_oal)
1579         install(TARGETS soft_oal
1580             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1581     endif()
1582     message(STATUS "Installing library and headers")
1583 else()
1584     message(STATUS "NOT installing library and headers")
1585 endif()
1587 if(ALSOFT_INSTALL_CONFIG)
1588     install(FILES alsoftrc.sample
1589         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1590     message(STATUS "Installing sample configuration")
1591 endif()
1593 if(ALSOFT_INSTALL_HRTF_DATA)
1594     install(DIRECTORY hrtf
1595         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1596     message(STATUS "Installing HRTF data files")
1597 endif()
1599 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1600     install(DIRECTORY presets
1601         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1602     message(STATUS "Installing AmbDec presets")
1603 endif()
1604 message(STATUS "")
1606 set(UNICODE_FLAG )
1607 if(MINGW)
1608     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1609 endif()
1610 set(EXTRA_INSTALLS )
1611 if(ALSOFT_UTILS)
1612     add_executable(openal-info utils/openal-info.c)
1613     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1614     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1615     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1616     set_target_properties(openal-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1617     if(ALSOFT_INSTALL_EXAMPLES)
1618         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1619     endif()
1621     if(SNDFILE_FOUND)
1622         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1623         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1624         target_include_directories(uhjdecoder
1625             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1626         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1627         target_link_libraries(uhjdecoder PUBLIC alsoft.common
1628             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1629         set_target_properties(uhjdecoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1631         add_executable(uhjencoder utils/uhjencoder.cpp)
1632         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1633         target_include_directories(uhjencoder
1634             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1635         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1636         target_link_libraries(uhjencoder PUBLIC alsoft.common
1637             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1638         set_target_properties(uhjencoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1639     endif()
1641     if(MYSOFA_FOUND)
1642         set(SOFA_SUPPORT_SRCS
1643             utils/sofa-support.cpp
1644             utils/sofa-support.h)
1645         add_library(alsoft.sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1646         target_compile_definitions(alsoft.sofa-support PRIVATE ${CPP_DEFS})
1647         target_include_directories(alsoft.sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1648         target_compile_options(alsoft.sofa-support PRIVATE ${C_FLAGS})
1649         target_link_libraries(alsoft.sofa-support PUBLIC alsoft.common MySOFA::MySOFA
1650             PRIVATE ${LINKER_FLAGS})
1651         set_target_properties(alsoft.sofa-support PROPERTIES ${DEFAULT_TARGET_PROPS})
1653         set(MAKEMHR_SRCS
1654             utils/makemhr/loaddef.cpp
1655             utils/makemhr/loaddef.h
1656             utils/makemhr/loadsofa.cpp
1657             utils/makemhr/loadsofa.h
1658             utils/makemhr/makemhr.cpp
1659             utils/makemhr/makemhr.h)
1660         add_executable(makemhr ${MAKEMHR_SRCS})
1661         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1662         target_include_directories(makemhr
1663             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1664         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1665         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} alsoft.sofa-support ${UNICODE_FLAG})
1666         set_target_properties(makemhr PROPERTIES ${DEFAULT_TARGET_PROPS})
1667         if(ALSOFT_INSTALL_EXAMPLES)
1668             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1669         endif()
1671         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1672         add_executable(sofa-info ${SOFAINFO_SRCS})
1673         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1674         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1675         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1676         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} alsoft.sofa-support
1677             ${UNICODE_FLAG})
1678         set_target_properties(sofa-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1679     endif()
1680     message(STATUS "Building utility programs")
1682     if(NOT ALSOFT_NO_CONFIG_UTIL)
1683         add_subdirectory(utils/alsoft-config)
1684     endif()
1685     message(STATUS "")
1686 endif()
1689 # Add a static library with common functions used by multiple example targets
1690 add_library(alsoft.excommon STATIC EXCLUDE_FROM_ALL
1691     examples/common/alhelpers.c
1692     examples/common/alhelpers.h)
1693 target_compile_definitions(alsoft.excommon PUBLIC ${CPP_DEFS})
1694 target_include_directories(alsoft.excommon PUBLIC ${OpenAL_SOURCE_DIR}/common)
1695 target_compile_options(alsoft.excommon PUBLIC ${C_FLAGS})
1696 target_link_libraries(alsoft.excommon PUBLIC OpenAL PRIVATE ${RT_LIB})
1697 set_target_properties(alsoft.excommon PROPERTIES ${DEFAULT_TARGET_PROPS})
1699 if(ALSOFT_EXAMPLES)
1700     add_executable(altonegen examples/altonegen.c)
1701     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} alsoft.excommon
1702         ${UNICODE_FLAG})
1703     set_target_properties(altonegen PROPERTIES ${DEFAULT_TARGET_PROPS})
1705     add_executable(alrecord examples/alrecord.c)
1706     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} alsoft.excommon ${UNICODE_FLAG})
1707     set_target_properties(alrecord PROPERTIES ${DEFAULT_TARGET_PROPS})
1709     add_executable(aldebug examples/aldebug.cpp)
1710     target_link_libraries(aldebug PRIVATE ${LINKER_FLAGS} alsoft.excommon ${UNICODE_FLAG})
1711     set_target_properties(aldebug PROPERTIES ${DEFAULT_TARGET_PROPS})
1713     add_executable(allafplay examples/allafplay.cpp)
1714     target_link_libraries(allafplay PRIVATE ${LINKER_FLAGS} alsoft.common alsoft.excommon
1715         ${UNICODE_FLAG})
1716     set_target_properties(allafplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1718     if(ALSOFT_INSTALL_EXAMPLES)
1719         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord aldebug allafplay)
1720     endif()
1722     message(STATUS "Building example programs")
1724     if(SNDFILE_FOUND)
1725         add_executable(alplay examples/alplay.c)
1726         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1727             ${UNICODE_FLAG})
1728         set_target_properties(alplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1730         add_executable(alstream examples/alstream.c)
1731         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1732             ${UNICODE_FLAG})
1733         set_target_properties(alstream PROPERTIES ${DEFAULT_TARGET_PROPS})
1735         add_executable(alreverb examples/alreverb.c)
1736         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1737             ${UNICODE_FLAG})
1738         set_target_properties(alreverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1740         add_executable(almultireverb examples/almultireverb.c)
1741         target_link_libraries(almultireverb
1742             PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon ${MATH_LIB} ${UNICODE_FLAG})
1743         set_target_properties(almultireverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1745         add_executable(allatency examples/allatency.c)
1746         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1747             ${UNICODE_FLAG})
1748         set_target_properties(allatency PROPERTIES ${DEFAULT_TARGET_PROPS})
1750         add_executable(alhrtf examples/alhrtf.c)
1751         target_link_libraries(alhrtf
1752             PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon ${MATH_LIB} ${UNICODE_FLAG})
1753         set_target_properties(alhrtf PROPERTIES ${DEFAULT_TARGET_PROPS})
1755         add_executable(alstreamcb examples/alstreamcb.cpp)
1756         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1757             ${UNICODE_FLAG})
1758         set_target_properties(alstreamcb PROPERTIES ${DEFAULT_TARGET_PROPS})
1760         add_executable(aldirect examples/aldirect.cpp)
1761         target_link_libraries(aldirect PRIVATE ${LINKER_FLAGS} SndFile::SndFile alsoft.excommon
1762             ${UNICODE_FLAG})
1763         set_target_properties(aldirect PROPERTIES ${DEFAULT_TARGET_PROPS})
1765         add_executable(alconvolve examples/alconvolve.c)
1766         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} alsoft.common SndFile::SndFile
1767             alsoft.excommon ${UNICODE_FLAG})
1768         set_target_properties(alconvolve PROPERTIES ${DEFAULT_TARGET_PROPS})
1770         if(ALSOFT_INSTALL_EXAMPLES)
1771             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1772                 alhrtf aldirect)
1773         endif()
1775         message(STATUS "Building SndFile example programs")
1776     endif()
1778     if(SDL2_FOUND)
1779         add_executable(alloopback examples/alloopback.c)
1780         target_link_libraries(alloopback
1781             PRIVATE ${LINKER_FLAGS} SDL2::SDL2 alsoft.excommon ${MATH_LIB})
1782         set_target_properties(alloopback PROPERTIES ${DEFAULT_TARGET_PROPS})
1784         if(ALSOFT_INSTALL_EXAMPLES)
1785             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1786         endif()
1788         message(STATUS "Building SDL example programs")
1790         set(FFVER_OK FALSE)
1791         if(FFMPEG_FOUND)
1792             set(FFVER_OK TRUE)
1793             if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1794                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1795                 set(FFVER_OK FALSE)
1796             endif()
1797             if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1798                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1799                 set(FFVER_OK FALSE)
1800             endif()
1801             if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1802                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1803                 set(FFVER_OK FALSE)
1804             endif()
1805             if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1806                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1807                 set(FFVER_OK FALSE)
1808             endif()
1809             if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1810                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1811                 set(FFVER_OK FALSE)
1812             endif()
1813         endif()
1814         if(FFVER_OK)
1815             add_executable(alffplay examples/alffplay.cpp)
1816             target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1817             target_link_libraries(alffplay
1818                 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} alsoft.excommon)
1819             set_target_properties(alffplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1821             if(ALSOFT_INSTALL_EXAMPLES)
1822                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1823             endif()
1824             message(STATUS "Building SDL+FFmpeg example programs")
1825         endif()
1826     endif()
1827     message(STATUS "")
1828 endif()
1830 if (ALSOFT_TESTS)
1831 add_subdirectory(tests)
1832 endif()
1834 if(EXTRA_INSTALLS)
1835     install(TARGETS ${EXTRA_INSTALLS}
1836         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1837         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1838         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1839         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1840 endif()