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 if(COMMAND CMAKE_POLICY)
34 cmake_policy(SET CMP0003 NEW)
35 cmake_policy(SET CMP0005 NEW)
37 cmake_policy(SET CMP0020 NEW)
40 cmake_policy(SET CMP0042 NEW)
43 cmake_policy(SET CMP0054 NEW)
46 cmake_policy(SET CMP0075 NEW)
49 cmake_policy(SET CMP0092 NEW)
52 cmake_policy(SET CMP0117 NEW)
54 endif(COMMAND CMAKE_POLICY)
58 if(NOT CMAKE_BUILD_TYPE)
59 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
60 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
63 if(NOT CMAKE_DEBUG_POSTFIX)
64 set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
65 "Library postfix for debug builds. Normally left blank."
69 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
71 include(CheckFunctionExists)
72 include(CheckLibraryExists)
73 include(CheckIncludeFile)
74 include(CheckIncludeFiles)
75 include(CheckSymbolExists)
76 include(CheckCCompilerFlag)
77 include(CheckCXXCompilerFlag)
78 include(CheckCSourceCompiles)
79 include(CheckCXXSourceCompiles)
80 include(CheckStructHasMember)
81 include(CMakePackageConfigHelpers)
82 include(GNUInstallDirs)
84 find_package(PkgConfig)
87 option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
89 option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
91 option(ALSOFT_UTILS "Build utility programs" ON)
92 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
94 option(ALSOFT_EXAMPLES "Build example programs" ON)
96 option(ALSOFT_INSTALL "Install main library" ON)
97 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
98 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
99 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
100 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
101 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
102 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
104 option(ALSOFT_EAX "Enable legacy EAX extensions" ${WIN32})
106 option(ALSOFT_SEARCH_INSTALL_DATADIR "Search the installation data directory" OFF)
107 if(ALSOFT_SEARCH_INSTALL_DATADIR)
108 set(ALSOFT_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
111 if(DEFINED SHARE_INSTALL_DIR)
112 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
113 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
116 if(DEFINED LIB_SUFFIX)
117 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
119 if(DEFINED ALSOFT_CONFIG)
120 message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
122 if(DEFINED ALSOFT_HRTF_DEFS)
123 message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
125 if(DEFINED ALSOFT_AMBDEC_PRESETS)
126 message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
130 set(CPP_DEFS ) # C pre-processor, not C++
137 set(CPP_DEFS ${CPP_DEFS} _WIN32 NOMINMAX)
139 set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
142 option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
144 option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
147 option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
151 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
152 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
153 set(INC_PATHS ${INC_PATHS} /usr/include)
154 set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
157 # When the library is built for static linking, apps should define
158 # AL_LIBTYPE_STATIC when including the AL headers.
163 set(LIB_MAJOR_VERSION "1")
164 set(LIB_MINOR_VERSION "22")
165 set(LIB_REVISION "2")
166 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
167 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
173 set(CMAKE_CXX_STANDARD 14)
174 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
176 # Prefer C11, but support C99 and C90 too.
177 set(CMAKE_C_STANDARD 11)
180 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
181 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
182 if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
183 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
184 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
185 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
186 if(NOT HAVE_POSIX_MEMALIGN_POSIX)
187 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
189 set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
192 unset(OLD_REQUIRED_FLAGS)
195 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
196 check_cxx_source_compiles("int *__restrict foo;
197 int main() { return 0; }" HAVE___RESTRICT)
199 set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
201 set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
204 # Some systems may need libatomic for atomic functions to work
205 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
206 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
207 check_cxx_source_compiles("#include <atomic>
208 std::atomic<int> foo{0};
209 int main() { return foo.fetch_add(2); }"
211 if(NOT HAVE_LIBATOMIC)
212 set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
214 set(EXTRA_LIBS atomic ${EXTRA_LIBS})
216 unset(OLD_REQUIRED_LIBRARIES)
219 # Include liblog for Android logging
220 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
222 set(EXTRA_LIBS log ${EXTRA_LIBS})
223 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
228 set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS)
229 check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
230 if(HAVE_PERMISSIVE_SWITCH)
231 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
233 set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4127 /wd4268 /wd4324 /wd5030)
236 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
238 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
241 message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
244 option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
245 if(FORCE_STATIC_VCRT)
247 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
248 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
249 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
250 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
251 if(${flag_var} MATCHES "/MD")
252 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
257 set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
259 $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
262 set(C_FLAGS ${C_FLAGS} -Werror)
265 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
267 foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
268 if(${flag_var} MATCHES "-DNDEBUG")
269 string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
273 check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
274 if(HAVE_FNO_MATH_ERRNO)
275 set(C_FLAGS ${C_FLAGS} -fno-math-errno)
278 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
279 if(ALSOFT_STATIC_LIBGCC)
280 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
281 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
282 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
283 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
284 unset(OLD_REQUIRED_LIBRARIES)
286 if(NOT HAVE_STATIC_LIBGCC_SWITCH)
287 message(FATAL_ERROR "Cannot static link libgcc")
289 set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
292 option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
293 if(ALSOFT_STATIC_STDCXX)
294 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
295 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
296 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
297 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
298 unset(OLD_REQUIRED_LIBRARIES)
300 if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
301 message(FATAL_ERROR "Cannot static link libstdc++")
303 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
307 option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
308 if(ALSOFT_STATIC_WINPTHREAD)
309 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
310 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
311 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
312 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
313 unset(OLD_REQUIRED_LIBRARIES)
315 if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
316 message(FATAL_ERROR "Cannot static link libwinpthread")
318 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
323 # Set visibility/export options if available
325 if(NOT LIBTYPE STREQUAL "STATIC")
326 set(EXPORT_DECL "__declspec(dllexport)")
329 set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
330 # Yes GCC, really don't accept visibility modes you don't support
331 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
333 check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
334 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
335 if(HAVE_GCC_PROTECTED_VISIBILITY)
336 if(NOT LIBTYPE STREQUAL "STATIC")
337 set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
340 check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
341 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
342 if(HAVE_GCC_DEFAULT_VISIBILITY)
343 if(NOT LIBTYPE STREQUAL "STATIC")
344 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
349 if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
350 check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
351 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
352 set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
356 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
363 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
364 # Yes GCC, really don't accept command line options you don't support
365 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
366 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
367 if(HAVE_MSSE2_SWITCH)
368 set(SSE2_SWITCH "-msse2")
370 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
371 unset(OLD_REQUIRED_FLAGS)
374 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
375 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
376 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
377 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
378 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
386 # Check for SSE support
387 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
389 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
390 if(ALSOFT_CPUEXT_SSE)
394 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
395 message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
398 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
400 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
401 if(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
405 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
406 message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
409 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
411 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
412 if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
416 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
417 message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
420 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
422 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
423 if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
427 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
428 message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
431 # Check for ARM Neon support
432 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
434 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
435 if(ALSOFT_CPUEXT_NEON)
436 check_c_source_compiles("#include <arm_neon.h>
439 int32x4_t ret4 = vdupq_n_s32(0);
440 return vgetq_lane_s32(ret4, 0);
441 }" HAVE_NEON_INTRINSICS)
442 if(HAVE_NEON_INTRINSICS)
447 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
448 message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
454 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
455 option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
456 if(ALSOFT_ENABLE_SSE2_CODEGEN)
458 check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
460 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
461 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
465 check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
466 if(HAVE_MFPMATH_SSE_2)
467 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
468 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
471 # SSE depends on a 16-byte aligned stack, and by default, GCC
472 # assumes the stack is suitably aligned. Older Linux code or other
473 # OSs don't guarantee this on 32-bit, so externally-callable
474 # functions need to ensure an aligned stack.
475 set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
481 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
482 foreach(flag_var ${SSE_FLAGS})
483 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
486 check_c_source_compiles("#include <emmintrin.h>
487 int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
489 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
493 check_include_file(malloc.h HAVE_MALLOC_H)
494 check_include_file(cpuid.h HAVE_CPUID_H)
495 check_include_file(intrin.h HAVE_INTRIN_H)
496 check_include_file(guiddef.h HAVE_GUIDDEF_H)
497 if(NOT HAVE_GUIDDEF_H)
498 check_include_file(initguid.h HAVE_INITGUID_H)
501 # Some systems need libm for some math functions to work
503 check_library_exists(m pow "" HAVE_LIBM)
505 set(MATH_LIB ${MATH_LIB} m)
506 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
509 # Some systems need to link with -lrt for clock_gettime as used by the common
512 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
517 # Check for the dlopen API (for dynamicly loading backend libs)
519 check_include_file(dlfcn.h HAVE_DLFCN_H)
520 check_library_exists(dl dlopen "" HAVE_LIBDL)
522 set(EXTRA_LIBS dl ${EXTRA_LIBS})
523 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
527 # Check for a cpuid intrinsic
529 check_c_source_compiles("#include <cpuid.h>
532 unsigned int eax, ebx, ecx, edx;
533 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
534 }" HAVE_GCC_GET_CPUID)
537 check_c_source_compiles("#include <intrin.h>
543 }" HAVE_CPUID_INTRINSIC)
546 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
547 check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
548 check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
551 # We need pthreads outside of Windows, for semaphores. It's also used to
552 # set the priority and name of threads, when possible.
553 check_include_file(pthread.h HAVE_PTHREAD_H)
554 if(NOT HAVE_PTHREAD_H)
555 message(FATAL_ERROR "PThreads is required for non-Windows builds!")
558 check_c_compiler_flag(-pthread HAVE_PTHREAD)
560 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
561 set(C_FLAGS ${C_FLAGS} -pthread)
562 set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
565 check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
567 # Some systems need pthread_np.h to get pthread_setname_np
568 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
569 if(HAVE_PTHREAD_NP_H)
570 check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
571 if(NOT HAVE_PTHREAD_SETNAME_NP)
572 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
575 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
576 if(NOT HAVE_PTHREAD_SETNAME_NP)
577 check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
582 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
585 # Common sources used by both the OpenAL implementation library, the OpenAL
586 # router, and certain tools and examples.
607 common/intrusive_ptr.h
609 common/phase_shifter.h
610 common/polyphase_resampler.cpp
611 common/polyphase_resampler.h
613 common/ringbuffer.cpp
622 # Core library routines
634 core/bsinc_tables.cpp
637 core/buffer_storage.cpp
638 core/buffer_storage.h
654 core/filters/biquad.h
655 core/filters/biquad.cpp
658 core/filters/splitter.cpp
659 core/filters/splitter.h
664 core/front_stablizer.h
675 core/resampler_limits.h
685 option(ALSOFT_REQUIRE_RTKIT "Require RTKit/D-Bus support" FALSE)
686 find_package(DBus1 QUIET)
687 if(NOT DBus1_FOUND AND PkgConfig_FOUND)
688 pkg_check_modules(DBUS dbus-1)
690 if(DBus1_FOUND OR DBUS_FOUND)
691 option(ALSOFT_RTKIT "Enable RTKit support" ON)
694 set(CORE_OBJS ${CORE_OBJS} core/dbus_wrap.cpp core/dbus_wrap.h
695 core/rtkit.cpp core/rtkit.h)
697 set(INC_PATHS ${INC_PATHS} ${DBUS_INCLUDE_DIRS})
698 set(CPP_DEFS ${CPP_DEFS} ${DBUS_CFLAGS_OTHER})
700 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBUS_LINK_LIBRARIES})
703 set(INC_PATHS ${INC_PATHS} ${DBus1_INCLUDE_DIRS})
704 set(CPP_DEFS ${CPP_DEFS} ${DBus1_DEFINITIONS})
706 set(EXTRA_LIBS ${EXTRA_LIBS} ${DBus1_LIBRARIES})
711 if(NOT DBus1_INCLUDE_DIRS)
712 set(MISSING_VARS "${MISSING_VARS} DBus1_INCLUDE_DIRS")
714 if(NOT DBus1_LIBRARIES)
715 set(MISSING_VARS "${MISSING_VARS} DBus1_LIBRARIES")
717 message(STATUS "Could NOT find DBus1 (missing:${MISSING_VARS})")
721 if(ALSOFT_REQUIRE_RTKIT AND NOT HAVE_RTKIT)
722 message(FATAL_ERROR "Failed to enabled required RTKit support")
725 # Default mixers, always available
726 set(CORE_OBJS ${CORE_OBJS}
728 core/mixer/hrtfbase.h
729 core/mixer/hrtfdefs.h
730 core/mixer/mixer_c.cpp)
732 # AL and related routines
740 al/effects/autowah.cpp
741 al/effects/chorus.cpp
742 al/effects/compressor.cpp
743 al/effects/convolution.cpp
744 al/effects/dedicated.cpp
745 al/effects/distortion.cpp
747 al/effects/effects.cpp
749 al/effects/equalizer.cpp
750 al/effects/fshifter.cpp
751 al/effects/modulator.cpp
753 al/effects/pshifter.cpp
754 al/effects/reverb.cpp
755 al/effects/vmorpher.cpp
768 # ALC and related routines
780 alc/effects/autowah.cpp
781 alc/effects/chorus.cpp
782 alc/effects/compressor.cpp
783 alc/effects/convolution.cpp
784 alc/effects/dedicated.cpp
785 alc/effects/distortion.cpp
787 alc/effects/equalizer.cpp
788 alc/effects/fshifter.cpp
789 alc/effects/modulator.cpp
791 alc/effects/pshifter.cpp
792 alc/effects/reverb.cpp
793 alc/effects/vmorpher.cpp
807 al/eax/fx_slot_index.cpp
808 al/eax/fx_slot_index.h
819 # Include SIMD mixers
820 set(CPU_EXTS "Default")
822 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp)
823 set(CPU_EXTS "${CPU_EXTS}, SSE")
826 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse2.cpp)
827 set(CPU_EXTS "${CPU_EXTS}, SSE2")
830 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
831 set(CPU_EXTS "${CPU_EXTS}, SSE3")
834 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
835 set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
838 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp)
839 set(CPU_EXTS "${CPU_EXTS}, Neon")
851 set(HAVE_PORTAUDIO 0)
852 set(HAVE_PULSEAUDIO 0)
853 set(HAVE_COREAUDIO 0)
859 if(WIN32 OR HAVE_DLFCN_H)
861 macro(ADD_BACKEND_LIBS _LIBS)
864 set(IS_LINKED " (linked)")
865 macro(ADD_BACKEND_LIBS _LIBS)
866 set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
871 set(ALC_OBJS ${ALC_OBJS}
872 alc/backends/base.cpp
874 # Default backends, always available
875 alc/backends/loopback.cpp
876 alc/backends/loopback.h
877 alc/backends/null.cpp
882 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
885 option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
886 if(ALSOFT_BACKEND_ALSA)
888 set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
889 set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
890 add_backend_libs(${ALSA_LIBRARIES})
891 set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
894 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
895 message(FATAL_ERROR "Failed to enabled required ALSA backend")
899 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
902 option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
903 if(ALSOFT_BACKEND_OSS)
905 set(BACKENDS "${BACKENDS} OSS,")
906 set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
908 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
910 set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
913 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
914 message(FATAL_ERROR "Failed to enabled required OSS backend")
917 # Check PipeWire backend
918 option(ALSOFT_REQUIRE_PIPEWIRE "Require PipeWire backend" OFF)
920 pkg_check_modules(PIPEWIRE libpipewire-0.3>=0.3.23)
922 option(ALSOFT_BACKEND_PIPEWIRE "Enable PipeWire backend" ON)
923 if(ALSOFT_BACKEND_PIPEWIRE)
925 set(BACKENDS "${BACKENDS} PipeWire${IS_LINKED},")
926 set(ALC_OBJS ${ALC_OBJS} alc/backends/pipewire.cpp alc/backends/pipewire.h)
927 add_backend_libs(${PIPEWIRE_LIBRARIES})
928 set(INC_PATHS ${INC_PATHS} ${PIPEWIRE_INCLUDE_DIRS})
932 if(ALSOFT_REQUIRE_PIPEWIRE AND NOT HAVE_PIPEWIRE)
933 message(FATAL_ERROR "Failed to enabled required PipeWire backend")
936 # Check Solaris backend
937 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
938 find_package(AudioIO)
940 option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
941 if(ALSOFT_BACKEND_SOLARIS)
943 set(BACKENDS "${BACKENDS} Solaris,")
944 set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
945 set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
948 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
949 message(FATAL_ERROR "Failed to enabled required Solaris backend")
952 # Check SndIO backend
953 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
954 find_package(SoundIO)
956 option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
957 if(ALSOFT_BACKEND_SNDIO)
959 set(BACKENDS "${BACKENDS} SndIO (linked),")
960 set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
961 set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
962 set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
965 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
966 message(FATAL_ERROR "Failed to enabled required SndIO backend")
969 # Check Windows-only backends
970 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
971 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
972 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
974 # Check MMSystem backend
975 option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
976 if(ALSOFT_BACKEND_WINMM)
978 set(BACKENDS "${BACKENDS} WinMM,")
979 set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
980 # There doesn't seem to be good way to search for winmm.lib for MSVC.
981 # find_library doesn't find it without being told to look in a specific
982 # place in the WindowsSDK, but it links anyway. If there ends up being
983 # Windows targets without this, another means to detect it is needed.
984 set(EXTRA_LIBS winmm ${EXTRA_LIBS})
987 # Check DSound backend
988 check_include_file(dsound.h HAVE_DSOUND_H)
990 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
991 PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
992 DOC "The DirectSound include directory")
994 if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
995 option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
996 if(ALSOFT_BACKEND_DSOUND)
998 set(BACKENDS "${BACKENDS} DirectSound,")
999 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
1001 if(NOT HAVE_DSOUND_H)
1002 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
1007 # Check for WASAPI backend
1008 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1009 if(HAVE_MMDEVICEAPI_H)
1010 option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1011 if(ALSOFT_BACKEND_WASAPI)
1013 set(BACKENDS "${BACKENDS} WASAPI,")
1014 set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
1018 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1019 message(FATAL_ERROR "Failed to enabled required WinMM backend")
1021 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1022 message(FATAL_ERROR "Failed to enabled required DSound backend")
1024 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1025 message(FATAL_ERROR "Failed to enabled required WASAPI backend")
1028 # Check PortAudio backend
1029 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1030 find_package(PortAudio)
1032 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1033 if(ALSOFT_BACKEND_PORTAUDIO)
1034 set(HAVE_PORTAUDIO 1)
1035 set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
1036 set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
1037 add_backend_libs(${PORTAUDIO_LIBRARIES})
1038 set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1041 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1042 message(FATAL_ERROR "Failed to enabled required PortAudio backend")
1045 # Check PulseAudio backend
1046 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1047 find_package(PulseAudio)
1048 if(PULSEAUDIO_FOUND)
1049 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1050 if(ALSOFT_BACKEND_PULSEAUDIO)
1051 set(HAVE_PULSEAUDIO 1)
1052 set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
1053 set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
1054 add_backend_libs(${PULSEAUDIO_LIBRARIES})
1055 set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1058 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1059 message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1062 # Check JACK backend
1063 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1066 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1067 if(ALSOFT_BACKEND_JACK)
1069 set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
1070 set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1071 add_backend_libs(${JACK_LIBRARIES})
1072 set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1075 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1076 message(FATAL_ERROR "Failed to enabled required JACK backend")
1079 # Check CoreAudio backend
1080 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1081 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
1082 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
1083 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1084 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1085 if(ALSOFT_BACKEND_COREAUDIO)
1086 set(HAVE_COREAUDIO 1)
1087 set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1088 set(BACKENDS "${BACKENDS} CoreAudio,")
1089 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
1090 find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1091 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
1093 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1094 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1097 # Some versions of OSX may need the AudioToolbox framework. Add it if
1099 find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1100 if(AUDIOTOOLBOX_LIBRARY)
1101 set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1104 set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1107 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1108 message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1111 # Check for OpenSL (Android) backend
1112 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1113 find_package(OpenSL)
1115 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1116 if(ALSOFT_BACKEND_OPENSL)
1118 set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1119 set(BACKENDS "${BACKENDS} OpenSL,")
1120 set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1123 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1124 message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1127 # Check for Oboe (Android) backend
1130 set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1132 # Force Oboe to build with hidden symbols. Don't want to be exporting
1134 set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1135 check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1136 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1137 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1139 add_subdirectory(${OBOE_SOURCE} ./oboe)
1140 set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1141 unset(OLD_CXX_FLAGS)
1143 set(OBOE_TARGET oboe)
1145 find_package(oboe CONFIG)
1146 if(NOT TARGET oboe::oboe)
1149 if(TARGET oboe::oboe)
1150 set(OBOE_TARGET "oboe::oboe")
1155 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1157 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1158 if(ALSOFT_BACKEND_OBOE)
1160 set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1161 set(BACKENDS "${BACKENDS} Oboe,")
1162 set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1165 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1166 message(FATAL_ERROR "Failed to enabled required Oboe backend")
1169 # Check for SDL2 backend
1170 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1173 # Off by default, since it adds a runtime dependency
1174 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1175 if(ALSOFT_BACKEND_SDL2)
1177 set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1178 set(BACKENDS "${BACKENDS} SDL2,")
1179 set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1180 set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1183 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1184 message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1187 # Optionally enable the Wave Writer backend
1188 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1189 if(ALSOFT_BACKEND_WAVE)
1191 set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1192 set(BACKENDS "${BACKENDS} WaveFile,")
1195 # This is always available
1196 set(BACKENDS "${BACKENDS} Null")
1200 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1201 # Get the current working branch and its latest abbreviated commit hash
1202 add_custom_target(build_version
1203 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1204 -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1205 -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1206 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1210 set(GIT_BRANCH "UNKNOWN")
1211 set(GIT_COMMIT_HASH "unknown")
1213 "${OpenAL_SOURCE_DIR}/version.h.in"
1214 "${OpenAL_BINARY_DIR}/version.h")
1218 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1219 if(ALSOFT_EMBED_HRTF_DATA)
1220 macro(make_hrtf_header FILENAME VARNAME)
1221 set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1222 set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1224 add_custom_command(OUTPUT "${outfile}"
1225 COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1226 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1227 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1228 DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1231 set(ALC_OBJS ${ALC_OBJS} "${outfile}")
1234 make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1239 find_package(MySOFA)
1240 if(NOT ALSOFT_NO_CONFIG_UTIL)
1241 find_package(Qt5Widgets QUIET)
1242 if(NOT Qt5Widgets_FOUND)
1243 message(STATUS "Could NOT find Qt5Widgets")
1247 if(ALSOFT_UTILS OR ALSOFT_EXAMPLES)
1248 find_package(SndFile)
1251 find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1256 set(LIBNAME "openal")
1258 set(LIBNAME "OpenAL32")
1261 # Needed for openal.pc.in
1262 set(prefix ${CMAKE_INSTALL_PREFIX})
1263 set(exec_prefix "\${prefix}")
1264 set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
1265 set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
1266 set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
1267 set(PACKAGE_VERSION "${LIB_VERSION}")
1268 set(PKG_CONFIG_CFLAGS )
1269 set(PKG_CONFIG_PRIVATE_LIBS )
1270 if(LIBTYPE STREQUAL "STATIC")
1271 set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1272 foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1273 # If this is already a linker flag, or is a full path+file, add it
1274 # as-is. Otherwise, it's a name intended to be dressed as -lname.
1275 if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1276 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1278 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1285 "${OpenAL_SOURCE_DIR}/config.h.in"
1286 "${OpenAL_BINARY_DIR}/config.h")
1288 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1289 "${OpenAL_BINARY_DIR}/openal.pc"
1293 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1294 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1295 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1296 target_compile_options(common PRIVATE ${C_FLAGS})
1297 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1301 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1303 # Build main library
1304 if(LIBTYPE STREQUAL "STATIC")
1305 add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1306 target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1307 target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1310 # This option is for static linking OpenAL Soft into another project
1311 # that already defines the IDs. It is up to that project to ensure all
1312 # required IDs are defined.
1313 option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1314 if(ALSOFT_NO_UID_DEFS)
1315 target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1319 set(RC_CONFIG resources/openal32.rc)
1320 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1321 add_library(OpenAL SHARED
1328 target_compile_definitions(OpenAL
1329 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}"
1330 "AL_API=${EXPORT_DECL}" ${CPP_DEFS})
1331 target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1332 target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1333 target_include_directories(OpenAL
1335 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1336 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1338 ${OpenAL_SOURCE_DIR}/common
1339 ${OpenAL_BINARY_DIR}
1341 set_target_properties(OpenAL PROPERTIES PREFIX "")
1342 set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1343 if(TARGET build_version)
1344 add_dependencies(OpenAL build_version)
1348 set(LIBNAME "soft_oal")
1349 set(IMPL_TARGET soft_oal)
1350 set(RC_CONFIG resources/soft_oal.rc)
1353 # !important: for osx framework public header works, the headers must be in
1355 set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1356 add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1357 ${TARGET_PUBLIC_HEADERS})
1359 set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1361 target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1363 if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1364 # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1365 set(LIBNAME "soft_oal")
1367 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1369 OUTPUT_VARIABLE BUNDLE_VERSION
1370 OUTPUT_STRIP_TRAILING_WHITESPACE)
1372 set(BUNDLE_VERSION 1)
1375 # Build: Fix rpath in iOS shared libraries
1376 # If this flag is not set, the final dylib binary ld path will be
1377 # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1378 # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1379 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1380 set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1383 set_target_properties(${IMPL_TARGET} PROPERTIES
1386 MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1387 MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1388 MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1389 MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1390 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1391 XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1392 XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1393 PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1398 target_include_directories(${IMPL_TARGET}
1400 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1402 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include/AL>
1403 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
1404 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/AL>
1407 ${OpenAL_BINARY_DIR}
1408 ${OpenAL_SOURCE_DIR}
1409 ${OpenAL_SOURCE_DIR}/common
1412 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1413 VERSION ${LIB_VERSION}
1414 SOVERSION ${LIB_MAJOR_VERSION}
1416 target_compile_definitions(${IMPL_TARGET}
1417 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES "ALC_API=${EXPORT_DECL}" "AL_API=${EXPORT_DECL}"
1419 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1421 if(TARGET build_version)
1422 add_dependencies(${IMPL_TARGET} build_version)
1425 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1426 find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1427 if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1429 if(NOT SED_EXECUTABLE)
1430 message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1432 if(NOT CMAKE_DLLTOOL)
1433 message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1436 set_property(TARGET OpenAL APPEND_STRING PROPERTY
1437 LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1438 add_custom_command(TARGET OpenAL POST_BUILD
1439 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1440 COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1441 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1449 message(STATUS "Building DLL router")
1453 message(STATUS "Building OpenAL with support for the following backends:")
1454 message(STATUS " ${BACKENDS}")
1456 message(STATUS "Building with support for CPU extensions:")
1457 message(STATUS " ${CPU_EXTS}")
1460 message(STATUS "Building with SSE${FPMATH_SET} codegen")
1465 message(STATUS "Building with legacy EAX extension support")
1469 if(ALSOFT_EMBED_HRTF_DATA)
1470 message(STATUS "Embedding HRTF datasets")
1474 # An alias for sub-project builds
1475 add_library(OpenAL::OpenAL ALIAS OpenAL)
1477 # Install main library
1479 configure_package_config_file(OpenALConfig.cmake.in OpenALConfig.cmake
1480 INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL)
1481 install(TARGETS OpenAL EXPORT OpenAL
1482 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1483 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1484 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1485 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1486 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1487 export(TARGETS OpenAL
1489 FILE OpenALTargets.cmake)
1490 install(EXPORT OpenAL
1491 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1493 FILE OpenALTargets.cmake)
1494 install(DIRECTORY include/AL
1495 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1496 install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1497 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1498 install(FILES "${OpenAL_BINARY_DIR}/OpenALConfig.cmake"
1499 DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL")
1501 install(TARGETS soft_oal
1502 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1504 message(STATUS "Installing library and headers")
1506 message(STATUS "NOT installing library and headers")
1509 if(ALSOFT_INSTALL_CONFIG)
1510 install(FILES alsoftrc.sample
1511 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1512 message(STATUS "Installing sample configuration")
1515 if(ALSOFT_INSTALL_HRTF_DATA)
1516 install(DIRECTORY hrtf
1517 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1518 message(STATUS "Installing HRTF data files")
1521 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1522 install(DIRECTORY presets
1523 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1524 message(STATUS "Installing AmbDec presets")
1530 set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1532 set(EXTRA_INSTALLS )
1534 add_executable(openal-info utils/openal-info.c)
1535 target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1536 target_compile_options(openal-info PRIVATE ${C_FLAGS})
1537 target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1538 if(ALSOFT_INSTALL_EXAMPLES)
1539 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1543 add_executable(uhjdecoder utils/uhjdecoder.cpp)
1544 target_compile_definitions(uhjdecoder PRIVATE ${CPP_DEFS})
1545 target_include_directories(uhjdecoder
1546 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1547 target_compile_options(uhjdecoder PRIVATE ${C_FLAGS})
1548 target_link_libraries(uhjdecoder PUBLIC common
1549 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1551 add_executable(uhjencoder utils/uhjencoder.cpp)
1552 target_compile_definitions(uhjencoder PRIVATE ${CPP_DEFS})
1553 target_include_directories(uhjencoder
1554 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/common)
1555 target_compile_options(uhjencoder PRIVATE ${C_FLAGS})
1556 target_link_libraries(uhjencoder PUBLIC common
1557 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ${UNICODE_FLAG})
1561 set(SOFA_SUPPORT_SRCS
1562 utils/sofa-support.cpp
1563 utils/sofa-support.h)
1564 add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1565 target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1566 target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1567 target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1568 target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1571 utils/makemhr/loaddef.cpp
1572 utils/makemhr/loaddef.h
1573 utils/makemhr/loadsofa.cpp
1574 utils/makemhr/loadsofa.h
1575 utils/makemhr/makemhr.cpp
1576 utils/makemhr/makemhr.h)
1578 set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1580 add_executable(makemhr ${MAKEMHR_SRCS})
1581 target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1582 target_include_directories(makemhr
1583 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1584 target_compile_options(makemhr PRIVATE ${C_FLAGS})
1585 target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1586 if(ALSOFT_INSTALL_EXAMPLES)
1587 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1590 set(SOFAINFO_SRCS utils/sofa-info.cpp)
1591 add_executable(sofa-info ${SOFAINFO_SRCS})
1592 target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1593 target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1594 target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1595 target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1597 message(STATUS "Building utility programs")
1599 if(NOT ALSOFT_NO_CONFIG_UTIL)
1600 add_subdirectory(utils/alsoft-config)
1606 # Add a static library with common functions used by multiple example targets
1607 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1608 examples/common/alhelpers.c
1609 examples/common/alhelpers.h)
1610 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1611 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1612 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1613 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1616 add_executable(altonegen examples/altonegen.c)
1617 target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1619 add_executable(alrecord examples/alrecord.c)
1620 target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1622 if(ALSOFT_INSTALL_EXAMPLES)
1623 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1626 message(STATUS "Building example programs")
1629 add_executable(alplay examples/alplay.c)
1630 target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1633 add_executable(alstream examples/alstream.c)
1634 target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1637 add_executable(alreverb examples/alreverb.c)
1638 target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1641 add_executable(almultireverb examples/almultireverb.c)
1642 target_link_libraries(almultireverb
1643 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1645 add_executable(allatency examples/allatency.c)
1646 target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1649 add_executable(alhrtf examples/alhrtf.c)
1650 target_link_libraries(alhrtf
1651 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1653 add_executable(alstreamcb examples/alstreamcb.cpp)
1654 target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1657 add_executable(alconvolve examples/alconvolve.c)
1658 target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1661 if(ALSOFT_INSTALL_EXAMPLES)
1662 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1666 message(STATUS "Building SndFile example programs")
1670 add_executable(alloopback examples/alloopback.c)
1671 target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1672 target_link_libraries(alloopback
1673 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1675 if(ALSOFT_INSTALL_EXAMPLES)
1676 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1679 message(STATUS "Building SDL example programs")
1684 if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1685 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1688 if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1689 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1692 if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1693 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1696 if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1697 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1700 if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1701 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1706 add_executable(alffplay examples/alffplay.cpp)
1707 target_include_directories(alffplay
1708 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1709 target_link_libraries(alffplay
1710 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1712 if(ALSOFT_INSTALL_EXAMPLES)
1713 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1715 message(STATUS "Building SDL+FFmpeg example programs")
1722 install(TARGETS ${EXTRA_INSTALLS}
1723 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1724 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
1725 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1726 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})