Release 1.23.1
[openal-soft.git] / CMakeLists.txt
blob55644b045f3fd2998c040c92421bab6dbaf8196f
1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
5 if(APPLE)
6     # The workaround for try_compile failing with code signing
7     # since cmake-3.18.2, not required
8     set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
9         ${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}
10         "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
11         "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
12     set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
13     set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
14 endif()
16 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
17     # Fix compile failure with armv7 deployment target >= 11.0, xcode clang
18     # will report:
19     # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
20     # iOS 10 is the maximum deployment target for 32-bit targets
21     # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
22     # deployment target
23     if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
24         if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
25             OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
26             message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
27             set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
28                 FORCE)
29         endif()
30     endif()
31 endif()
33 set(CMAKE_C_VISIBILITY_PRESET hidden)
34 set(CMAKE_CXX_VISIBILITY_PRESET hidden)
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++14.
80     CXX_STANDARD 14
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)
113 option(ALSOFT_INSTALL "Install main library" ON)
114 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
115 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
116 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
117 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
118 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
119 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
121 option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
123 option(ALSOFT_SEARCH_INSTALL_DATADIR "Search the installation data directory" OFF)
124 if(ALSOFT_SEARCH_INSTALL_DATADIR)
125     set(ALSOFT_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
126 endif()
128 if(DEFINED SHARE_INSTALL_DIR)
129     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
130     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
131 endif()
133 if(DEFINED LIB_SUFFIX)
134     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
135 endif()
136 if(DEFINED ALSOFT_CONFIG)
137     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
138 endif()
139 if(DEFINED ALSOFT_HRTF_DEFS)
140     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
141 endif()
142 if(DEFINED ALSOFT_AMBDEC_PRESETS)
143     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
144 endif()
147 set(CPP_DEFS ) # C pre-processor, not C++
148 set(INC_PATHS )
149 set(C_FLAGS )
150 set(LINKER_FLAGS )
151 set(EXTRA_LIBS )
153 if(WIN32)
154     set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
155     if(MINGW)
156         set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
157     endif()
159     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
160     if(MINGW)
161         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
162     endif()
163 elseif(APPLE)
164     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
165 endif()
168 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
169 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
170     set(INC_PATHS ${INC_PATHS} /usr/include)
171     set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
172 endif()
174 # When the library is built for static linking, apps should define
175 # AL_LIBTYPE_STATIC when including the AL headers.
176 if(NOT LIBTYPE)
177     set(LIBTYPE SHARED)
178 endif()
180 set(LIB_MAJOR_VERSION "1")
181 set(LIB_MINOR_VERSION "23")
182 set(LIB_REVISION "1")
183 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
184 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
186 set(EXPORT_DECL "")
189 if(NOT WIN32)
190     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
191     check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
192     if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
193         set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
194         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
195         check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
196         if(NOT HAVE_POSIX_MEMALIGN_POSIX)
197             set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
198         else()
199             set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
200         endif()
201     endif()
202     unset(OLD_REQUIRED_FLAGS)
203 endif()
205 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
206 check_cxx_source_compiles("int *__restrict foo;
207 int main() { return 0; }" HAVE___RESTRICT)
208 if(HAVE___RESTRICT)
209     set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
210 else()
211     set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
212 endif()
214 # Some systems may need libatomic for atomic functions to work
215 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
216 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
217 check_cxx_source_compiles("#include <atomic>
218 std::atomic<int> foo{0};
219 int main() { return foo.fetch_add(2); }"
220 HAVE_LIBATOMIC)
221 if(NOT HAVE_LIBATOMIC)
222     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
223 else()
224     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
225 endif()
226 unset(OLD_REQUIRED_LIBRARIES)
228 if(ANDROID)
229     # Include liblog for Android logging
230     check_library_exists(log __android_log_print "" HAVE_LIBLOG)
231     if(HAVE_LIBLOG)
232         set(EXTRA_LIBS log ${EXTRA_LIBS})
233         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
234     endif()
235 endif()
237 if(MSVC)
238     set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
239     check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
240     if(HAVE_PERMISSIVE_SWITCH)
241         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
242     endif()
243     set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030 /wd5051)
245     if(NOT DXSDK_DIR)
246         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
247     else()
248         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
249     endif()
250     if(DXSDK_DIR)
251         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
252     endif()
254     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
255     if(FORCE_STATIC_VCRT)
256         foreach(flag_var
257                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
258                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
259                 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
260                 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
261             if(${flag_var} MATCHES "/MD")
262                 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
263             endif()
264         endforeach(flag_var)
265     endif()
266 else()
267     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
268         -Wpedantic
269         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
271     check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
272     if(HAVE_WNO_CXX20_ATTR_EXT)
273         set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
274     else()
275         check_cxx_compiler_flag(-Wno-c++20-extensions HAVE_WNO_CXX20_EXT)
276         if(HAVE_WNO_CXX20_EXT)
277             set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-extensions>)
278         endif()
279     endif()
281     if(ALSOFT_WERROR)
282         set(C_FLAGS ${C_FLAGS} -Werror)
283     endif()
285     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
286     # instead of NDEBUG)
287     foreach(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
288         if(${flag_var} MATCHES "-DNDEBUG")
289             string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
290         endif()
291     endforeach()
293     check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
294     if(HAVE_FNO_MATH_ERRNO)
295         set(C_FLAGS ${C_FLAGS} -fno-math-errno)
296     endif()
298     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
299     if(ALSOFT_STATIC_LIBGCC)
300         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
301         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
302         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
303         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
304         unset(OLD_REQUIRED_LIBRARIES)
306         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
307             message(FATAL_ERROR "Cannot static link libgcc")
308         endif()
309         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
310     endif()
312     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
313     if(ALSOFT_STATIC_STDCXX)
314         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
315         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
316         check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
317         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
318         unset(OLD_REQUIRED_LIBRARIES)
320         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
321             message(FATAL_ERROR "Cannot static link libstdc++")
322         endif()
323         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
324     endif()
326     if(WIN32)
327         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
328         if(ALSOFT_STATIC_WINPTHREAD)
329             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
330             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
331             check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
332             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
333             unset(OLD_REQUIRED_LIBRARIES)
335             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
336                 message(FATAL_ERROR "Cannot static link libwinpthread")
337             endif()
338             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
339         endif()
340     endif()
341 endif()
343 # Set visibility/export options if available
344 if(WIN32)
345     if(NOT LIBTYPE STREQUAL "STATIC")
346         set(EXPORT_DECL "__declspec(dllexport)")
347     endif()
348 else()
349     set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
350     # Yes GCC, really don't accept visibility modes you don't support
351     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
353     check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
354                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
355     if(HAVE_GCC_PROTECTED_VISIBILITY)
356         if(NOT LIBTYPE STREQUAL "STATIC")
357             set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
358         endif()
359     else()
360         check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
361                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
362         if(HAVE_GCC_DEFAULT_VISIBILITY)
363             if(NOT LIBTYPE STREQUAL "STATIC")
364                 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
365             endif()
366         endif()
367     endif()
369     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
370 endif()
373 set(SSE2_SWITCH "")
375 if(NOT MSVC)
376     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
377     # Yes GCC, really don't accept command line options you don't support
378     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
379     check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
380     if(HAVE_MSSE2_SWITCH)
381         set(SSE2_SWITCH "-msse2")
382     endif()
383     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
384     unset(OLD_REQUIRED_FLAGS)
385 endif()
387 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
388 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
389 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
390 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
391 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
393 set(HAVE_SSE        0)
394 set(HAVE_SSE2       0)
395 set(HAVE_SSE3       0)
396 set(HAVE_SSE4_1     0)
397 set(HAVE_NEON       0)
399 # Check for SSE support
400 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
401 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
402 if(ALSOFT_CPUEXT_SSE AND HAVE_XMMINTRIN_H)
403     set(HAVE_SSE 1)
404 endif()
405 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
406     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
407 endif()
409 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
410 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
411 if(ALSOFT_CPUEXT_SSE2 AND HAVE_SSE AND HAVE_EMMINTRIN_H)
412     set(HAVE_SSE2 1)
413 endif()
414 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
415     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
416 endif()
418 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
419 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
420 if(ALSOFT_CPUEXT_SSE3 AND HAVE_SSE2 AND HAVE_PMMINTRIN_H)
421     set(HAVE_SSE3 1)
422 endif()
423 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
424     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
425 endif()
427 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
428 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
429 if(ALSOFT_CPUEXT_SSE4_1 AND HAVE_SSE3 AND HAVE_SMMINTRIN_H)
430     set(HAVE_SSE4_1 1)
431 endif()
432 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
433     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
434 endif()
436 # Check for ARM Neon support
437 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
438 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
439 if(ALSOFT_CPUEXT_NEON AND HAVE_ARM_NEON_H)
440     check_c_source_compiles("#include <arm_neon.h>
441         int main()
442         {
443             int32x4_t ret4 = vdupq_n_s32(0);
444             return vgetq_lane_s32(ret4, 0);
445         }" HAVE_NEON_INTRINSICS)
446     if(HAVE_NEON_INTRINSICS)
447         set(HAVE_NEON 1)
448     endif()
449 endif()
450 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
451     message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
452 endif()
455 set(SSE_FLAGS )
456 set(FPMATH_SET "0")
457 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
458     option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
459     if(ALSOFT_ENABLE_SSE2_CODEGEN)
460         if(MSVC)
461             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
462             if(HAVE_ARCH_SSE2)
463                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
464                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
465                 set(FPMATH_SET 2)
466             endif()
467         elseif(SSE2_SWITCH)
468             check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
469             if(HAVE_MFPMATH_SSE_2)
470                 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
471                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
472                 set(FPMATH_SET 2)
473             endif()
474             # SSE depends on a 16-byte aligned stack, and by default, GCC
475             # assumes the stack is suitably aligned. Older Linux code or other
476             # OSs don't guarantee this on 32-bit, so externally-callable
477             # functions need to ensure an aligned stack.
478             set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
479         endif()
480     endif()
481 endif()
483 if(HAVE_SSE2)
484     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
485     foreach(flag_var ${SSE_FLAGS})
486         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
487     endforeach()
489     check_c_source_compiles("#include <emmintrin.h>
490         int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
492     set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
493 endif()
496 check_include_file(malloc.h HAVE_MALLOC_H)
497 check_include_file(cpuid.h HAVE_CPUID_H)
498 check_include_file(intrin.h HAVE_INTRIN_H)
499 check_include_file(guiddef.h HAVE_GUIDDEF_H)
500 if(NOT HAVE_GUIDDEF_H)
501     check_include_file(initguid.h HAVE_INITGUID_H)
502 endif()
504 # Some systems need libm for some math functions to work
505 set(MATH_LIB )
506 check_library_exists(m pow "" HAVE_LIBM)
507 if(HAVE_LIBM)
508     set(MATH_LIB ${MATH_LIB} m)
509     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
510 endif()
512 # Some systems need to link with -lrt for clock_gettime as used by the common
513 # eaxmple functions.
514 set(RT_LIB )
515 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
516 if(HAVE_LIBRT)
517     set(RT_LIB rt)
518 endif()
520 # Check for the dlopen API (for dynamicly loading backend libs)
521 if(ALSOFT_DLOPEN)
522     check_include_file(dlfcn.h HAVE_DLFCN_H)
523     check_library_exists(dl dlopen "" HAVE_LIBDL)
524     if(HAVE_LIBDL)
525         set(EXTRA_LIBS dl ${EXTRA_LIBS})
526         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
527     endif()
528 endif()
530 # Check for a cpuid intrinsic
531 if(HAVE_CPUID_H)
532     check_c_source_compiles("#include <cpuid.h>
533         int main()
534         {
535             unsigned int eax, ebx, ecx, edx;
536             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
537         }" HAVE_GCC_GET_CPUID)
538 endif()
539 if(HAVE_INTRIN_H)
540     check_c_source_compiles("#include <intrin.h>
541         int main()
542         {
543             int regs[4];
544             __cpuid(regs, 0);
545             return regs[0];
546         }" HAVE_CPUID_INTRINSIC)
547 endif()
549 check_symbol_exists(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
550 check_symbol_exists(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
551 check_symbol_exists(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
553 if(NOT WIN32)
554     # We need pthreads outside of Windows, for semaphores. It's also used to
555     # set the priority and name of threads, when possible.
556     check_include_file(pthread.h HAVE_PTHREAD_H)
557     if(NOT HAVE_PTHREAD_H)
558         message(FATAL_ERROR "PThreads is required for non-Windows builds!")
559     endif()
561     check_c_compiler_flag(-pthread HAVE_PTHREAD)
562     if(HAVE_PTHREAD)
563         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
564         set(C_FLAGS ${C_FLAGS} -pthread)
565         set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
566     endif()
568     check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
570     # Some systems need pthread_np.h to get pthread_setname_np
571     check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
572     if(HAVE_PTHREAD_NP_H)
573         check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
574         if(NOT HAVE_PTHREAD_SETNAME_NP)
575             check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
576         endif()
577     else()
578         check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
579         if(NOT HAVE_PTHREAD_SETNAME_NP)
580             check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
581         endif()
582     endif()
583 endif()
585 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
588 # Common sources used by both the OpenAL implementation library, the OpenAL
589 # router, and certain tools and examples.
590 set(COMMON_OBJS
591     common/albit.h
592     common/albyte.h
593     common/alcomplex.cpp
594     common/alcomplex.h
595     common/aldeque.h
596     common/alfstream.cpp
597     common/alfstream.h
598     common/almalloc.cpp
599     common/almalloc.h
600     common/alnumbers.h
601     common/alnumeric.h
602     common/aloptional.h
603     common/alspan.h
604     common/alstring.cpp
605     common/alstring.h
606     common/altraits.h
607     common/atomic.h
608     common/comptr.h
609     common/dynload.cpp
610     common/dynload.h
611     common/intrusive_ptr.h
612     common/opthelpers.h
613     common/phase_shifter.h
614     common/polyphase_resampler.cpp
615     common/polyphase_resampler.h
616     common/pragmadefs.h
617     common/ringbuffer.cpp
618     common/ringbuffer.h
619     common/strutils.cpp
620     common/strutils.h
621     common/threads.cpp
622     common/threads.h
623     common/vecmat.h
624     common/vector.h)
626 # Core library routines
627 set(CORE_OBJS
628     core/ambdec.cpp
629     core/ambdec.h
630     core/ambidefs.cpp
631     core/ambidefs.h
632     core/async_event.h
633     core/bformatdec.cpp
634     core/bformatdec.h
635     core/bs2b.cpp
636     core/bs2b.h
637     core/bsinc_defs.h
638     core/bsinc_tables.cpp
639     core/bsinc_tables.h
640     core/bufferline.h
641     core/buffer_storage.cpp
642     core/buffer_storage.h
643     core/context.cpp
644     core/context.h
645     core/converter.cpp
646     core/converter.h
647     core/cpu_caps.cpp
648     core/cpu_caps.h
649     core/cubic_defs.h
650     core/cubic_tables.cpp
651     core/cubic_tables.h
652     core/devformat.cpp
653     core/devformat.h
654     core/device.cpp
655     core/device.h
656     core/effects/base.h
657     core/effectslot.cpp
658     core/effectslot.h
659     core/except.cpp
660     core/except.h
661     core/filters/biquad.h
662     core/filters/biquad.cpp
663     core/filters/nfc.cpp
664     core/filters/nfc.h
665     core/filters/splitter.cpp
666     core/filters/splitter.h
667     core/fmt_traits.cpp
668     core/fmt_traits.h
669     core/fpu_ctrl.cpp
670     core/fpu_ctrl.h
671     core/front_stablizer.h
672     core/helpers.cpp
673     core/helpers.h
674     core/hrtf.cpp
675     core/hrtf.h
676     core/logging.cpp
677     core/logging.h
678     core/mastering.cpp
679     core/mastering.h
680     core/mixer.cpp
681     core/mixer.h
682     core/resampler_limits.h
683     core/uhjfilter.cpp
684     core/uhjfilter.h
685     core/uiddefs.cpp
686     core/voice.cpp
687     core/voice.h
688     core/voice_change.h)
690 set(HAVE_RTKIT 0)
691 if(NOT WIN32)
692     option(ALSOFT_RTKIT "Enable RTKit support" ON)
693     option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
694     if(ALSOFT_RTKIT)
695         find_package(DBus1 QUIET)
696         if(NOT DBus1_FOUND AND PkgConfig_FOUND)
697             pkg_check_modules(DBUS dbus-1)
698         endif()
699         if(DBus1_FOUND OR DBUS_FOUND)
700             set(HAVE_RTKIT 1)
701             set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
702                 core/rtkit.cpp core/rtkit.h)
703             if(NOT DBus1_FOUND)
704                 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
705                 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
706                 if(NOT HAVE_DLFCN_H)
707                     set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
708                 endif()
709             elseif(HAVE_DLFCN_H)
710                 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
711                 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
712             else()
713                 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
714             endif()
715         endif()
716     else()
717         set(MISSING_VARS "")
718         if(NOT DBus1_INCLUDE_DIRS)
719             set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
720         endif()
721         if(NOT DBus1_LIBRARIES)
722             set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
723         endif()
724         message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
725         unset(MISSING_VARS)
726     endif()
727 endif()
728 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
729     message(FATAL_ERROR "Failed to enabled required RTKit support")
730 endif()
732 # Default mixers, always available
733 set(CORE_OBJS ${CORE_OBJS}
734     core/mixer/defs.h
735     core/mixer/hrtfbase.h
736     core/mixer/hrtfdefs.h
737     core/mixer/mixer_c.cpp)
739 # AL and related routines
740 set(OPENAL_OBJS
741     al/auxeffectslot.cpp
742     al/auxeffectslot.h
743     al/buffer.cpp
744     al/buffer.h
745     al/effect.cpp
746     al/effect.h
747     al/effects/autowah.cpp
748     al/effects/chorus.cpp
749     al/effects/compressor.cpp
750     al/effects/convolution.cpp
751     al/effects/dedicated.cpp
752     al/effects/distortion.cpp
753     al/effects/echo.cpp
754     al/effects/effects.cpp
755     al/effects/effects.h
756     al/effects/equalizer.cpp
757     al/effects/fshifter.cpp
758     al/effects/modulator.cpp
759     al/effects/null.cpp
760     al/effects/pshifter.cpp
761     al/effects/reverb.cpp
762     al/effects/vmorpher.cpp
763     al/error.cpp
764     al/event.cpp
765     al/event.h
766     al/extension.cpp
767     al/filter.cpp
768     al/filter.h
769     al/listener.cpp
770     al/listener.h
771     al/source.cpp
772     al/source.h
773     al/state.cpp)
775 # ALC and related routines
776 set(ALC_OBJS
777     alc/alc.cpp
778     alc/alu.cpp
779     alc/alu.h
780     alc/alconfig.cpp
781     alc/alconfig.h
782     alc/context.cpp
783     alc/context.h
784     alc/device.cpp
785     alc/device.h
786     alc/effects/base.h
787     alc/effects/autowah.cpp
788     alc/effects/chorus.cpp
789     alc/effects/compressor.cpp
790     alc/effects/convolution.cpp
791     alc/effects/dedicated.cpp
792     alc/effects/distortion.cpp
793     alc/effects/echo.cpp
794     alc/effects/equalizer.cpp
795     alc/effects/fshifter.cpp
796     alc/effects/modulator.cpp
797     alc/effects/null.cpp
798     alc/effects/pshifter.cpp
799     alc/effects/reverb.cpp
800     alc/effects/vmorpher.cpp
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.cpp
819         al/eax/globals.h
820         al/eax/utils.cpp
821         al/eax/utils.h
822         al/eax/x_ram.h
823     )
824 endif()
826 # Include SIMD mixers
827 set(CPU_EXTS "Default")
828 if(HAVE_SSE)
829     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp)
830     set(CPU_EXTS "${CPU_EXTS}, SSE")
831 endif()
832 if(HAVE_SSE2)
833     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
834     set(CPU_EXTS "${CPU_EXTS}, SSE2")
835 endif()
836 if(HAVE_SSE3)
837     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
838     set(CPU_EXTS "${CPU_EXTS}, SSE3")
839 endif()
840 if(HAVE_SSE4_1)
841     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
842     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
843 endif()
844 if(HAVE_NEON)
845     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
846     set(CPU_EXTS "${CPU_EXTS}, Neon")
847 endif()
850 set(HAVE_ALSA       0)
851 set(HAVE_OSS        0)
852 set(HAVE_PIPEWIRE   0)
853 set(HAVE_SOLARIS    0)
854 set(HAVE_SNDIO      0)
855 set(HAVE_DSOUND     0)
856 set(HAVE_WASAPI     0)
857 set(HAVE_WINMM      0)
858 set(HAVE_PORTAUDIO  0)
859 set(HAVE_PULSEAUDIO 0)
860 set(HAVE_COREAUDIO  0)
861 set(HAVE_OPENSL     0)
862 set(HAVE_OBOE       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 enabled 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 enabled 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
967     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
968     option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
969     if(ALSOFT_BACKEND_SNDIO)
970         find_package(SoundIO)
971         if(SOUNDIO_FOUND)
972             set(HAVE_SNDIO 1)
973             set(BACKENDS  "${BACKENDS} SndIO (linked),")
974             set(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
975             set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
976             set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
977         endif()
978     endif()
979 endif()
980 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
981     message(FATAL_ERROR "Failed to enabled required ALSA backend")
982 endif()
983 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
984     message(FATAL_ERROR "Failed to enabled required OSS backend")
985 endif()
986 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
987     message(FATAL_ERROR "Failed to enabled required Solaris backend")
988 endif()
989 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
990     message(FATAL_ERROR "Failed to enabled required SndIO backend")
991 endif()
993 # Check Windows-only backends
994 if(WIN32)
995     # Check MMSystem backend
996     option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
997     option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
998     if(ALSOFT_BACKEND_WINMM)
999         set(HAVE_WINMM 1)
1000         set(BACKENDS "${BACKENDS} WinMM,")
1001         set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
1002         # There doesn't seem to be good way to search for winmm.lib for MSVC.
1003         # find_library doesn't find it without being told to look in a specific
1004         # place in the WindowsSDK, but it links anyway. If there ends up being
1005         # Windows targets without this, another means to detect it is needed.
1006         set(EXTRA_LIBS winmm ${EXTRA_LIBS})
1007     endif()
1009     # Check DSound backend
1010     option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1011     option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1012     if(ALSOFT_BACKEND_DSOUND)
1013         check_include_file(dsound.h HAVE_DSOUND_H)
1014         if(DXSDK_DIR)
1015             find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
1016                 PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
1017                 DOC "The DirectSound include directory")
1018         endif()
1019         if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1020             set(HAVE_DSOUND 1)
1021             set(BACKENDS "${BACKENDS} DirectSound,")
1022             set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1024             if(NOT HAVE_DSOUND_H)
1025                 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1026             endif()
1027         endif()
1028     endif()
1030     # Check for WASAPI backend
1031     option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1032     option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1033     if(ALSOFT_BACKEND_WASAPI)
1034         check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1035         if(HAVE_MMDEVICEAPI_H)
1036             set(HAVE_WASAPI 1)
1037             set(BACKENDS  "${BACKENDS} WASAPI,")
1038             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1039         endif()
1040     endif()
1041 endif()
1042 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1043     message(FATAL_ERROR "Failed to enabled required WinMM backend")
1044 endif()
1045 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1046     message(FATAL_ERROR "Failed to enabled required DSound backend")
1047 endif()
1048 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1049     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1050 endif()
1052 # Check JACK backend
1053 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1054 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1055 if(ALSOFT_BACKEND_JACK)
1056     find_package(JACK)
1057     if(JACK_FOUND)
1058         set(HAVE_JACK 1)
1059         set(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1060         set(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1061         add_backend_libs(${JACK_LIBRARIES})
1062         set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1063     endif()
1064 endif()
1065 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1066     message(FATAL_ERROR "Failed to enabled required JACK backend")
1067 endif()
1069 # Check CoreAudio backend
1070 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1071 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1072 if(ALSOFT_BACKEND_COREAUDIO)
1073     find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1074     find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1075     if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1076         set(HAVE_COREAUDIO 1)
1077         set(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1078         set(BACKENDS  "${BACKENDS} CoreAudio,")
1080         set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1081         if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1082             find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1083             if(COREFOUNDATION_FRAMEWORK)
1084                 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1085             endif()
1086         else()
1087             set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1088         endif()
1090         # Some versions of OSX may need the AudioToolbox framework. Add it if
1091         # it's found.
1092         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1093         if(AUDIOTOOLBOX_LIBRARY)
1094             set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1095         endif()
1097         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1098     endif()
1099 endif()
1100 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1101     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1102 endif()
1104 # Check for Oboe (Android) backend
1105 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1106 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1107 if(ALSOFT_BACKEND_OBOE)
1108     set(OBOE_TARGET )
1109     if(ANDROID)
1110         set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1111         if(OBOE_SOURCE)
1112             add_subdirectory(${OBOE_SOURCE} ./oboe)
1113             set(OBOE_TARGET oboe)
1114         else()
1115             find_package(oboe CONFIG)
1116             if(NOT TARGET oboe::oboe)
1117                 find_package(Oboe)
1118             endif()
1119             if(TARGET oboe::oboe)
1120                 set(OBOE_TARGET "oboe::oboe")
1121             endif()
1122         endif()
1123     endif()
1125     if(OBOE_TARGET)
1126         set(HAVE_OBOE 1)
1127         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1128         set(BACKENDS  "${BACKENDS} Oboe,")
1129         set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1130     endif()
1131 endif()
1132 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1133     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1134 endif()
1136 # Check for OpenSL (Android) backend
1137 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1138 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1139 if(ALSOFT_BACKEND_OPENSL)
1140     find_package(OpenSL)
1141     if(OPENSL_FOUND)
1142         set(HAVE_OPENSL 1)
1143         set(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1144         set(BACKENDS  "${BACKENDS} OpenSL,")
1145         set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1146     endif()
1147 endif()
1148 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1149     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1150 endif()
1152 # Check PortAudio backend
1153 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1154 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1155 if(ALSOFT_BACKEND_PORTAUDIO)
1156     find_package(PortAudio)
1157     if(PORTAUDIO_FOUND)
1158         set(HAVE_PORTAUDIO 1)
1159         set(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1160         set(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1161         add_backend_libs(${PORTAUDIO_LIBRARIES})
1162         set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1163     endif()
1164 endif()
1165 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1166     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1167 endif()
1169 # Check for SDL2 backend
1170 # Off by default, since it adds a runtime dependency
1171 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1172 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1173 if(ALSOFT_BACKEND_SDL2)
1174     if(SDL2_FOUND)
1175         set(HAVE_SDL2 1)
1176         set(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1177         set(BACKENDS  "${BACKENDS} SDL2,")
1178         set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1179     else()
1180         message(STATUS "Could NOT find SDL2")
1181     endif()
1182 endif()
1183 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1184     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1185 endif()
1187 # Optionally enable the Wave Writer backend
1188 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1189 if(ALSOFT_BACKEND_WAVE)
1190     set(HAVE_WAVE 1)
1191     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1192     set(BACKENDS  "${BACKENDS} WaveFile,")
1193 endif()
1195 # This is always available
1196 set(BACKENDS  "${BACKENDS} Null")
1199 find_package(Git)
1200 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1201     set(GIT_DIR "${OpenAL_SOURCE_DIR}/.git")
1203     # Check if this is a submodule, if it is then find the .git directory
1204     if(NOT IS_DIRECTORY "${OpenAL_SOURCE_DIR}/.git")
1205         file(READ ${GIT_DIR} submodule)
1206         string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE ${submodule})
1207         string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
1208         get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
1209         get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
1210     endif()
1212     # Get the current working branch and its latest abbreviated commit hash
1213     add_custom_command(OUTPUT "${OpenAL_BINARY_DIR}/version_witness.txt"
1214         BYPRODUCTS "${OpenAL_BINARY_DIR}/version.h"
1215         COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1216             -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1217             -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1218         COMMAND ${CMAKE_COMMAND} -E touch "${OpenAL_BINARY_DIR}/version_witness.txt"
1219         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1220         MAIN_DEPENDENCY "${OpenAL_SOURCE_DIR}/version.h.in"
1221         DEPENDS "${GIT_DIR}/index" "${OpenAL_SOURCE_DIR}/version.cmake"
1222         VERBATIM
1223     )
1225     add_custom_target(build_version DEPENDS "${OpenAL_BINARY_DIR}/version_witness.txt")
1226 else()
1227     set(GIT_BRANCH "UNKNOWN")
1228     set(GIT_COMMIT_HASH "unknown")
1229     configure_file(
1230         "${OpenAL_SOURCE_DIR}/version.h.in"
1231         "${OpenAL_BINARY_DIR}/version.h")
1232 endif()
1235 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1236 if(ALSOFT_EMBED_HRTF_DATA)
1237     macro(make_hrtf_header FILENAME VARNAME)
1238         set(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1239         set(outfile  "${OpenAL_BINARY_DIR}/${VARNAME}.txt")
1241         add_custom_command(OUTPUT "${outfile}"
1242             COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1243                 -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1244             WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1245             DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1246             VERBATIM
1247         )
1248         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1249     endmacro()
1251     make_hrtf_header("Default HRTF.mhr" "default_hrtf")
1252 endif()
1255 if(ALSOFT_UTILS)
1256     find_package(MySOFA)
1257     if(NOT ALSOFT_NO_CONFIG_UTIL)
1258         find_package(Qt5Widgets QUIET)
1259         if(NOT Qt5Widgets_FOUND)
1260             message(STATUS "Could NOT find Qt5Widgets")
1261         endif()
1262     endif()
1263 endif()
1264 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1265     find_package(SndFile)
1266     if(SDL2_FOUND)
1267         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1268     endif()
1269 endif()
1271 if(NOT WIN32)
1272     set(LIBNAME "openal")
1273 else()
1274     set(LIBNAME "OpenAL32")
1275 endif()
1277 # Needed for openal.pc.in
1278 set(prefix ${CMAKE_INSTALL_PREFIX})
1279 set(exec_prefix "\${prefix}")
1280 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1281 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1282 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1283 set(PACKAGE_VERSION "${LIB_VERSION}")
1284 set(PKG_CONFIG_CFLAGS )
1285 set(PKG_CONFIG_PRIVATE_LIBS )
1286 if(LIBTYPE STREQUAL "STATIC")
1287     set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1288     foreach(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1289         # If this is already a linker flag, or is a full path+file, add it
1290         # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1291         # it's a name intended to be dressed as -lname.
1292         if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1293             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1294         elseif(FLAG MATCHES "^SDL2::SDL2")
1295             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1296         else()
1297             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1298         endif()
1299     endforeach()
1300 endif()
1302 # End configuration
1303 configure_file(
1304     "${OpenAL_SOURCE_DIR}/config.h.in"
1305     "${OpenAL_BINARY_DIR}/config.h")
1306 configure_file(
1307     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1308     "${OpenAL_BINARY_DIR}/openal.pc"
1309     @ONLY)
1312 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1313 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1314 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1315 target_compile_options(common PRIVATE ${C_FLAGS})
1316 set_target_properties(common PROPERTIES ${DEFAULT_TARGET_PROPS} POSITION_INDEPENDENT_CODE TRUE)
1319 unset(HAS_ROUTER)
1320 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1322 # Build main library
1323 if(LIBTYPE STREQUAL "STATIC")
1324     add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1325     target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1326     target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1328     if(WIN32)
1329         # This option is for static linking OpenAL Soft into another project
1330         # that already defines the IDs. It is up to that project to ensure all
1331         # required IDs are defined.
1332         option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1333         if(ALSOFT_NO_UID_DEFS)
1334             target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1335         endif()
1336     endif()
1337 else()
1338     set(RC_CONFIG resources/openal32.rc)
1339     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1340         add_library(OpenAL SHARED
1341             resources/router.rc
1342             router/router.cpp
1343             router/router.h
1344             router/alc.cpp
1345             router/al.cpp
1346         )
1347         target_compile_definitions(OpenAL
1348             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1349             "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1350         target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1351         target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1352         target_include_directories(OpenAL
1353           PUBLIC
1354             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1355             $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1356           PRIVATE
1357             ${OpenAL_SOURCE_DIR}/common
1358             ${OpenAL_BINARY_DIR}
1359         )
1360         set_target_properties(OpenAL PROPERTIES ${DEFAULT_TARGET_PROPS} PREFIX ""
1361             OUTPUT_NAME ${LIBNAME})
1362         if(TARGET build_version)
1363             add_dependencies(OpenAL build_version)
1364         endif()
1365         set(HAS_ROUTER 1)
1367         set(LIBNAME "soft_oal")
1368         set(IMPL_TARGET soft_oal)
1369         set(RC_CONFIG resources/soft_oal.rc)
1370     endif()
1372     # !important: for osx framework public header works, the headers must be in
1373     # the project
1374     set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h
1375         include/AL/efx-presets.h)
1377     add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1378         ${TARGET_PUBLIC_HEADERS})
1379     if(WIN32)
1380         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1381     endif()
1382     target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1384     if(NOT WIN32 AND NOT APPLE)
1385         # FIXME: This doesn't put a dependency on the version script. Changing
1386         # the version script will not cause a relink as it should.
1387         set_property(TARGET ${IMPL_TARGET} APPEND_STRING PROPERTY
1388             LINK_FLAGS " -Wl,--version-script=${OpenAL_SOURCE_DIR}/libopenal.version")
1389     endif()
1391     if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1392         # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1393         set(LIBNAME "soft_oal")
1394         if(GIT_FOUND)
1395             execute_process(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1396                 TIMEOUT 5
1397                 OUTPUT_VARIABLE BUNDLE_VERSION
1398                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1399         else()
1400             set(BUNDLE_VERSION 1)
1401         endif()
1403         # Build: Fix rpath in iOS shared libraries
1404         # If this flag is not set, the final dylib binary ld path will be
1405         # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1406         # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1407         if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1408             set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1409         endif()
1411         set_target_properties(${IMPL_TARGET} PROPERTIES
1412             FRAMEWORK TRUE
1413             FRAMEWORK_VERSION C
1414             MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1415             MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1416             MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1417             MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1418             XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1419             XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1420             XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1421             PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1422             MACOSX_RPATH TRUE)
1423     endif()
1424 endif()
1426 target_include_directories(${IMPL_TARGET}
1427   PUBLIC
1428     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1429   INTERFACE
1430     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1431     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1432     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1433   PRIVATE
1434     ${INC_PATHS}
1435     ${OpenAL_BINARY_DIR}
1436     ${OpenAL_SOURCE_DIR}
1437     ${OpenAL_SOURCE_DIR}/common
1440 set_target_properties(${IMPL_TARGET} PROPERTIES ${DEFAULT_TARGET_PROPS}
1441     OUTPUT_NAME ${LIBNAME}
1442     VERSION ${LIB_VERSION}
1443     SOVERSION ${LIB_MAJOR_VERSION}
1445 target_compile_definitions(${IMPL_TARGET}
1446     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1447     ${CPP_DEFS})
1448 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1450 if(TARGET build_version)
1451     add_dependencies(${IMPL_TARGET} build_version)
1452 endif()
1454 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1455     find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1456     if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1457         message(STATUS "")
1458         if(NOT SED_EXECUTABLE)
1459             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1460         endif()
1461         if(NOT CMAKE_DLLTOOL)
1462             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1463         endif()
1464     else()
1465         set_property(TARGET OpenAL APPEND_STRING PROPERTY
1466             LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1467         add_custom_command(TARGET OpenAL POST_BUILD
1468             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1469             COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1470             # Technically OpenAL32.def was created by the build, but cmake
1471             # doesn't recognize it due to -Wl,--output-def,OpenAL32.def being
1472             # manually specified. But declaring the file here allows it to be
1473             # properly cleaned, e.g. during make clean.
1474             BYPRODUCTS OpenAL32.def OpenAL32.lib
1475             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1476             VERBATIM
1477         )
1478     endif()
1479 endif()
1481 if(HAS_ROUTER)
1482     message(STATUS "")
1483     message(STATUS "Building DLL router")
1484 endif()
1486 message(STATUS "")
1487 message(STATUS "Building OpenAL with support for the following backends:")
1488 message(STATUS "   ${BACKENDS}")
1489 message(STATUS "")
1490 message(STATUS "Building with support for CPU extensions:")
1491 message(STATUS "    ${CPU_EXTS}")
1492 message(STATUS "")
1493 if(FPMATH_SET)
1494     message(STATUS "Building with SSE${FPMATH_SET} codegen")
1495     message(STATUS "")
1496 endif()
1498 if(ALSOFT_EAX)
1499     message(STATUS "Building with legacy EAX extension support")
1500     message(STATUS "")
1501 endif()
1503 if(ALSOFT_EMBED_HRTF_DATA)
1504     message(STATUS "Embedding HRTF datasets")
1505     message(STATUS "")
1506 endif()
1508 # An alias for sub-project builds
1509 add_library(OpenAL::OpenAL ALIAS OpenAL)
1511 # Install main library
1512 if(ALSOFT_INSTALL)
1513     configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1514         INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1515     install(TARGETS OpenAL EXPORT OpenAL
1516         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1517         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1518         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1519         FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1520         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1521     export(TARGETS OpenAL
1522         NAMESPACE OpenAL::
1523         FILE OpenALTargets.cmake)
1524     install(EXPORT OpenAL
1525         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1526         NAMESPACE OpenAL::
1527         FILE OpenALTargets.cmake)
1528     install(DIRECTORY include/AL
1529         DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1530     install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1531         DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1532     install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1533         DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1534     if(TARGET soft_oal)
1535         install(TARGETS soft_oal
1536             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1537     endif()
1538     message(STATUS "Installing library and headers")
1539 else()
1540     message(STATUS "NOT installing library and headers")
1541 endif()
1543 if(ALSOFT_INSTALL_CONFIG)
1544     install(FILES alsoftrc.sample
1545         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1546     message(STATUS "Installing sample configuration")
1547 endif()
1549 if(ALSOFT_INSTALL_HRTF_DATA)
1550     install(DIRECTORY hrtf
1551         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1552     message(STATUS "Installing HRTF data files")
1553 endif()
1555 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1556     install(DIRECTORY presets
1557         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1558     message(STATUS "Installing AmbDec presets")
1559 endif()
1560 message(STATUS "")
1562 set(UNICODE_FLAG )
1563 if(MINGW)
1564     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1565 endif()
1566 set(EXTRA_INSTALLS )
1567 if(ALSOFT_UTILS)
1568     add_executable(openal-info utils/openal-info.c)
1569     target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1570     target_compile_options(openal-info PRIVATE ${C_FLAGS})
1571     target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1572     set_target_properties(openal-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1573     if(ALSOFT_INSTALL_EXAMPLES)
1574         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1575     endif()
1577     if(SNDFILE_FOUND)
1578         add_executable(uhjdecoder utils/uhjdecoder.cpp)
1579         target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1580         target_include_directories(uhjdecoder
1581             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1582         target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1583         target_link_libraries(uhjdecoder PUBLIC common
1584             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1585         set_target_properties(uhjdecoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1587         add_executable(uhjencoder utils/uhjencoder.cpp)
1588         target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1589         target_include_directories(uhjencoder
1590             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1591         target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1592         target_link_libraries(uhjencoder PUBLIC common
1593             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1594         set_target_properties(uhjencoder PROPERTIES ${DEFAULT_TARGET_PROPS})
1595     endif()
1597     if(MYSOFA_FOUND)
1598         set(SOFA_SUPPORT_SRCS
1599             utils/sofa-support.cpp
1600             utils/sofa-support.h)
1601         add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1602         target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1603         target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1604         target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1605         target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1606         set_target_properties(sofa-support PROPERTIES ${DEFAULT_TARGET_PROPS})
1608         set(MAKEMHR_SRCS
1609             utils/makemhr/loaddef.cpp
1610             utils/makemhr/loaddef.h
1611             utils/makemhr/loadsofa.cpp
1612             utils/makemhr/loadsofa.h
1613             utils/makemhr/makemhr.cpp
1614             utils/makemhr/makemhr.h)
1615         if(NOT HAVE_GETOPT)
1616             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1617         endif()
1618         add_executable(makemhr ${MAKEMHR_SRCS})
1619         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1620         target_include_directories(makemhr
1621             PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1622         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1623         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1624         set_target_properties(makemhr PROPERTIES ${DEFAULT_TARGET_PROPS})
1625         if(ALSOFT_INSTALL_EXAMPLES)
1626             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1627         endif()
1629         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1630         add_executable(sofa-info ${SOFAINFO_SRCS})
1631         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1632         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1633         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1634         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1635         set_target_properties(sofa-info PROPERTIES ${DEFAULT_TARGET_PROPS})
1636     endif()
1637     message(STATUS "Building utility programs")
1639     if(NOT ALSOFT_NO_CONFIG_UTIL)
1640         add_subdirectory(utils/alsoft-config)
1641     endif()
1642     message(STATUS "")
1643 endif()
1646 # Add a static library with common functions used by multiple example targets
1647 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1648     examples/common/alhelpers.c
1649     examples/common/alhelpers.h)
1650 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1651 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1652 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1653 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1654 set_target_properties(ex-common PROPERTIES ${DEFAULT_TARGET_PROPS})
1656 if(ALSOFT_EXAMPLES)
1657     add_executable(altonegen examples/altonegen.c)
1658     target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1659     set_target_properties(altonegen PROPERTIES ${DEFAULT_TARGET_PROPS})
1661     add_executable(alrecord examples/alrecord.c)
1662     target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1663     set_target_properties(alrecord PROPERTIES ${DEFAULT_TARGET_PROPS})
1665     if(ALSOFT_INSTALL_EXAMPLES)
1666         set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1667     endif()
1669     message(STATUS "Building example programs")
1671     if(SNDFILE_FOUND)
1672         add_executable(alplay examples/alplay.c)
1673         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1674             ${UNICODE_FLAG})
1675         set_target_properties(alplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1677         add_executable(alstream examples/alstream.c)
1678         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1679             ${UNICODE_FLAG})
1680         set_target_properties(alstream PROPERTIES ${DEFAULT_TARGET_PROPS})
1682         add_executable(alreverb examples/alreverb.c)
1683         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1684             ${UNICODE_FLAG})
1685         set_target_properties(alreverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1687         add_executable(almultireverb examples/almultireverb.c)
1688         target_link_libraries(almultireverb
1689             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1690         set_target_properties(almultireverb PROPERTIES ${DEFAULT_TARGET_PROPS})
1692         add_executable(allatency examples/allatency.c)
1693         target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1694             ${UNICODE_FLAG})
1695         set_target_properties(allatency PROPERTIES ${DEFAULT_TARGET_PROPS})
1697         add_executable(alhrtf examples/alhrtf.c)
1698         target_link_libraries(alhrtf
1699             PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1700         set_target_properties(alhrtf PROPERTIES ${DEFAULT_TARGET_PROPS})
1702         add_executable(alstreamcb examples/alstreamcb.cpp)
1703         target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1704             ${UNICODE_FLAG})
1705         set_target_properties(alstreamcb PROPERTIES ${DEFAULT_TARGET_PROPS})
1707         add_executable(alconvolve examples/alconvolve.c)
1708         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1709             ${UNICODE_FLAG})
1710         set_target_properties(alconvolve PROPERTIES ${DEFAULT_TARGET_PROPS})
1712         if(ALSOFT_INSTALL_EXAMPLES)
1713             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1714                 alhrtf)
1715         endif()
1717         message(STATUS "Building SndFile example programs")
1718     endif()
1720     if(SDL2_FOUND)
1721         add_executable(alloopback examples/alloopback.c)
1722         target_link_libraries(alloopback
1723             PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ex-common ${MATH_LIB})
1724         set_target_properties(alloopback PROPERTIES ${DEFAULT_TARGET_PROPS})
1726         if(ALSOFT_INSTALL_EXAMPLES)
1727             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1728         endif()
1730         message(STATUS "Building SDL example programs")
1732         set(FFVER_OK FALSE)
1733         if(FFMPEG_FOUND)
1734             set(FFVER_OK TRUE)
1735             if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1736                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1737                 set(FFVER_OK FALSE)
1738             endif()
1739             if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1740                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1741                 set(FFVER_OK FALSE)
1742             endif()
1743             if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1744                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1745                 set(FFVER_OK FALSE)
1746             endif()
1747             if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1748                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1749                 set(FFVER_OK FALSE)
1750             endif()
1751             if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1752                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1753                 set(FFVER_OK FALSE)
1754             endif()
1755         endif()
1756         if(FFVER_OK)
1757             add_executable(alffplay examples/alffplay.cpp)
1758             target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1759             target_link_libraries(alffplay
1760                 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} ex-common)
1761             set_target_properties(alffplay PROPERTIES ${DEFAULT_TARGET_PROPS})
1763             if(ALSOFT_INSTALL_EXAMPLES)
1764                 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1765             endif()
1766             message(STATUS "Building SDL+FFmpeg example programs")
1767         endif()
1768     endif()
1769     message(STATUS "")
1770 endif()
1772 if(EXTRA_INSTALLS)
1773     install(TARGETS ${EXTRA_INSTALLS}
1774         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1775         BUNDLE  DESTINATION ${CMAKE_INSTALL_BINDIR}
1776         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1777         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1778 endif()