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"
35 if(COMMAND CMAKE_POLICY)
36 cmake_policy(SET CMP0003 NEW)
37 cmake_policy(SET CMP0005 NEW)
39 cmake_policy(SET CMP0020 NEW)
42 cmake_policy(SET CMP0042 NEW)
45 cmake_policy(SET CMP0054 NEW)
48 cmake_policy(SET CMP0075 NEW)
50 endif(COMMAND CMAKE_POLICY)
52 if(NOT CMAKE_BUILD_TYPE)
53 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
54 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
57 if(NOT CMAKE_DEBUG_POSTFIX)
58 set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
59 "Library postfix for debug builds. Normally left blank."
63 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
65 include(CheckFunctionExists)
66 include(CheckLibraryExists)
67 include(CheckIncludeFile)
68 include(CheckIncludeFiles)
69 include(CheckSymbolExists)
70 include(CheckCCompilerFlag)
71 include(CheckCXXCompilerFlag)
72 include(CheckCSourceCompiles)
73 include(CheckCXXSourceCompiles)
74 include(CheckStructHasMember)
75 include(CMakePackageConfigHelpers)
76 include(GNUInstallDirs)
78 find_package(PkgConfig)
81 option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
83 option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
85 option(ALSOFT_UTILS "Build utility programs" ON)
86 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
88 option(ALSOFT_EXAMPLES "Build example programs" ON)
90 option(ALSOFT_INSTALL "Install main library" ON)
91 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
92 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
93 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
94 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
95 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
96 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
98 option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
100 if(DEFINED SHARE_INSTALL_DIR)
101 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
102 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
105 if(DEFINED LIB_SUFFIX)
106 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
108 if(DEFINED ALSOFT_CONFIG)
109 message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
111 if(DEFINED ALSOFT_HRTF_DEFS)
112 message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
114 if(DEFINED ALSOFT_AMBDEC_PRESETS)
115 message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
119 set(CPP_DEFS ) # C pre-processor, not C++
126 set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
128 set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
131 option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
133 option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
136 option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
140 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
141 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
142 set(INC_PATHS ${INC_PATHS} /usr/include)
143 set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
146 # When the library is built for static linking, apps should define
147 # AL_LIBTYPE_STATIC when including the AL headers.
152 set(LIB_MAJOR_VERSION "1")
153 set(LIB_MINOR_VERSION "22")
154 set(LIB_REVISION "0")
155 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
156 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
162 set(CMAKE_CXX_STANDARD 14)
163 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
165 # Prefer C11, but support C99 and C90 too.
166 set(CMAKE_C_STANDARD 11)
169 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
170 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
171 if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
172 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
173 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
174 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
175 if(NOT HAVE_POSIX_MEMALIGN_POSIX)
176 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
178 set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
181 unset(OLD_REQUIRED_FLAGS)
184 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
185 check_cxx_source_compiles("int *__restrict foo;
186 int main() { return 0; }" HAVE___RESTRICT)
188 set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
190 set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
193 # Some systems may need libatomic for atomic functions to work
194 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
195 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
196 check_cxx_source_compiles("#include <atomic>
197 std::atomic<int> foo{0};
198 int main() { return foo.fetch_add(2); }"
200 if(NOT HAVE_LIBATOMIC)
201 set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
203 set(EXTRA_LIBS atomic ${EXTRA_LIBS})
205 unset(OLD_REQUIRED_LIBRARIES)
208 # Include liblog for Android logging
209 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
211 set(EXTRA_LIBS log ${EXTRA_LIBS})
212 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
217 set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
218 check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
219 if(HAVE_PERMISSIVE_SWITCH)
220 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
222 set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030)
223 # Remove /W3, which is added by default, since we set /W4. Some build
224 # generators with MSVC complain about both /W3 and /W4 being specified.
225 foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
226 if(${flag_var} MATCHES "/W3")
227 string(REGEX REPLACE "/W3" "" ${flag_var} "${${flag_var}}")
232 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
234 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
237 message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
240 option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
241 if(FORCE_STATIC_VCRT)
243 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
244 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
245 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
246 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
247 if(${flag_var} MATCHES "/MD")
248 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
253 set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
255 $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
258 set(C_FLAGS ${C_FLAGS} -Werror)
261 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
263 foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
264 if(${flag_var} MATCHES "-DNDEBUG")
265 string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
269 check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
270 if(HAVE_FNO_MATH_ERRNO)
271 set(C_FLAGS ${C_FLAGS} -fno-math-errno)
274 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
275 if(ALSOFT_STATIC_LIBGCC)
276 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
277 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
278 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
279 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
280 unset(OLD_REQUIRED_LIBRARIES)
282 if(NOT HAVE_STATIC_LIBGCC_SWITCH)
283 message(FATAL_ERROR "Cannot static link libgcc")
285 set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
288 option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
289 if(ALSOFT_STATIC_STDCXX)
290 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
291 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
292 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
293 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
294 unset(OLD_REQUIRED_LIBRARIES)
296 if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
297 message(FATAL_ERROR "Cannot static link libstdc++")
299 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
303 option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
304 if(ALSOFT_STATIC_WINPTHREAD)
305 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
306 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
307 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
308 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
309 unset(OLD_REQUIRED_LIBRARIES)
311 if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
312 message(FATAL_ERROR "Cannot static link libwinpthread")
314 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
319 # Set visibility/export options if available
321 if(NOT LIBTYPE STREQUAL "STATIC")
322 set(EXPORT_DECL "__declspec(dllexport)")
325 set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
326 # Yes GCC, really don't accept visibility modes you don't support
327 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
329 check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
330 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
331 if(HAVE_GCC_PROTECTED_VISIBILITY)
332 if(NOT LIBTYPE STREQUAL "STATIC")
333 set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
336 check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
337 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
338 if(HAVE_GCC_DEFAULT_VISIBILITY)
339 if(NOT LIBTYPE STREQUAL "STATIC")
340 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
345 if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
346 check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
347 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
348 set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
352 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
359 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
360 # Yes GCC, really don't accept command line options you don't support
361 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
362 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
363 if(HAVE_MSSE2_SWITCH)
364 set(SSE2_SWITCH "-msse2")
366 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
367 unset(OLD_REQUIRED_FLAGS)
370 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
371 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
372 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
373 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
374 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
382 # Check for SSE support
383 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
385 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
386 if(ALSOFT_CPUEXT_SSE)
390 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
391 message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
394 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
396 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
397 if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
401 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
402 message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
405 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
407 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
408 if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
412 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
413 message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
416 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
418 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
419 if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
423 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
424 message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
427 # Check for ARM Neon support
428 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
430 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
431 if(ALSOFT_CPUEXT_NEON)
432 check_c_source_compiles("#include <arm_neon.h>
435 int32x4_t ret4 = vdupq_n_s32(0);
436 return vgetq_lane_s32(ret4, 0);
437 }" HAVE_NEON_INTRINSICS)
438 if(HAVE_NEON_INTRINSICS)
443 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
444 message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
450 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
451 option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
452 if(ALSOFT_ENABLE_SSE2_CODEGEN)
454 check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
456 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
457 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
461 check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
462 if(HAVE_MFPMATH_SSE_2)
463 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
464 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
467 # SSE depends on a 16-byte aligned stack, and by default, GCC
468 # assumes the stack is suitably aligned. Older Linux code or other
469 # OSs don't guarantee this on 32-bit, so externally-callable
470 # functions need to ensure an aligned stack.
471 set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
477 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
478 foreach(flag_var ${SSE_FLAGS})
479 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
482 check_c_source_compiles("#include <emmintrin.h>
483 int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
485 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
489 check_include_file(malloc.h HAVE_MALLOC_H)
490 check_include_file(cpuid.h HAVE_CPUID_H)
491 check_include_file(intrin.h HAVE_INTRIN_H)
492 check_include_file(guiddef.h HAVE_GUIDDEF_H)
493 if(NOT HAVE_GUIDDEF_H)
494 check_include_file(initguid.h HAVE_INITGUID_H)
497 # Some systems need libm for some math functions to work
499 check_library_exists(m pow "" HAVE_LIBM)
501 set(MATH_LIB ${MATH_LIB} m)
502 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
505 # Some systems need to link with -lrt for clock_gettime as used by the common
508 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
513 # Check for the dlopen API (for dynamicly loading backend libs)
515 check_include_file(dlfcn.h HAVE_DLFCN_H)
516 check_library_exists(dl dlopen "" HAVE_LIBDL)
518 set(EXTRA_LIBS dl ${EXTRA_LIBS})
519 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
523 # Check for a cpuid intrinsic
525 check_c_source_compiles("#include <cpuid.h>
528 unsigned int eax, ebx, ecx, edx;
529 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
530 }" HAVE_GCC_GET_CPUID)
533 check_c_source_compiles("#include <intrin.h>
539 }" HAVE_CPUID_INTRINSIC)
542 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
543 check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
544 check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
547 # We need pthreads outside of Windows, for semaphores. It's also used to
548 # set the priority and name of threads, when possible.
549 check_include_file(pthread.h HAVE_PTHREAD_H)
550 if(NOT HAVE_PTHREAD_H)
551 message(FATAL_ERROR "PThreads is required for non-Windows builds!")
554 check_c_compiler_flag(-pthread HAVE_PTHREAD)
556 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
557 set(C_FLAGS ${C_FLAGS} -pthread)
558 set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
561 check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
563 # Some systems need pthread_np.h to get pthread_setname_np
564 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
565 if(HAVE_PTHREAD_NP_H)
566 check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
567 if(NOT HAVE_PTHREAD_SETNAME_NP)
568 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
571 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
572 if(NOT HAVE_PTHREAD_SETNAME_NP)
573 check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
578 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
581 # Common sources used by both the OpenAL implementation library, the OpenAL
582 # router, and certain tools and examples.
603 common/intrusive_ptr.h
605 common/phase_shifter.h
606 common/polyphase_resampler.cpp
607 common/polyphase_resampler.h
609 common/ringbuffer.cpp
618 # Core library routines
630 core/bsinc_tables.cpp
633 core/buffer_storage.cpp
634 core/buffer_storage.h
650 core/filters/biquad.h
651 core/filters/biquad.cpp
654 core/filters/splitter.cpp
655 core/filters/splitter.h
660 core/front_stablizer.h
671 core/resampler_limits.h
681 option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
682 find_package(DBus1 QUIET)
683 if(NOT DBus1_FOUND AND PkgConfig_FOUND)
684 pkg_check_modules(DBUS dbus-1)
686 if(DBus1_FOUND OR DBUS_FOUND)
687 option(ALSOFT_RTKIT "Enable RTKit support" ON)
690 set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
691 core/rtkit.cpp core/rtkit.h)
693 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
694 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
696 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
699 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
700 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
702 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
707 if(NOT DBus1_INCLUDE_DIRS)
708 set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
710 if(NOT DBus1_LIBRARIES)
711 set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
713 message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
717 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
718 message(FATAL_ERROR "Failed to enabled required RTKit support")
721 # Default mixers, always available
722 set(CORE_OBJS ${CORE_OBJS}
724 core/mixer/hrtfbase.h
725 core/mixer/hrtfdefs.h
726 core/mixer/mixer_c.cpp)
728 # AL and related routines
736 al/effects/autowah.cpp
737 al/effects/chorus.cpp
738 al/effects/compressor.cpp
739 al/effects/convolution.cpp
740 al/effects/dedicated.cpp
741 al/effects/distortion.cpp
743 al/effects/effects.cpp
745 al/effects/equalizer.cpp
746 al/effects/fshifter.cpp
747 al/effects/modulator.cpp
749 al/effects/pshifter.cpp
750 al/effects/reverb.cpp
751 al/effects/vmorpher.cpp
764 # ALC and related routines
776 alc/effects/autowah.cpp
777 alc/effects/chorus.cpp
778 alc/effects/compressor.cpp
779 alc/effects/convolution.cpp
780 alc/effects/dedicated.cpp
781 alc/effects/distortion.cpp
783 alc/effects/equalizer.cpp
784 alc/effects/fshifter.cpp
785 alc/effects/modulator.cpp
787 alc/effects/pshifter.cpp
788 alc/effects/reverb.cpp
789 alc/effects/vmorpher.cpp
804 al/eax_fx_slot_index.cpp
805 al/eax_fx_slot_index.h
817 # Include SIMD mixers
818 set(CPU_EXTS "Default")
820 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp)
821 set(CPU_EXTS "${CPU_EXTS}, SSE")
824 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
825 set(CPU_EXTS "${CPU_EXTS}, SSE2")
828 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
829 set(CPU_EXTS "${CPU_EXTS}, SSE3")
832 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
833 set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
836 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp)
837 set(CPU_EXTS "${CPU_EXTS}, Neon")
849 set(HAVE_PORTAUDIO 0)
850 set(HAVE_PULSEAUDIO 0)
851 set(HAVE_COREAUDIO 0)
857 if(WIN32 OR HAVE_DLFCN_H)
859 macro(ADD_BACKEND_LIBS _LIBS)
862 set(IS_LINKED " (linked)")
863 macro(ADD_BACKEND_LIBS _LIBS)
864 set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
869 set(ALC_OBJS ${ALC_OBJS}
870 alc/backends/base.cpp
872 # Default backends, always available
873 alc/backends/loopback.cpp
874 alc/backends/loopback.h
875 alc/backends/null.cpp
880 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
883 option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
884 if(ALSOFT_BACKEND_ALSA)
886 set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
887 set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
888 add_backend_libs(${ALSA_LIBRARIES})
889 set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
892 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
893 message(FATAL_ERROR "Failed to enabled required ALSA backend")
897 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
900 option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
901 if(ALSOFT_BACKEND_OSS)
903 set(BACKENDS "${BACKENDS} OSS,")
904 set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
906 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
908 set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
911 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
912 message(FATAL_ERROR "Failed to enabled required OSS backend")
915 # Check PipeWire backend
916 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
918 pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
920 option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
921 if(ALSOFT_BACKEND_PIPEWIRE)
923 set(BACKENDS "${BACKENDS} PipeWire${IS_LINKED},")
924 set(ALC_OBJS ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
925 add_backend_libs(${PIPEWIRE_LIBRARIES})
926 set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
930 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
931 message(FATAL_ERROR "Failed to enabled required PipeWire backend")
934 # Check Solaris backend
935 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
936 find_package(AudioIO)
938 option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
939 if(ALSOFT_BACKEND_SOLARIS)
941 set(BACKENDS "${BACKENDS} Solaris,")
942 set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
943 set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
946 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
947 message(FATAL_ERROR "Failed to enabled required Solaris backend")
950 # Check SndIO backend
951 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
952 find_package(SoundIO)
954 option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
955 if(ALSOFT_BACKEND_SNDIO)
957 set(BACKENDS "${BACKENDS} SndIO (linked),")
958 set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
959 set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
960 set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
963 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
964 message(FATAL_ERROR "Failed to enabled required SndIO backend")
967 # Check Windows-only backends
968 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
969 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
970 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
972 # Check MMSystem backend
973 option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
974 if(ALSOFT_BACKEND_WINMM)
976 set(BACKENDS "${BACKENDS} WinMM,")
977 set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
978 # There doesn't seem to be good way to search for winmm.lib for MSVC.
979 # find_library doesn't find it without being told to look in a specific
980 # place in the WindowsSDK, but it links anyway. If there ends up being
981 # Windows targets without this, another means to detect it is needed.
982 set(EXTRA_LIBS winmm ${EXTRA_LIBS})
985 # Check DSound backend
986 check_include_file(dsound.h HAVE_DSOUND_H)
988 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
989 PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
990 DOC "The DirectSound include directory")
992 if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
993 option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
994 if(ALSOFT_BACKEND_DSOUND)
996 set(BACKENDS "${BACKENDS} DirectSound,")
997 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
999 if(NOT HAVE_DSOUND_H)
1000 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1005 # Check for WASAPI backend
1006 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1007 if(HAVE_MMDEVICEAPI_H)
1008 option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1009 if(ALSOFT_BACKEND_WASAPI)
1011 set(BACKENDS "${BACKENDS} WASAPI,")
1012 set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1016 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1017 message(FATAL_ERROR "Failed to enabled required WinMM backend")
1019 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1020 message(FATAL_ERROR "Failed to enabled required DSound backend")
1022 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1023 message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1026 # Check PortAudio backend
1027 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1028 find_package(PortAudio)
1030 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1031 if(ALSOFT_BACKEND_PORTAUDIO)
1032 set(HAVE_PORTAUDIO 1)
1033 set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1034 set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1035 add_backend_libs(${PORTAUDIO_LIBRARIES})
1036 set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1039 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1040 message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1043 # Check PulseAudio backend
1044 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1045 find_package(PulseAudio)
1046 if(PULSEAUDIO_FOUND)
1047 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1048 if(ALSOFT_BACKEND_PULSEAUDIO)
1049 set(HAVE_PULSEAUDIO 1)
1050 set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1051 set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
1052 add_backend_libs(${PULSEAUDIO_LIBRARIES})
1053 set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1056 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1057 message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1060 # Check JACK backend
1061 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1064 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1065 if(ALSOFT_BACKEND_JACK)
1067 set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1068 set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1069 add_backend_libs(${JACK_LIBRARIES})
1070 set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1073 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1074 message(FATAL_ERROR "Failed to enabled required JACK backend")
1077 # Check CoreAudio backend
1078 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1079 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1080 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1081 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1082 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1083 if(ALSOFT_BACKEND_COREAUDIO)
1084 set(HAVE_COREAUDIO 1)
1085 set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1086 set(BACKENDS "${BACKENDS} CoreAudio,")
1087 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
1088 find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1089 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
1091 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1092 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1095 # Some versions of OSX may need the AudioToolbox framework. Add it if
1097 find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1098 if(AUDIOTOOLBOX_LIBRARY)
1099 set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1102 set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1105 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1106 message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1109 # Check for OpenSL (Android) backend
1110 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1111 find_package(OpenSL)
1113 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1114 if(ALSOFT_BACKEND_OPENSL)
1116 set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1117 set(BACKENDS "${BACKENDS} OpenSL,")
1118 set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1121 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1122 message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1125 # Check for Oboe (Android) backend
1128 set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1130 # Force Oboe to build with hidden symbols. Don't want to be exporting
1132 set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1133 check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1134 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1135 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1137 add_subdirectory(${OBOE_SOURCE} ./oboe)
1138 set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1139 unset(OLD_CXX_FLAGS)
1141 set(OBOE_TARGET oboe)
1145 set(OBOE_TARGET "oboe::oboe")
1150 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1152 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1153 if(ALSOFT_BACKEND_OBOE)
1155 set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1156 set(BACKENDS "${BACKENDS} Oboe,")
1157 set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1160 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1161 message(FATAL_ERROR "Failed to enabled required Oboe backend")
1164 # Check for SDL2 backend
1165 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1168 # Off by default, since it adds a runtime dependency
1169 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1170 if(ALSOFT_BACKEND_SDL2)
1172 set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1173 set(BACKENDS "${BACKENDS} SDL2,")
1174 set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1175 set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1178 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1179 message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1182 # Optionally enable the Wave Writer backend
1183 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1184 if(ALSOFT_BACKEND_WAVE)
1186 set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1187 set(BACKENDS "${BACKENDS} WaveFile,")
1190 # This is always available
1191 set(BACKENDS "${BACKENDS} Null")
1195 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1196 # Get the current working branch and its latest abbreviated commit hash
1197 add_custom_target(build_version
1198 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1199 -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1200 -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1201 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1205 set(GIT_BRANCH "UNKNOWN")
1206 set(GIT_COMMIT_HASH "unknown")
1208 "${OpenAL_SOURCE_DIR}/version.h.in"
1209 "${OpenAL_BINARY_DIR}/version.h")
1213 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1214 if(ALSOFT_EMBED_HRTF_DATA)
1215 macro(make_hrtf_header FILENAME VARNAME)
1216 set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1217 set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1219 add_custom_command(OUTPUT "${outfile}"
1220 COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1221 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1222 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1223 DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1226 set(ALC_OBJS ${ALC_OBJS} "${outfile}")
1229 make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1234 find_package(MySOFA)
1235 if(NOT ALSOFT_NO_CONFIG_UTIL)
1236 find_package(Qt5Widgets QUIET)
1237 if(NOT Qt5Widgets_FOUND)
1238 message(STATUS "Could NOT find Qt5Widgets")
1242 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1243 find_package(SndFile)
1246 find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1251 set(LIBNAME "openal")
1253 set(LIBNAME "OpenAL32")
1256 # Needed for openal.pc.in
1257 set(prefix ${CMAKE_INSTALL_PREFIX})
1258 set(exec_prefix "\${prefix}")
1259 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1260 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1261 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1262 set(PACKAGE_VERSION "${LIB_VERSION}")
1263 set(PKG_CONFIG_CFLAGS )
1264 set(PKG_CONFIG_PRIVATE_LIBS )
1265 if(LIBTYPE STREQUAL "STATIC")
1266 set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1267 foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1268 # If this is already a linker flag, or is a full path+file, add it
1269 # as-is. Otherwise, it's a name intended to be dressed as -lname.
1270 if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1271 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1273 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1280 "${OpenAL_SOURCE_DIR}/config.h.in"
1281 "${OpenAL_BINARY_DIR}/config.h")
1283 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1284 "${OpenAL_BINARY_DIR}/openal.pc"
1288 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1289 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1290 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1291 target_compile_options(common PRIVATE ${C_FLAGS})
1292 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1296 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1298 # Build main library
1299 if(LIBTYPE STREQUAL "STATIC")
1300 add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1301 target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1302 target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1305 # This option is for static linking OpenAL Soft into another project
1306 # that already defines the IDs. It is up to that project to ensure all
1307 # required IDs are defined.
1308 option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1309 if(ALSOFT_NO_UID_DEFS)
1310 target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1314 set(RC_CONFIG resources/openal32.rc)
1315 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1316 add_library(OpenAL SHARED
1323 target_compile_definitions(OpenAL
1324 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1325 "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1326 target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1327 target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1328 target_include_directories(OpenAL
1330 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1331 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1333 ${OpenAL_SOURCE_DIR}/common
1334 ${OpenAL_BINARY_DIR}
1336 set_target_properties(OpenAL PROPERTIES PREFIX "")
1337 set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1338 if(TARGET build_version)
1339 add_dependencies(OpenAL build_version)
1343 set(LIBNAME "soft_oal")
1344 set(IMPL_TARGET soft_oal)
1345 set(RC_CONFIG resources/soft_oal.rc)
1348 # !important: for osx framework public header works, the headers must be in
1350 set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1351 add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1352 ${TARGET_PUBLIC_HEADERS})
1354 set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1356 target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1358 if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1359 # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1360 set(LIBNAME "soft_oal")
1362 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1364 OUTPUT_VARIABLE BUNDLE_VERSION
1365 OUTPUT_STRIP_TRAILING_WHITESPACE)
1367 set(BUNDLE_VERSION 1)
1370 # Build: Fix rpath in iOS shared libraries
1371 # If this flag is not set, the final dylib binary ld path will be
1372 # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1373 # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1374 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1375 set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1378 set_target_properties(${IMPL_TARGET} PROPERTIES
1381 MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1382 MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1383 MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1384 MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1385 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1386 XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1387 XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1388 PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1393 target_include_directories(${IMPL_TARGET}
1395 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1397 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1398 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1399 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1402 ${OpenAL_BINARY_DIR}
1403 ${OpenAL_SOURCE_DIR}
1404 ${OpenAL_SOURCE_DIR}/common
1407 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1408 VERSION ${LIB_VERSION}
1409 SOVERSION ${LIB_MAJOR_VERSION}
1411 target_compile_definitions(${IMPL_TARGET}
1412 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1414 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1416 if(TARGET build_version)
1417 add_dependencies(${IMPL_TARGET} build_version)
1420 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1421 find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1422 if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1424 if(NOT SED_EXECUTABLE)
1425 message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1427 if(NOT CMAKE_DLLTOOL)
1428 message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1431 set_property(TARGET OpenAL APPEND_STRING PROPERTY
1432 LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1433 add_custom_command(TARGET OpenAL POST_BUILD
1434 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1435 COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1436 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1444 message(STATUS "Building DLL router")
1448 message(STATUS "Building OpenAL with support for the following backends:")
1449 message(STATUS " ${BACKENDS}")
1451 message(STATUS "Building with support for CPU extensions:")
1452 message(STATUS " ${CPU_EXTS}")
1455 message(STATUS "Building with SSE${FPMATH_SET} codegen")
1460 message(STATUS "Building with legacy EAX extension support")
1464 if(ALSOFT_EMBED_HRTF_DATA)
1465 message(STATUS "Embedding HRTF datasets")
1469 # An alias for sub-project builds
1470 add_library(OpenAL::OpenAL ALIAS OpenAL)
1472 # Install main library
1474 configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1475 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1476 install(TARGETS OpenAL EXPORT OpenAL
1477 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1478 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1479 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1480 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1481 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1482 export(TARGETS OpenAL
1484 FILE OpenALTargets.cmake)
1485 install(EXPORT OpenAL
1486 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1488 FILE OpenALTargets.cmake)
1489 install(DIRECTORY include/AL
1490 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1491 install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1492 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1493 install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1494 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1496 install(TARGETS soft_oal
1497 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1499 message(STATUS "Installing library and headers")
1501 message(STATUS "NOT installing library and headers")
1504 if(ALSOFT_INSTALL_CONFIG)
1505 install(FILES alsoftrc.sample
1506 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1507 message(STATUS "Installing sample configuration")
1510 if(ALSOFT_INSTALL_HRTF_DATA)
1511 install(DIRECTORY hrtf
1512 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1513 message(STATUS "Installing HRTF data files")
1516 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1517 install(DIRECTORY presets
1518 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1519 message(STATUS "Installing AmbDec presets")
1525 set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1527 set(EXTRA_INSTALLS )
1529 add_executable(openal-info utils/openal-info.c)
1530 target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1531 target_compile_options(openal-info PRIVATE ${C_FLAGS})
1532 target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1533 if(ALSOFT_INSTALL_EXAMPLES)
1534 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1538 add_executable(uhjdecoder utils/uhjdecoder.cpp)
1539 target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1540 target_include_directories(uhjdecoder
1541 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1542 target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1543 target_link_libraries(uhjdecoder PUBLIC common
1544 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1546 add_executable(uhjencoder utils/uhjencoder.cpp)
1547 target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1548 target_include_directories(uhjencoder
1549 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1550 target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1551 target_link_libraries(uhjencoder PUBLIC common
1552 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1556 set(SOFA_SUPPORT_SRCS
1557 utils/sofa-support.cpp
1558 utils/sofa-support.h)
1559 add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1560 target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1561 target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1562 target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1563 target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1566 utils/makemhr/loaddef.cpp
1567 utils/makemhr/loaddef.h
1568 utils/makemhr/loadsofa.cpp
1569 utils/makemhr/loadsofa.h
1570 utils/makemhr/makemhr.cpp
1571 utils/makemhr/makemhr.h)
1573 set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1575 add_executable(makemhr ${MAKEMHR_SRCS})
1576 target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1577 target_include_directories(makemhr
1578 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1579 target_compile_options(makemhr PRIVATE ${C_FLAGS})
1580 target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1581 if(ALSOFT_INSTALL_EXAMPLES)
1582 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1585 set(SOFAINFO_SRCS utils/sofa-info.cpp)
1586 add_executable(sofa-info ${SOFAINFO_SRCS})
1587 target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1588 target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1589 target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1590 target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1592 message(STATUS "Building utility programs")
1594 if(NOT ALSOFT_NO_CONFIG_UTIL)
1595 add_subdirectory(utils/alsoft-config)
1601 # Add a static library with common functions used by multiple example targets
1602 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1603 examples/common/alhelpers.c
1604 examples/common/alhelpers.h)
1605 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1606 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1607 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1608 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1611 add_executable(altonegen examples/altonegen.c)
1612 target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1614 add_executable(alrecord examples/alrecord.c)
1615 target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1617 if(ALSOFT_INSTALL_EXAMPLES)
1618 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1621 message(STATUS "Building example programs")
1624 add_executable(alplay examples/alplay.c)
1625 target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1628 add_executable(alstream examples/alstream.c)
1629 target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1632 add_executable(alreverb examples/alreverb.c)
1633 target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1636 add_executable(almultireverb examples/almultireverb.c)
1637 target_link_libraries(almultireverb
1638 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1640 add_executable(allatency examples/allatency.c)
1641 target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1644 add_executable(alhrtf examples/alhrtf.c)
1645 target_link_libraries(alhrtf
1646 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1648 add_executable(alstreamcb examples/alstreamcb.cpp)
1649 target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1652 add_executable(alconvolve examples/alconvolve.c)
1653 target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1656 if(ALSOFT_INSTALL_EXAMPLES)
1657 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1661 message(STATUS "Building SndFile example programs")
1665 add_executable(alloopback examples/alloopback.c)
1666 target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1667 target_link_libraries(alloopback
1668 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1670 if(ALSOFT_INSTALL_EXAMPLES)
1671 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1674 message(STATUS "Building SDL example programs")
1679 if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1680 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1683 if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1684 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1687 if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1688 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1691 if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1692 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1695 if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1696 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1701 add_executable(alffplay examples/alffplay.cpp)
1702 target_include_directories(alffplay
1703 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1704 target_link_libraries(alffplay
1705 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1707 if(ALSOFT_INSTALL_EXAMPLES)
1708 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1710 message(STATUS "Building SDL+FFmpeg example programs")
1717 install(TARGETS ${EXTRA_INSTALLS}
1718 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1719 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
1720 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1721 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})