1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
5 # The workaround for try_compile failing with code signing
6 # since cmake-3.18.2, not required
7 set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
8 "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED"
9 "CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED")
10 set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
11 set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
13 # Fix compile failure with armv7 deployment target >= 11.0, xcode clang will
15 # error: invalid iOS deployment version '--target=armv7-apple-ios13.6',
16 # iOS 10 is the maximum deployment target for 32-bit targets
17 # If CMAKE_OSX_DEPLOYMENT_TARGET is not defined, cmake will choose latest
19 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
20 if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ".*armv7.*")
21 if(NOT DEFINED CMAKE_OSX_DEPLOYMENT_TARGET
22 OR NOT CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "11.0")
23 message(STATUS "Forcing iOS deployment target to 10.0 for armv7")
24 set(CMAKE_OSX_DEPLOYMENT_TARGET "10.0" CACHE STRING "Minimum OS X deployment version"
32 if(COMMAND CMAKE_POLICY)
33 cmake_policy(SET CMP0003 NEW)
34 cmake_policy(SET CMP0005 NEW)
36 cmake_policy(SET CMP0020 NEW)
39 cmake_policy(SET CMP0042 NEW)
42 cmake_policy(SET CMP0054 NEW)
45 cmake_policy(SET CMP0075 NEW)
47 endif(COMMAND CMAKE_POLICY)
49 if(NOT CMAKE_BUILD_TYPE)
50 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
51 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
54 if(NOT CMAKE_DEBUG_POSTFIX)
55 set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
56 "Library postfix for debug builds. Normally left blank."
60 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
62 include(CheckFunctionExists)
63 include(CheckLibraryExists)
64 include(CheckIncludeFile)
65 include(CheckIncludeFiles)
66 include(CheckSymbolExists)
67 include(CheckCCompilerFlag)
68 include(CheckCXXCompilerFlag)
69 include(CheckCSourceCompiles)
70 include(CheckCXXSourceCompiles)
71 include(CheckStructHasMember)
72 include(GNUInstallDirs)
75 option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
77 option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
79 option(ALSOFT_UTILS "Build utility programs" ON)
80 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
82 option(ALSOFT_EXAMPLES "Build example programs" ON)
84 option(ALSOFT_INSTALL "Install main library" ON)
85 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
86 option(ALSOFT_INSTALL_HRTF_DATA "Install HRTF data files" ON)
87 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
88 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
89 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
90 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
92 if(DEFINED SHARE_INSTALL_DIR)
93 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
94 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
97 if(DEFINED LIB_SUFFIX)
98 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
100 if(DEFINED ALSOFT_CONFIG)
101 message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
103 if(DEFINED ALSOFT_HRTF_DEFS)
104 message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
106 if(DEFINED ALSOFT_AMBDEC_PRESETS)
107 message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
111 set(CPP_DEFS ) # C pre-processor, not C++
118 set(CPP_DEFS ${CPP_DEFS} _WIN32)
120 set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
123 option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
125 option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
128 option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
132 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
133 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
134 set(INC_PATHS ${INC_PATHS} /usr/include)
135 set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
138 # When the library is built for static linking, apps should define
139 # AL_LIBTYPE_STATIC when including the AL headers.
144 set(LIB_MAJOR_VERSION "1")
145 set(LIB_MINOR_VERSION "21")
146 set(LIB_REVISION "0")
147 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
148 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
154 set(CMAKE_CXX_STANDARD 14)
155 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
157 # Prefer C11, but support C99 and C90 too.
158 set(CMAKE_C_STANDARD 11)
161 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
162 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
163 if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
164 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
165 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
166 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
167 if(NOT HAVE_POSIX_MEMALIGN_POSIX)
168 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
170 set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
173 unset(OLD_REQUIRED_FLAGS)
176 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
177 check_cxx_source_compiles("int *__restrict foo;
178 int main() { return 0; }" HAVE___RESTRICT)
180 set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
182 set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
185 # Some systems may need libatomic for atomic functions to work
186 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
187 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
188 check_cxx_source_compiles("#include <atomic>
189 std::atomic<int> foo{0};
190 int main() { return foo.fetch_add(2); }"
192 if(NOT HAVE_LIBATOMIC)
193 set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
195 set(EXTRA_LIBS atomic ${EXTRA_LIBS})
197 unset(OLD_REQUIRED_LIBRARIES)
199 # Include liblog for Android logging
200 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
202 set(EXTRA_LIBS log ${EXTRA_LIBS})
203 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
207 set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
208 check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
209 if(HAVE_PERMISSIVE_SWITCH)
210 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
212 set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324 /wd5030)
213 # Remove /W3, which is added by default, since we set /W4. Some build
214 # generators with MSVC complain about both /W3 and /W4 being specified.
215 foreach(flag_var CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
216 if(${flag_var} MATCHES "/W3")
217 string(REGEX REPLACE "/W3" "" ${flag_var} "${${flag_var}}")
222 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
224 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
227 message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
230 option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
231 if(FORCE_STATIC_VCRT)
233 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
234 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
235 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
236 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
237 if(${flag_var} MATCHES "/MD")
238 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
243 set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
245 $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
248 set(C_FLAGS ${C_FLAGS} -Werror)
251 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
253 foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
254 if(${flag_var} MATCHES "-DNDEBUG")
255 string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
259 check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
260 if(HAVE_FNO_MATH_ERRNO)
261 set(C_FLAGS ${C_FLAGS} -fno-math-errno)
264 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
265 if(ALSOFT_STATIC_LIBGCC)
266 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
267 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
268 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
269 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
270 unset(OLD_REQUIRED_LIBRARIES)
272 if(NOT HAVE_STATIC_LIBGCC_SWITCH)
273 message(FATAL_ERROR "Cannot static link libgcc")
275 set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
278 option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
279 if(ALSOFT_STATIC_STDCXX)
280 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
281 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
282 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
283 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
284 unset(OLD_REQUIRED_LIBRARIES)
286 if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
287 message(FATAL_ERROR "Cannot static link libstdc++")
289 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
293 option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
294 if(ALSOFT_STATIC_WINPTHREAD)
295 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
296 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
297 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
298 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
299 unset(OLD_REQUIRED_LIBRARIES)
301 if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
302 message(FATAL_ERROR "Cannot static link libwinpthread")
304 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
309 # Set visibility/export options if available
311 if(NOT LIBTYPE STREQUAL "STATIC")
312 set(EXPORT_DECL "__declspec(dllexport)")
315 set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
316 # Yes GCC, really don't accept visibility modes you don't support
317 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
319 check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
320 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
321 if(HAVE_GCC_PROTECTED_VISIBILITY)
322 if(NOT LIBTYPE STREQUAL "STATIC")
323 set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
326 check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
327 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
328 if(HAVE_GCC_DEFAULT_VISIBILITY)
329 if(NOT LIBTYPE STREQUAL "STATIC")
330 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
335 if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
336 check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
337 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
338 set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
342 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
348 set(SSE4_1_SWITCH "")
349 set(FPU_NEON_SWITCH "")
351 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
353 # Yes GCC, really don't accept command line options you don't support
354 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
356 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
357 if(HAVE_MSSE2_SWITCH)
358 set(SSE2_SWITCH "-msse2")
359 check_c_compiler_flag(-msse3 HAVE_MSSE3_SWITCH)
360 if(HAVE_MSSE3_SWITCH)
361 set(SSE3_SWITCH "-msse3")
362 check_c_compiler_flag(-msse4.1 HAVE_MSSE4_1_SWITCH)
363 if(HAVE_MSSE4_1_SWITCH)
364 set(SSE4_1_SWITCH "-msse4.1")
368 check_c_compiler_flag(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
369 if(HAVE_MFPU_NEON_SWITCH)
370 set(FPU_NEON_SWITCH "-mfpu=neon")
372 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
373 unset(OLD_REQUIRED_FLAGS)
375 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H ${SSE2_SWITCH})
376 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${SSE2_SWITCH})
377 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H ${SSE3_SWITCH})
378 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${SSE4_1_SWITCH})
379 check_include_file(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
383 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC))
384 option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
385 if(ALSOFT_ENABLE_SSE2_CODEGEN)
387 check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
388 if(HAVE_MFPMATH_SSE_2)
389 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
390 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
393 # SSE depends on a 16-byte aligned stack, and by default, GCC
394 # assumes the stack is suitably aligned. Older Linux code or other
395 # OSs don't guarantee this on 32-bit, so externally-callable
396 # functions need to ensure an aligned stack.
397 set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
399 check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
401 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
402 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
410 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
411 foreach(flag_var ${SSE_FLAGS})
412 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
415 check_c_source_compiles("#include <emmintrin.h>
416 int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
418 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
422 check_include_file(malloc.h HAVE_MALLOC_H)
423 check_include_file(cpuid.h HAVE_CPUID_H)
424 check_include_file(intrin.h HAVE_INTRIN_H)
425 check_include_file(guiddef.h HAVE_GUIDDEF_H)
426 if(NOT HAVE_GUIDDEF_H)
427 check_include_file(initguid.h HAVE_INITGUID_H)
430 # Some systems need libm for some math functions to work
432 check_library_exists(m pow "" HAVE_LIBM)
434 set(MATH_LIB ${MATH_LIB} m)
435 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
438 # Some systems need to link with -lrt for clock_gettime as used by the common
441 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
446 # Check for the dlopen API (for dynamicly loading backend libs)
448 check_include_file(dlfcn.h HAVE_DLFCN_H)
449 check_library_exists(dl dlopen "" HAVE_LIBDL)
451 set(EXTRA_LIBS dl ${EXTRA_LIBS})
452 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
456 # Check for a cpuid intrinsic
458 check_c_source_compiles("#include <cpuid.h>
461 unsigned int eax, ebx, ecx, edx;
462 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
463 }" HAVE_GCC_GET_CPUID)
466 check_c_source_compiles("#include <intrin.h>
472 }" HAVE_CPUID_INTRINSIC)
475 check_cxx_source_compiles("#include <cstdlib>
478 void *ptr{std::aligned_alloc(alignof(int), sizeof(int))};
481 }" HAVE_STD_ALIGNED_ALLOC)
482 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
483 check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
484 check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
487 # We need pthreads outside of Windows, for semaphores. It's also used to
488 # set the priority and name of threads, when possible.
489 check_include_file(pthread.h HAVE_PTHREAD_H)
490 if(NOT HAVE_PTHREAD_H)
491 message(FATAL_ERROR "PThreads is required for non-Windows builds!")
494 check_c_compiler_flag(-pthread HAVE_PTHREAD)
496 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
497 set(C_FLAGS ${C_FLAGS} -pthread)
498 set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
501 check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
503 # Some systems need pthread_np.h to get pthread_setname_np
504 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
505 if(HAVE_PTHREAD_NP_H)
506 check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
507 if(NOT HAVE_PTHREAD_SETNAME_NP)
508 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
510 check_c_source_compiles("
512 #include <pthread_np.h>
515 pthread_setname_np(\"testname\");
518 PTHREAD_SETNAME_NP_ONE_PARAM
520 check_c_source_compiles("
522 #include <pthread_np.h>
525 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
528 PTHREAD_SETNAME_NP_THREE_PARAMS
532 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
533 if(NOT HAVE_PTHREAD_SETNAME_NP)
534 check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
536 check_c_source_compiles("
540 pthread_setname_np(\"testname\");
543 PTHREAD_SETNAME_NP_ONE_PARAM
545 check_c_source_compiles("
549 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
552 PTHREAD_SETNAME_NP_THREE_PARAMS
558 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
561 # Common sources used by both the OpenAL implementation library and potentially
582 common/intrusive_ptr.h
585 common/polyphase_resampler.cpp
586 common/polyphase_resampler.h
633 alc/buffer_storage.cpp
642 alc/effects/autowah.cpp
643 alc/effects/chorus.cpp
644 alc/effects/compressor.cpp
645 alc/effects/convolution.cpp
646 alc/effects/dedicated.cpp
647 alc/effects/distortion.cpp
649 alc/effects/equalizer.cpp
650 alc/effects/fshifter.cpp
651 alc/effects/modulator.cpp
653 alc/effects/pshifter.cpp
654 alc/effects/reverb.cpp
655 alc/effects/vmorpher.cpp
657 alc/filters/biquad.cpp
660 alc/filters/splitter.cpp
661 alc/filters/splitter.h
666 alc/front_stablizer.h
684 alc/mixer/mixer_c.cpp
688 set(CPU_EXTS "Default")
695 # Check for SSE+SSE2 support
696 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
697 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
698 if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
699 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
700 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
701 if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
704 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
706 set_source_files_properties(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
707 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
709 set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
712 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
713 message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
715 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
716 message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
719 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
721 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
722 if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
724 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
726 set_source_files_properties(alc/mixer/mixer_sse3.cpp PROPERTIES
727 COMPILE_FLAGS "${SSE3_SWITCH}")
729 set(CPU_EXTS "${CPU_EXTS}, SSE3")
732 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
733 message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
736 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
738 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
739 if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
741 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
743 set_source_files_properties(alc/mixer/mixer_sse41.cpp PROPERTIES
744 COMPILE_FLAGS "${SSE4_1_SWITCH}")
746 set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
749 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
750 message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
753 # Check for ARM Neon support
754 option(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
756 option(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
757 if(ALSOFT_CPUEXT_NEON)
759 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
761 set_source_files_properties(alc/mixer/mixer_neon.cpp PROPERTIES
762 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
764 set(CPU_EXTS "${CPU_EXTS}, Neon")
767 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
768 message(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
779 set(HAVE_PORTAUDIO 0)
780 set(HAVE_PULSEAUDIO 0)
781 set(HAVE_COREAUDIO 0)
787 if(WIN32 OR HAVE_DLFCN_H)
789 macro(ADD_BACKEND_LIBS _LIBS)
792 set(IS_LINKED " (linked)")
793 macro(ADD_BACKEND_LIBS _LIBS)
794 set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
799 set(ALC_OBJS ${ALC_OBJS}
800 alc/backends/base.cpp
802 # Default backends, always available
803 alc/backends/loopback.cpp
804 alc/backends/loopback.h
805 alc/backends/null.cpp
810 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
813 option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
814 if(ALSOFT_BACKEND_ALSA)
816 set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
817 set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
818 add_backend_libs(${ALSA_LIBRARIES})
819 set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
822 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
823 message(FATAL_ERROR "Failed to enabled required ALSA backend")
827 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
830 option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
831 if(ALSOFT_BACKEND_OSS)
833 set(BACKENDS "${BACKENDS} OSS,")
834 set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
836 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
838 set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
841 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
842 message(FATAL_ERROR "Failed to enabled required OSS backend")
845 # Check Solaris backend
846 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
847 find_package(AudioIO)
849 option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
850 if(ALSOFT_BACKEND_SOLARIS)
852 set(BACKENDS "${BACKENDS} Solaris,")
853 set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
854 set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
857 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
858 message(FATAL_ERROR "Failed to enabled required Solaris backend")
861 # Check SndIO backend
862 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
863 find_package(SoundIO)
865 option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
866 if(ALSOFT_BACKEND_SNDIO)
868 set(BACKENDS "${BACKENDS} SndIO (linked),")
869 set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
870 set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
871 set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
874 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
875 message(FATAL_ERROR "Failed to enabled required SndIO backend")
878 # Check Windows-only backends
879 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
880 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
881 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
883 set(WINSDK_LIB_DIRS )
884 set(WINSDK_INCLUDE_DIRS )
885 find_package(WindowsSDK)
887 get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
888 get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
891 # Check MMSystem backend
892 check_include_files("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
893 find_library(WINMM_LIBRARY NAMES winmm
894 PATHS ${WINSDK_LIB_DIRS})
895 if(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
896 option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
897 if(ALSOFT_BACKEND_WINMM)
899 set(BACKENDS "${BACKENDS} WinMM,")
900 set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
901 set(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
905 # Check DSound backend
908 option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
909 if(ALSOFT_BACKEND_DSOUND)
911 set(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
912 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
913 add_backend_libs(${DSOUND_LIBRARIES})
914 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
918 # Check for WASAPI backend
919 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
920 if(HAVE_MMDEVICEAPI_H)
921 option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
922 if(ALSOFT_BACKEND_WASAPI)
924 set(BACKENDS "${BACKENDS} WASAPI,")
925 set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
929 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
930 message(FATAL_ERROR "Failed to enabled required WinMM backend")
932 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
933 message(FATAL_ERROR "Failed to enabled required DSound backend")
935 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
936 message(FATAL_ERROR "Failed to enabled required WASAPI backend")
939 # Check PortAudio backend
940 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
941 find_package(PortAudio)
943 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
944 if(ALSOFT_BACKEND_PORTAUDIO)
945 set(HAVE_PORTAUDIO 1)
946 set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
947 set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
948 add_backend_libs(${PORTAUDIO_LIBRARIES})
949 set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
952 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
953 message(FATAL_ERROR "Failed to enabled required PortAudio backend")
956 # Check PulseAudio backend
957 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
958 find_package(PulseAudio)
960 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
961 if(ALSOFT_BACKEND_PULSEAUDIO)
962 set(HAVE_PULSEAUDIO 1)
963 set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
964 set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
965 add_backend_libs(${PULSEAUDIO_LIBRARIES})
966 set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
969 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
970 message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
974 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
977 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
978 if(ALSOFT_BACKEND_JACK)
980 set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
981 set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
982 add_backend_libs(${JACK_LIBRARIES})
983 set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
986 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
987 message(FATAL_ERROR "Failed to enabled required JACK backend")
990 # Check CoreAudio backend
991 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
992 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
993 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
994 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
995 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
996 if(ALSOFT_BACKEND_COREAUDIO)
997 set(HAVE_COREAUDIO 1)
998 set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
999 set(BACKENDS "${BACKENDS} CoreAudio,")
1000 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
1001 find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1002 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
1004 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1005 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1008 # Some versions of OSX may need the AudioToolbox framework. Add it if
1010 find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1011 if(AUDIOTOOLBOX_LIBRARY)
1012 set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1015 set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1018 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1019 message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1022 # Check for OpenSL (Android) backend
1023 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1024 find_package(OpenSL)
1026 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1027 if(ALSOFT_BACKEND_OPENSL)
1029 set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1030 set(BACKENDS "${BACKENDS} OpenSL,")
1031 set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1032 set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1035 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1036 message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1039 # Check for Oboe (Android) backend
1042 set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1044 # Force Oboe to build with hidden symbols. Don't want to be exporting
1046 set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1047 check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1048 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1049 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1051 add_subdirectory(${OBOE_SOURCE} ./oboe)
1052 set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1053 unset(OLD_CXX_FLAGS)
1055 set(OBOE_TARGET oboe)
1059 set(OBOE_TARGET "oboe::oboe")
1064 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1066 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1067 if(ALSOFT_BACKEND_OBOE)
1069 set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1070 set(BACKENDS "${BACKENDS} Oboe,")
1071 set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1074 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1075 message(FATAL_ERROR "Failed to enabled required Oboe backend")
1078 # Check for SDL2 backend
1079 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1082 # Off by default, since it adds a runtime dependency
1083 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1084 if(ALSOFT_BACKEND_SDL2)
1086 set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1087 set(BACKENDS "${BACKENDS} SDL2,")
1088 set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1089 set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1092 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1093 message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1096 # Optionally enable the Wave Writer backend
1097 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1098 if(ALSOFT_BACKEND_WAVE)
1100 set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1101 set(BACKENDS "${BACKENDS} WaveFile,")
1104 # This is always available
1105 set(BACKENDS "${BACKENDS} Null")
1109 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1110 # Get the current working branch and its latest abbreviated commit hash
1111 add_custom_target(build_version
1112 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1113 -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1114 -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1115 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1119 set(GIT_BRANCH "UNKNOWN")
1120 set(GIT_COMMIT_HASH "unknown")
1122 "${OpenAL_SOURCE_DIR}/version.h.in"
1123 "${OpenAL_BINARY_DIR}/version.h")
1127 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1128 if(ALSOFT_EMBED_HRTF_DATA)
1129 macro(make_hrtf_header FILENAME VARNAME)
1130 set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1131 set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1133 add_custom_command(OUTPUT "${outfile}"
1134 COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1135 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1136 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1137 DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1140 set(ALC_OBJS ${ALC_OBJS} "${outfile}")
1143 make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1147 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1148 find_package(Qt5Widgets)
1151 find_package(SndFile)
1154 find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1159 set(LIBNAME "openal")
1161 set(LIBNAME "OpenAL32")
1164 # Needed for openal.pc.in
1165 set(prefix ${CMAKE_INSTALL_PREFIX})
1166 set(exec_prefix "\${prefix}")
1167 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1168 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1169 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1170 set(PACKAGE_VERSION "${LIB_VERSION}")
1171 set(PKG_CONFIG_CFLAGS )
1172 set(PKG_CONFIG_PRIVATE_LIBS )
1173 if(LIBTYPE STREQUAL "STATIC")
1174 set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1175 foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1176 # If this is already a linker flag, or is a full path+file, add it
1177 # as-is. Otherwise, it's a name intended to be dressed as -lname.
1178 if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1179 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1181 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1188 "${OpenAL_SOURCE_DIR}/config.h.in"
1189 "${OpenAL_BINARY_DIR}/config.h")
1191 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1192 "${OpenAL_BINARY_DIR}/openal.pc"
1196 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1197 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1198 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1199 target_compile_options(common PRIVATE ${C_FLAGS})
1200 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1204 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1206 # Build main library
1207 if(LIBTYPE STREQUAL "STATIC")
1208 add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1209 target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1210 target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1212 # This option is for static linking OpenAL Soft into another project
1213 # that already defines the IDs. It is up to that project to ensure all
1214 # required IDs are defined.
1215 option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1216 if(ALSOFT_NO_UID_DEFS)
1217 target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1221 set(RC_CONFIG resources/openal32.rc)
1222 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1223 add_library(OpenAL SHARED
1230 target_compile_definitions(OpenAL
1231 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1232 target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1233 target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1234 target_include_directories(OpenAL
1236 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1237 $<INSTALL_INTERFACE:include>
1239 ${OpenAL_SOURCE_DIR}/common
1240 ${OpenAL_BINARY_DIR}
1242 set_target_properties(OpenAL PROPERTIES PREFIX "")
1243 set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1244 if(TARGET build_version)
1245 add_dependencies(OpenAL build_version)
1249 set(LIBNAME "soft_oal")
1250 set(IMPL_TARGET soft_oal)
1251 set(RC_CONFIG resources/soft_oal.rc)
1254 # !important: for osx framework public header works, the headers must be in
1256 set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1257 add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG}
1258 ${TARGET_PUBLIC_HEADERS})
1260 set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1262 target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1264 if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1265 # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1266 set(LIBNAME "soft_oal")
1268 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1270 OUTPUT_VARIABLE BUNDLE_VERSION
1271 OUTPUT_STRIP_TRAILING_WHITESPACE)
1273 set(BUNDLE_VERSION 1)
1276 # Build: Fix rpath in iOS shared libraries
1277 # If this flag is not set, the final dylib binary ld path will be
1278 # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1279 # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1280 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1281 set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1284 set_target_properties(${IMPL_TARGET} PROPERTIES
1287 MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1288 MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1289 MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1290 MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1291 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1292 XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1293 XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1294 PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1299 target_include_directories(${IMPL_TARGET}
1301 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1302 $<INSTALL_INTERFACE:include>
1305 ${OpenAL_BINARY_DIR}
1306 ${OpenAL_SOURCE_DIR}
1307 ${OpenAL_SOURCE_DIR}/alc
1308 ${OpenAL_SOURCE_DIR}/common
1311 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1312 VERSION ${LIB_VERSION}
1313 SOVERSION ${LIB_MAJOR_VERSION}
1315 target_compile_definitions(${IMPL_TARGET}
1316 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1317 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1319 if(TARGET build_version)
1320 add_dependencies(${IMPL_TARGET} build_version)
1323 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1324 find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1325 if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1327 if(NOT SED_EXECUTABLE)
1328 message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1330 if(NOT CMAKE_DLLTOOL)
1331 message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1334 set_property(TARGET OpenAL APPEND_STRING PROPERTY
1335 LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1336 add_custom_command(TARGET OpenAL POST_BUILD
1337 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1338 COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1339 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1347 message(STATUS "Building DLL router")
1351 Building OpenAL with support for the following backends:
1354 Building with support for CPU extensions:
1358 message(STATUS "Building with SSE${FPMATH_SET} codegen
1362 if(ALSOFT_EMBED_HRTF_DATA)
1363 message(STATUS "Embedding HRTF datasets
1367 # Install main library
1369 install(TARGETS OpenAL EXPORT OpenAL
1370 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1371 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1372 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1373 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1374 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1375 export(TARGETS OpenAL
1377 FILE OpenALConfig.cmake)
1378 install(EXPORT OpenAL
1379 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1381 FILE OpenALConfig.cmake)
1382 install(DIRECTORY include/AL
1383 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1384 install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1385 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1387 install(TARGETS soft_oal
1388 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1390 message(STATUS "Installing library and headers")
1392 message(STATUS "NOT installing library and headers")
1395 if(ALSOFT_INSTALL_CONFIG)
1396 install(FILES alsoftrc.sample
1397 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1398 message(STATUS "Installing sample configuration")
1401 if(ALSOFT_INSTALL_HRTF_DATA)
1402 install(DIRECTORY hrtf
1403 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1404 message(STATUS "Installing HRTF data files")
1407 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1408 install(DIRECTORY presets
1409 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1410 message(STATUS "Installing AmbDec presets")
1416 set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1418 set(EXTRA_INSTALLS )
1420 add_executable(openal-info utils/openal-info.c)
1421 target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1422 target_compile_options(openal-info PRIVATE ${C_FLAGS})
1423 target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1424 if(ALSOFT_INSTALL_EXAMPLES)
1425 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1428 find_package(MySOFA)
1430 set(SOFA_SUPPORT_SRCS
1431 utils/sofa-support.cpp
1432 utils/sofa-support.h)
1433 add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1434 target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1435 target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1436 target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1437 target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1440 utils/makemhr/loaddef.cpp
1441 utils/makemhr/loaddef.h
1442 utils/makemhr/loadsofa.cpp
1443 utils/makemhr/loadsofa.h
1444 utils/makemhr/makemhr.cpp
1445 utils/makemhr/makemhr.h)
1447 set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1449 add_executable(makemhr ${MAKEMHR_SRCS})
1450 target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1451 target_include_directories(makemhr
1452 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1453 target_compile_options(makemhr PRIVATE ${C_FLAGS})
1454 target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1455 if(ALSOFT_INSTALL_EXAMPLES)
1456 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1459 set(SOFAINFO_SRCS utils/sofa-info.cpp)
1460 add_executable(sofa-info ${SOFAINFO_SRCS})
1461 target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1462 target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1463 target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1464 target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1466 message(STATUS "Building utility programs")
1468 if(NOT ALSOFT_NO_CONFIG_UTIL)
1469 add_subdirectory(utils/alsoft-config)
1475 # Add a static library with common functions used by multiple example targets
1476 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1477 examples/common/alhelpers.c
1478 examples/common/alhelpers.h)
1479 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1480 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1481 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1482 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1485 add_executable(altonegen examples/altonegen.c)
1486 target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1488 add_executable(alrecord examples/alrecord.c)
1489 target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1491 if(ALSOFT_INSTALL_EXAMPLES)
1492 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1495 message(STATUS "Building example programs")
1498 add_executable(alplay examples/alplay.c)
1499 target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1502 add_executable(alstream examples/alstream.c)
1503 target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1506 add_executable(alreverb examples/alreverb.c)
1507 target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1510 add_executable(almultireverb examples/almultireverb.c)
1511 target_link_libraries(almultireverb
1512 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1514 add_executable(allatency examples/allatency.c)
1515 target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1518 add_executable(alhrtf examples/alhrtf.c)
1519 target_link_libraries(alhrtf
1520 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1522 add_executable(alstreamcb examples/alstreamcb.cpp)
1523 target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1526 add_executable(alconvolve examples/alconvolve.c)
1527 target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1530 if(ALSOFT_INSTALL_EXAMPLES)
1531 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1535 message(STATUS "Building SndFile example programs")
1539 add_executable(alloopback examples/alloopback.c)
1540 target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1541 target_link_libraries(alloopback
1542 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1544 if(ALSOFT_INSTALL_EXAMPLES)
1545 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1548 message(STATUS "Building SDL example programs")
1553 if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1554 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1557 if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1558 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1561 if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1562 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1565 if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1566 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1569 if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1570 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1575 add_executable(alffplay examples/alffplay.cpp)
1576 target_include_directories(alffplay
1577 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1578 target_link_libraries(alffplay
1579 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1581 if(ALSOFT_INSTALL_EXAMPLES)
1582 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1584 message(STATUS "Building SDL+FFmpeg example programs")
1591 install(TARGETS ${EXTRA_INSTALLS}
1592 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1593 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
1594 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1595 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})