1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
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)
16 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
17 # Fix compile failure with armv7 deployment target >= 11.0, xcode clang
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
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"
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)
40 cmake_policy(SET CMP0020 NEW)
43 cmake_policy(SET CMP0042 NEW)
46 cmake_policy(SET CMP0054 NEW)
49 cmake_policy(SET CMP0058 NEW)
52 cmake_policy(SET CMP0063 NEW)
55 cmake_policy(SET CMP0075 NEW)
58 cmake_policy(SET CMP0092 NEW)
61 cmake_policy(SET CMP0117 NEW)
63 endif(COMMAND CMAKE_POLICY)
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."
72 if(NOT CMAKE_DEBUG_POSTFIX)
73 set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
74 "Library postfix for debug builds. Normally left blank."
78 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
80 include(CheckFunctionExists)
81 include(CheckLibraryExists)
82 include(CheckIncludeFile)
83 include(CheckIncludeFiles)
84 include(CheckSymbolExists)
85 include(CheckCCompilerFlag)
86 include(CheckCXXCompilerFlag)
87 include(CheckCSourceCompiles)
88 include(CheckCXXSourceCompiles)
89 include(CheckStructHasMember)
90 include(CMakePackageConfigHelpers)
91 include(GNUInstallDirs)
93 find_package(PkgConfig)
96 option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
98 option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
100 option(ALSOFT_UTILS "Build utility programs" ON)
101 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
103 option(ALSOFT_EXAMPLES "Build example programs" ON)
105 option(ALSOFT_INSTALL "Install main library" ON)
106 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
107 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
108 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
109 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
110 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
111 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
113 option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
115 option(ALSOFT_SEARCH_INSTALL_DATADIR "Search the installation data directory" OFF)
116 if(ALSOFT_SEARCH_INSTALL_DATADIR)
117 set(ALSOFT_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
120 if(DEFINED SHARE_INSTALL_DIR)
121 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
122 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
125 if(DEFINED LIB_SUFFIX)
126 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
128 if(DEFINED ALSOFT_CONFIG)
129 message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
131 if(DEFINED ALSOFT_HRTF_DEFS)
132 message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
134 if(DEFINED ALSOFT_AMBDEC_PRESETS)
135 message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
139 set(CPP_DEFS ) # C pre-processor, not C++
146 set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
148 set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
151 option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
153 option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
156 option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
160 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
161 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
162 set(INC_PATHS ${INC_PATHS} /usr/include)
163 set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
166 # When the library is built for static linking, apps should define
167 # AL_LIBTYPE_STATIC when including the AL headers.
172 set(LIB_MAJOR_VERSION "1")
173 set(LIB_MINOR_VERSION "23")
174 set(LIB_REVISION "0")
175 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
176 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
182 set(CMAKE_CXX_STANDARD 14)
183 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
185 # Prefer C11, but support C99 and C90 too.
186 set(CMAKE_C_STANDARD 11)
189 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
190 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
191 if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
192 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
193 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
194 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
195 if(NOT HAVE_POSIX_MEMALIGN_POSIX)
196 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
198 set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
201 unset(OLD_REQUIRED_FLAGS)
204 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
205 check_cxx_source_compiles("int *__restrict foo;
206 int main() { return 0; }" HAVE___RESTRICT)
208 set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
210 set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
213 # Some systems may need libatomic for atomic functions to work
214 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
215 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
216 check_cxx_source_compiles("#include <atomic>
217 std::atomic<int> foo{0};
218 int main() { return foo.fetch_add(2); }"
220 if(NOT HAVE_LIBATOMIC)
221 set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
223 set(EXTRA_LIBS atomic ${EXTRA_LIBS})
225 unset(OLD_REQUIRED_LIBRARIES)
228 # Include liblog for Android logging
229 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
231 set(EXTRA_LIBS log ${EXTRA_LIBS})
232 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
237 set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
238 check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
239 if(HAVE_PERMISSIVE_SWITCH)
240 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
242 set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030 /wd5051)
245 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
247 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
250 message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
253 option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
254 if(FORCE_STATIC_VCRT)
256 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
257 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
258 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
259 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
260 if(${flag_var} MATCHES "/MD")
261 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
266 set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
268 $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
270 check_cxx_compiler_flag(-Wno-c++20-attribute-extensions HAVE_WNO_CXX20_ATTR_EXT)
271 if(HAVE_WNO_CXX20_ATTR_EXT)
272 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-attribute-extensions>)
274 check_cxx_compiler_flag(-Wno-c++20-extensions HAVE_WNO_CXX20_EXT)
275 if(HAVE_WNO_CXX20_EXT)
276 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:-Wno-c++20-extensions>)
281 set(C_FLAGS ${C_FLAGS} -Werror)
284 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
286 foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
287 if(${flag_var} MATCHES "-DNDEBUG")
288 string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
292 check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
293 if(HAVE_FNO_MATH_ERRNO)
294 set(C_FLAGS ${C_FLAGS} -fno-math-errno)
297 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
298 if(ALSOFT_STATIC_LIBGCC)
299 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
300 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
301 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
302 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
303 unset(OLD_REQUIRED_LIBRARIES)
305 if(NOT HAVE_STATIC_LIBGCC_SWITCH)
306 message(FATAL_ERROR "Cannot static link libgcc")
308 set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
311 option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
312 if(ALSOFT_STATIC_STDCXX)
313 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
314 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
315 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
316 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
317 unset(OLD_REQUIRED_LIBRARIES)
319 if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
320 message(FATAL_ERROR "Cannot static link libstdc++")
322 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
326 option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
327 if(ALSOFT_STATIC_WINPTHREAD)
328 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
329 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
330 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
331 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
332 unset(OLD_REQUIRED_LIBRARIES)
334 if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
335 message(FATAL_ERROR "Cannot static link libwinpthread")
337 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
342 # Set visibility/export options if available
344 if(NOT LIBTYPE STREQUAL "STATIC")
345 set(EXPORT_DECL "__declspec(dllexport)")
348 set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
349 # Yes GCC, really don't accept visibility modes you don't support
350 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
352 check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
353 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
354 if(HAVE_GCC_PROTECTED_VISIBILITY)
355 if(NOT LIBTYPE STREQUAL "STATIC")
356 set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
359 check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
360 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
361 if(HAVE_GCC_DEFAULT_VISIBILITY)
362 if(NOT LIBTYPE STREQUAL "STATIC")
363 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
368 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
375 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
376 # Yes GCC, really don't accept command line options you don't support
377 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
378 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
379 if(HAVE_MSSE2_SWITCH)
380 set(SSE2_SWITCH "-msse2")
382 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
383 unset(OLD_REQUIRED_FLAGS)
386 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
387 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
388 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
389 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
390 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
398 # Check for SSE support
399 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
401 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
402 if(ALSOFT_CPUEXT_SSE)
406 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
407 message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
410 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
412 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
413 if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
417 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
418 message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
421 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
423 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
424 if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
428 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
429 message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
432 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
434 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
435 if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
439 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
440 message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
443 # Check for ARM Neon support
444 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
446 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
447 if(ALSOFT_CPUEXT_NEON)
448 check_c_source_compiles("#include <arm_neon.h>
451 int32x4_t ret4 = vdupq_n_s32(0);
452 return vgetq_lane_s32(ret4, 0);
453 }" HAVE_NEON_INTRINSICS)
454 if(HAVE_NEON_INTRINSICS)
459 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
460 message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
466 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
467 option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
468 if(ALSOFT_ENABLE_SSE2_CODEGEN)
470 check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
472 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
473 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
477 check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
478 if(HAVE_MFPMATH_SSE_2)
479 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
480 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
483 # SSE depends on a 16-byte aligned stack, and by default, GCC
484 # assumes the stack is suitably aligned. Older Linux code or other
485 # OSs don't guarantee this on 32-bit, so externally-callable
486 # functions need to ensure an aligned stack.
487 set(EXPORT_DECL "${EXPORT_DECL}__attribute__((force_align_arg_pointer))")
493 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
494 foreach(flag_var ${SSE_FLAGS})
495 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
498 check_c_source_compiles("#include <emmintrin.h>
499 int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
501 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
505 check_include_file(malloc.h HAVE_MALLOC_H)
506 check_include_file(cpuid.h HAVE_CPUID_H)
507 check_include_file(intrin.h HAVE_INTRIN_H)
508 check_include_file(guiddef.h HAVE_GUIDDEF_H)
509 if(NOT HAVE_GUIDDEF_H)
510 check_include_file(initguid.h HAVE_INITGUID_H)
513 # Some systems need libm for some math functions to work
515 check_library_exists(m pow "" HAVE_LIBM)
517 set(MATH_LIB ${MATH_LIB} m)
518 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
521 # Some systems need to link with -lrt for clock_gettime as used by the common
524 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
529 # Check for the dlopen API (for dynamicly loading backend libs)
531 check_include_file(dlfcn.h HAVE_DLFCN_H)
532 check_library_exists(dl dlopen "" HAVE_LIBDL)
534 set(EXTRA_LIBS dl ${EXTRA_LIBS})
535 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
539 # Check for a cpuid intrinsic
541 check_c_source_compiles("#include <cpuid.h>
544 unsigned int eax, ebx, ecx, edx;
545 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
546 }" HAVE_GCC_GET_CPUID)
549 check_c_source_compiles("#include <intrin.h>
555 }" HAVE_CPUID_INTRINSIC)
558 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
559 check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
560 check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
563 # We need pthreads outside of Windows, for semaphores. It's also used to
564 # set the priority and name of threads, when possible.
565 check_include_file(pthread.h HAVE_PTHREAD_H)
566 if(NOT HAVE_PTHREAD_H)
567 message(FATAL_ERROR "PThreads is required for non-Windows builds!")
570 check_c_compiler_flag(-pthread HAVE_PTHREAD)
572 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
573 set(C_FLAGS ${C_FLAGS} -pthread)
574 set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
577 check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
579 # Some systems need pthread_np.h to get pthread_setname_np
580 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
581 if(HAVE_PTHREAD_NP_H)
582 check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
583 if(NOT HAVE_PTHREAD_SETNAME_NP)
584 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
587 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
588 if(NOT HAVE_PTHREAD_SETNAME_NP)
589 check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
594 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
597 # Common sources used by both the OpenAL implementation library, the OpenAL
598 # router, and certain tools and examples.
619 common/intrusive_ptr.h
621 common/phase_shifter.h
622 common/polyphase_resampler.cpp
623 common/polyphase_resampler.h
625 common/ringbuffer.cpp
634 # Core library routines
646 core/bsinc_tables.cpp
649 core/buffer_storage.cpp
650 core/buffer_storage.h
658 core/cubic_tables.cpp
669 core/filters/biquad.h
670 core/filters/biquad.cpp
673 core/filters/splitter.cpp
674 core/filters/splitter.h
679 core/front_stablizer.h
690 core/resampler_limits.h
700 option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
701 find_package(DBus1 QUIET)
702 if(NOT DBus1_FOUND AND PkgConfig_FOUND)
703 pkg_check_modules(DBUS dbus-1)
705 if(DBus1_FOUND OR DBUS_FOUND)
706 option(ALSOFT_RTKIT "Enable RTKit support" ON)
709 set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
710 core/rtkit.cpp core/rtkit.h)
712 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
713 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
715 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
718 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
719 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
721 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
726 if(NOT DBus1_INCLUDE_DIRS)
727 set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
729 if(NOT DBus1_LIBRARIES)
730 set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
732 message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
736 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
737 message(FATAL_ERROR "Failed to enabled required RTKit support")
740 # Default mixers, always available
741 set(CORE_OBJS ${CORE_OBJS}
743 core/mixer/hrtfbase.h
744 core/mixer/hrtfdefs.h
745 core/mixer/mixer_c.cpp)
747 # AL and related routines
755 al/effects/autowah.cpp
756 al/effects/chorus.cpp
757 al/effects/compressor.cpp
758 al/effects/convolution.cpp
759 al/effects/dedicated.cpp
760 al/effects/distortion.cpp
762 al/effects/effects.cpp
764 al/effects/equalizer.cpp
765 al/effects/fshifter.cpp
766 al/effects/modulator.cpp
768 al/effects/pshifter.cpp
769 al/effects/reverb.cpp
770 al/effects/vmorpher.cpp
783 # ALC and related routines
795 alc/effects/autowah.cpp
796 alc/effects/chorus.cpp
797 alc/effects/compressor.cpp
798 alc/effects/convolution.cpp
799 alc/effects/dedicated.cpp
800 alc/effects/distortion.cpp
802 alc/effects/equalizer.cpp
803 alc/effects/fshifter.cpp
804 alc/effects/modulator.cpp
806 alc/effects/pshifter.cpp
807 alc/effects/reverb.cpp
808 alc/effects/vmorpher.cpp
822 al/eax/fx_slot_index.cpp
823 al/eax/fx_slot_index.h
834 # Include SIMD mixers
835 set(CPU_EXTS "Default")
837 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp)
838 set(CPU_EXTS "${CPU_EXTS}, SSE")
841 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
842 set(CPU_EXTS "${CPU_EXTS}, SSE2")
845 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
846 set(CPU_EXTS "${CPU_EXTS}, SSE3")
849 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
850 set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
853 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp)
854 set(CPU_EXTS "${CPU_EXTS}, Neon")
866 set(HAVE_PORTAUDIO 0)
867 set(HAVE_PULSEAUDIO 0)
868 set(HAVE_COREAUDIO 0)
874 if(WIN32 OR HAVE_DLFCN_H)
876 macro(ADD_BACKEND_LIBS _LIBS)
879 set(IS_LINKED " (linked)")
880 macro(ADD_BACKEND_LIBS _LIBS)
881 set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
886 set(ALC_OBJS ${ALC_OBJS}
887 alc/backends/base.cpp
889 # Default backends, always available
890 alc/backends/loopback.cpp
891 alc/backends/loopback.h
892 alc/backends/null.cpp
897 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
900 option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
901 if(ALSOFT_BACKEND_ALSA)
903 set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
904 set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
905 add_backend_libs(${ALSA_LIBRARIES})
906 set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
909 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
910 message(FATAL_ERROR "Failed to enabled required ALSA backend")
914 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
917 option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
918 if(ALSOFT_BACKEND_OSS)
920 set(BACKENDS "${BACKENDS} OSS,")
921 set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
923 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
925 set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
928 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
929 message(FATAL_ERROR "Failed to enabled required OSS backend")
932 # Check PipeWire backend
933 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
935 pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
937 option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
938 if(ALSOFT_BACKEND_PIPEWIRE)
940 set(BACKENDS "${BACKENDS} PipeWire${IS_LINKED},")
941 set(ALC_OBJS ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
942 add_backend_libs(${PIPEWIRE_LIBRARIES})
943 set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
947 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
948 message(FATAL_ERROR "Failed to enabled required PipeWire backend")
951 # Check Solaris backend
952 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
953 find_package(AudioIO)
955 option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
956 if(ALSOFT_BACKEND_SOLARIS)
958 set(BACKENDS "${BACKENDS} Solaris,")
959 set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
960 set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
963 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
964 message(FATAL_ERROR "Failed to enabled required Solaris backend")
967 # Check SndIO backend
968 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
969 find_package(SoundIO)
971 option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
972 if(ALSOFT_BACKEND_SNDIO)
974 set(BACKENDS "${BACKENDS} SndIO (linked),")
975 set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
976 set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
977 set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
980 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
981 message(FATAL_ERROR "Failed to enabled required SndIO backend")
984 # Check Windows-only backends
985 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
986 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
987 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
989 # Check MMSystem backend
990 option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
991 if(ALSOFT_BACKEND_WINMM)
993 set(BACKENDS "${BACKENDS} WinMM,")
994 set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
995 # There doesn't seem to be good way to search for winmm.lib for MSVC.
996 # find_library doesn't find it without being told to look in a specific
997 # place in the WindowsSDK, but it links anyway. If there ends up being
998 # Windows targets without this, another means to detect it is needed.
999 set(EXTRA_LIBS winmm ${EXTRA_LIBS})
1002 # Check DSound backend
1003 check_include_file(dsound.h HAVE_DSOUND_H)
1005 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
1006 PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
1007 DOC "The DirectSound include directory")
1009 if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
1010 option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1011 if(ALSOFT_BACKEND_DSOUND)
1013 set(BACKENDS "${BACKENDS} DirectSound,")
1014 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1016 if(NOT HAVE_DSOUND_H)
1017 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1022 # Check for WASAPI backend
1023 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1024 if(HAVE_MMDEVICEAPI_H)
1025 option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1026 if(ALSOFT_BACKEND_WASAPI)
1028 set(BACKENDS "${BACKENDS} WASAPI,")
1029 set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1033 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1034 message(FATAL_ERROR "Failed to enabled required WinMM backend")
1036 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1037 message(FATAL_ERROR "Failed to enabled required DSound backend")
1039 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1040 message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1043 # Check PortAudio backend
1044 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1045 find_package(PortAudio)
1047 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1048 if(ALSOFT_BACKEND_PORTAUDIO)
1049 set(HAVE_PORTAUDIO 1)
1050 set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1051 set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1052 add_backend_libs(${PORTAUDIO_LIBRARIES})
1053 set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1056 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1057 message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1060 # Check PulseAudio backend
1061 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1062 find_package(PulseAudio)
1063 if(PULSEAUDIO_FOUND)
1064 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1065 if(ALSOFT_BACKEND_PULSEAUDIO)
1066 set(HAVE_PULSEAUDIO 1)
1067 set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1068 set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
1069 add_backend_libs(${PULSEAUDIO_LIBRARY})
1070 set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIR})
1073 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1074 message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1077 # Check JACK backend
1078 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1081 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1082 if(ALSOFT_BACKEND_JACK)
1084 set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1085 set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1086 add_backend_libs(${JACK_LIBRARIES})
1087 set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1090 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1091 message(FATAL_ERROR "Failed to enabled required JACK backend")
1094 # Check CoreAudio backend
1095 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1096 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1097 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1098 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1099 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1100 if(ALSOFT_BACKEND_COREAUDIO)
1101 set(HAVE_COREAUDIO 1)
1102 set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1103 set(BACKENDS "${BACKENDS} CoreAudio,")
1105 set(EXTRA_LIBS -Wl,-framework,CoreAudio ${EXTRA_LIBS})
1106 if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|tvOS)$")
1107 find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1108 if(COREFOUNDATION_FRAMEWORK)
1109 set(EXTRA_LIBS -Wl,-framework,CoreFoundation ${EXTRA_LIBS})
1112 set(EXTRA_LIBS -Wl,-framework,AudioUnit,-framework,ApplicationServices ${EXTRA_LIBS})
1115 # Some versions of OSX may need the AudioToolbox framework. Add it if
1117 find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1118 if(AUDIOTOOLBOX_LIBRARY)
1119 set(EXTRA_LIBS -Wl,-framework,AudioToolbox ${EXTRA_LIBS})
1122 set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1125 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1126 message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1129 # Check for OpenSL (Android) backend
1130 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1131 find_package(OpenSL)
1133 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1134 if(ALSOFT_BACKEND_OPENSL)
1136 set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1137 set(BACKENDS "${BACKENDS} OpenSL,")
1138 set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1141 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1142 message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1145 # Check for Oboe (Android) backend
1148 set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1150 add_subdirectory(${OBOE_SOURCE} ./oboe)
1151 set(OBOE_TARGET oboe)
1153 find_package(oboe CONFIG)
1154 if(NOT TARGET oboe::oboe)
1157 if(TARGET oboe::oboe)
1158 set(OBOE_TARGET "oboe::oboe")
1163 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1165 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1166 if(ALSOFT_BACKEND_OBOE)
1168 set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1169 set(BACKENDS "${BACKENDS} Oboe,")
1170 set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1173 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1174 message(FATAL_ERROR "Failed to enabled required Oboe backend")
1177 # Check for SDL2 backend
1178 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1179 find_package(SDL2 QUIET)
1181 # Off by default, since it adds a runtime dependency
1182 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1183 if(ALSOFT_BACKEND_SDL2)
1185 set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1186 set(BACKENDS "${BACKENDS} SDL2,")
1187 set(EXTRA_LIBS ${EXTRA_LIBS} SDL2::SDL2)
1190 message(STATUS "Could NOT find SDL2")
1192 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1193 message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1196 # Optionally enable the Wave Writer backend
1197 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1198 if(ALSOFT_BACKEND_WAVE)
1200 set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1201 set(BACKENDS "${BACKENDS} WaveFile,")
1204 # This is always available
1205 set(BACKENDS "${BACKENDS} Null")
1209 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git/index")
1210 # Get the current working branch and its latest abbreviated commit hash
1211 add_custom_command(OUTPUT "${OpenAL_BINARY_DIR}/version_witness.txt"
1212 BYPRODUCTS "${OpenAL_BINARY_DIR}/version.h"
1213 COMMAND ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1214 -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1215 -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1216 COMMAND ${CMAKE_COMMAND} -E touch "${OpenAL_BINARY_DIR}/version_witness.txt"
1217 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1218 MAIN_DEPENDENCY "${OpenAL_SOURCE_DIR}/version.h.in"
1219 DEPENDS "${OpenAL_SOURCE_DIR}/.git/index" "${OpenAL_SOURCE_DIR}/version.cmake"
1223 add_custom_target(build_version DEPENDS "${OpenAL_BINARY_DIR}/version_witness.txt")
1225 set(GIT_BRANCH "UNKNOWN")
1226 set(GIT_COMMIT_HASH "unknown")
1228 "${OpenAL_SOURCE_DIR}/version.h.in"
1229 "${OpenAL_BINARY_DIR}/version.h")
1233 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1234 if(ALSOFT_EMBED_HRTF_DATA)
1235 macro(make_hrtf_header FILENAME VARNAME)
1236 set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1237 set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.txt")
1239 add_custom_command(OUTPUT "${outfile}"
1240 COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1241 -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1242 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1243 DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1246 set(ALC_OBJS ${ALC_OBJS} "${outfile}")
1249 make_hrtf_header("Default HRTF.mhr" "default_hrtf")
1254 find_package(MySOFA)
1255 if(NOT ALSOFT_NO_CONFIG_UTIL)
1256 find_package(Qt5Widgets QUIET)
1257 if(NOT Qt5Widgets_FOUND)
1258 message(STATUS "Could NOT find Qt5Widgets")
1262 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1263 find_package(SndFile)
1265 find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1270 set(LIBNAME "openal")
1272 set(LIBNAME "OpenAL32")
1275 # Needed for openal.pc.in
1276 set(prefix ${CMAKE_INSTALL_PREFIX})
1277 set(exec_prefix "\${prefix}")
1278 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1279 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1280 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1281 set(PACKAGE_VERSION "${LIB_VERSION}")
1282 set(PKG_CONFIG_CFLAGS )
1283 set(PKG_CONFIG_PRIVATE_LIBS )
1284 if(LIBTYPE STREQUAL "STATIC")
1285 set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1286 foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1287 # If this is already a linker flag, or is a full path+file, add it
1288 # as-is. If it's an SDL2 target, add the link flag for it. Otherwise,
1289 # it's a name intended to be dressed as -lname.
1290 if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1291 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1292 elseif(FLAG MATCHES "^SDL2::SDL2")
1293 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -lSDL2")
1295 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1302 "${OpenAL_SOURCE_DIR}/config.h.in"
1303 "${OpenAL_BINARY_DIR}/config.h")
1305 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1306 "${OpenAL_BINARY_DIR}/openal.pc"
1310 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1311 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1312 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1313 target_compile_options(common PRIVATE ${C_FLAGS})
1314 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1318 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1320 # Build main library
1321 if(LIBTYPE STREQUAL "STATIC")
1322 add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1323 target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1324 target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1327 # This option is for static linking OpenAL Soft into another project
1328 # that already defines the IDs. It is up to that project to ensure all
1329 # required IDs are defined.
1330 option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1331 if(ALSOFT_NO_UID_DEFS)
1332 target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1336 set(RC_CONFIG resources/openal32.rc)
1337 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1338 add_library(OpenAL SHARED
1345 target_compile_definitions(OpenAL
1346 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1347 "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1348 target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1349 target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1350 target_include_directories(OpenAL
1352 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1353 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1355 ${OpenAL_SOURCE_DIR}/common
1356 ${OpenAL_BINARY_DIR}
1358 set_target_properties(OpenAL PROPERTIES PREFIX "")
1359 set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1360 if(TARGET build_version)
1361 add_dependencies(OpenAL build_version)
1365 set(LIBNAME "soft_oal")
1366 set(IMPL_TARGET soft_oal)
1367 set(RC_CONFIG resources/soft_oal.rc)
1370 # !important: for osx framework public header works, the headers must be in
1372 set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h
1373 include/AL/efx-presets.h)
1374 add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1375 ${TARGET_PUBLIC_HEADERS})
1377 set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1379 target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1381 if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1382 # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1383 set(LIBNAME "soft_oal")
1385 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD
1387 OUTPUT_VARIABLE BUNDLE_VERSION
1388 OUTPUT_STRIP_TRAILING_WHITESPACE)
1390 set(BUNDLE_VERSION 1)
1393 # Build: Fix rpath in iOS shared libraries
1394 # If this flag is not set, the final dylib binary ld path will be
1395 # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1396 # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1397 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1398 set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1401 set_target_properties(${IMPL_TARGET} PROPERTIES
1404 MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1405 MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1406 MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${LIB_VERSION}"
1407 MACOSX_FRAMEWORK_BUNDLE_VERSION "${BUNDLE_VERSION}"
1408 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1409 XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1410 XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1411 PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1416 target_include_directories(${IMPL_TARGET}
1418 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1420 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1421 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1422 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1425 ${OpenAL_BINARY_DIR}
1426 ${OpenAL_SOURCE_DIR}
1427 ${OpenAL_SOURCE_DIR}/common
1430 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1431 VERSION ${LIB_VERSION}
1432 SOVERSION ${LIB_MAJOR_VERSION}
1434 target_compile_definitions(${IMPL_TARGET}
1435 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1437 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1439 if(TARGET build_version)
1440 add_dependencies(${IMPL_TARGET} build_version)
1443 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1444 find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1445 if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1447 if(NOT SED_EXECUTABLE)
1448 message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1450 if(NOT CMAKE_DLLTOOL)
1451 message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1454 set_property(TARGET OpenAL APPEND_STRING PROPERTY
1455 LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1456 add_custom_command(TARGET OpenAL POST_BUILD
1457 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1458 COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1459 # Technically OpenAL32.def was created by the build, but cmake
1460 # doesn't recognize it due to -Wl,--output-def,OpenAL32.def being
1461 # manually specified. But declaring the file here allows it to be
1462 # properly cleaned, e.g. during make clean.
1463 BYPRODUCTS OpenAL32.def OpenAL32.lib
1464 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1472 message(STATUS "Building DLL router")
1476 message(STATUS "Building OpenAL with support for the following backends:")
1477 message(STATUS " ${BACKENDS}")
1479 message(STATUS "Building with support for CPU extensions:")
1480 message(STATUS " ${CPU_EXTS}")
1483 message(STATUS "Building with SSE${FPMATH_SET} codegen")
1488 message(STATUS "Building with legacy EAX extension support")
1492 if(ALSOFT_EMBED_HRTF_DATA)
1493 message(STATUS "Embedding HRTF datasets")
1497 # An alias for sub-project builds
1498 add_library(OpenAL::OpenAL ALIAS OpenAL)
1500 # Install main library
1502 configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1503 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1504 install(TARGETS OpenAL EXPORT OpenAL
1505 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1506 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1507 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1508 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1509 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1510 export(TARGETS OpenAL
1512 FILE OpenALTargets.cmake)
1513 install(EXPORT OpenAL
1514 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1516 FILE OpenALTargets.cmake)
1517 install(DIRECTORY include/AL
1518 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1519 install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1520 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1521 install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1522 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1524 install(TARGETS soft_oal
1525 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1527 message(STATUS "Installing library and headers")
1529 message(STATUS "NOT installing library and headers")
1532 if(ALSOFT_INSTALL_CONFIG)
1533 install(FILES alsoftrc.sample
1534 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1535 message(STATUS "Installing sample configuration")
1538 if(ALSOFT_INSTALL_HRTF_DATA)
1539 install(DIRECTORY hrtf
1540 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1541 message(STATUS "Installing HRTF data files")
1544 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1545 install(DIRECTORY presets
1546 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1547 message(STATUS "Installing AmbDec presets")
1553 set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1555 set(EXTRA_INSTALLS )
1557 add_executable(openal-info utils/openal-info.c)
1558 target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1559 target_compile_options(openal-info PRIVATE ${C_FLAGS})
1560 target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1561 if(ALSOFT_INSTALL_EXAMPLES)
1562 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1566 add_executable(uhjdecoder utils/uhjdecoder.cpp)
1567 target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1568 target_include_directories(uhjdecoder
1569 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1570 target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1571 target_link_libraries(uhjdecoder PUBLIC common
1572 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1574 add_executable(uhjencoder utils/uhjencoder.cpp)
1575 target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1576 target_include_directories(uhjencoder
1577 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1578 target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1579 target_link_libraries(uhjencoder PUBLIC common
1580 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1584 set(SOFA_SUPPORT_SRCS
1585 utils/sofa-support.cpp
1586 utils/sofa-support.h)
1587 add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1588 target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1589 target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1590 target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1591 target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1594 utils/makemhr/loaddef.cpp
1595 utils/makemhr/loaddef.h
1596 utils/makemhr/loadsofa.cpp
1597 utils/makemhr/loadsofa.h
1598 utils/makemhr/makemhr.cpp
1599 utils/makemhr/makemhr.h)
1601 set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1603 add_executable(makemhr ${MAKEMHR_SRCS})
1604 target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1605 target_include_directories(makemhr
1606 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1607 target_compile_options(makemhr PRIVATE ${C_FLAGS})
1608 target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1609 if(ALSOFT_INSTALL_EXAMPLES)
1610 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1613 set(SOFAINFO_SRCS utils/sofa-info.cpp)
1614 add_executable(sofa-info ${SOFAINFO_SRCS})
1615 target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1616 target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1617 target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1618 target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1620 message(STATUS "Building utility programs")
1622 if(NOT ALSOFT_NO_CONFIG_UTIL)
1623 add_subdirectory(utils/alsoft-config)
1629 # Add a static library with common functions used by multiple example targets
1630 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1631 examples/common/alhelpers.c
1632 examples/common/alhelpers.h)
1633 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1634 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1635 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1636 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1639 add_executable(altonegen examples/altonegen.c)
1640 target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1642 add_executable(alrecord examples/alrecord.c)
1643 target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1645 if(ALSOFT_INSTALL_EXAMPLES)
1646 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1649 message(STATUS "Building example programs")
1652 add_executable(alplay examples/alplay.c)
1653 target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1656 add_executable(alstream examples/alstream.c)
1657 target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1660 add_executable(alreverb examples/alreverb.c)
1661 target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1664 add_executable(almultireverb examples/almultireverb.c)
1665 target_link_libraries(almultireverb
1666 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1668 add_executable(allatency examples/allatency.c)
1669 target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1672 add_executable(alhrtf examples/alhrtf.c)
1673 target_link_libraries(alhrtf
1674 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1676 add_executable(alstreamcb examples/alstreamcb.cpp)
1677 target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1680 add_executable(alconvolve examples/alconvolve.c)
1681 target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1684 if(ALSOFT_INSTALL_EXAMPLES)
1685 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1689 message(STATUS "Building SndFile example programs")
1693 add_executable(alloopback examples/alloopback.c)
1694 target_link_libraries(alloopback
1695 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ex-common ${MATH_LIB})
1697 if(ALSOFT_INSTALL_EXAMPLES)
1698 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1701 message(STATUS "Building SDL example programs")
1706 if(AVFORMAT_VERSION VERSION_LESS "59.27.100")
1707 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 59.27.100)")
1710 if(AVCODEC_VERSION VERSION_LESS "59.37.100")
1711 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 59.37.100)")
1714 if(AVUTIL_VERSION VERSION_LESS "57.28.100")
1715 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 57.28.100)")
1718 if(SWSCALE_VERSION VERSION_LESS "6.7.100")
1719 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 6.7.100)")
1722 if(SWRESAMPLE_VERSION VERSION_LESS "4.7.100")
1723 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 4.7.100)")
1728 add_executable(alffplay examples/alffplay.cpp)
1729 target_include_directories(alffplay PRIVATE ${FFMPEG_INCLUDE_DIRS})
1730 target_link_libraries(alffplay
1731 PRIVATE ${LINKER_FLAGS} SDL2::SDL2 ${FFMPEG_LIBRARIES} ex-common)
1733 if(ALSOFT_INSTALL_EXAMPLES)
1734 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1736 message(STATUS "Building SDL+FFmpeg example programs")
1743 install(TARGETS ${EXTRA_INSTALLS}
1744 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1745 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
1746 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1747 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})