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(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
350 # Yes GCC, really don't accept command line options you don't support
351 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
353 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
354 if(HAVE_MSSE2_SWITCH)
355 set(SSE2_SWITCH "-msse2")
357 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
358 unset(OLD_REQUIRED_FLAGS)
360 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H)
361 check_include_file(emmintrin.h HAVE_EMMINTRIN_H)
362 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H)
363 check_include_file(smmintrin.h HAVE_SMMINTRIN_H)
364 check_include_file(arm_neon.h HAVE_ARM_NEON_H)
372 # Check for SSE+SSE2 support
373 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
374 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
375 if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
376 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
377 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
378 if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
383 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
384 message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
386 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
387 message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
390 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
392 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
393 if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
397 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
398 message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
401 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
403 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
404 if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
408 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
409 message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
412 # Check for ARM Neon support
413 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
415 option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
416 if(ALSOFT_CPUEXT_NEON)
417 check_c_source_compiles("#include <arm_neon.h>
420 int32x4_t ret4 = vdupq_n_s32(0);
421 return vgetq_lane_s32(ret4, 0);
422 }" HAVE_NEON_INTRINSICS)
423 if(HAVE_NEON_INTRINSICS)
428 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
429 message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
435 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND HAVE_SSE2)
436 option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
437 if(ALSOFT_ENABLE_SSE2_CODEGEN)
438 if(SSE2_SWITCH OR NOT MSVC)
439 check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
440 if(HAVE_MFPMATH_SSE_2)
441 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
442 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
445 # SSE depends on a 16-byte aligned stack, and by default, GCC
446 # assumes the stack is suitably aligned. Older Linux code or other
447 # OSs don't guarantee this on 32-bit, so externally-callable
448 # functions need to ensure an aligned stack.
449 set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
451 check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
453 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
454 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
462 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
463 foreach(flag_var ${SSE_FLAGS})
464 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
467 check_c_source_compiles("#include <emmintrin.h>
468 int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
470 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
474 check_include_file(malloc.h HAVE_MALLOC_H)
475 check_include_file(cpuid.h HAVE_CPUID_H)
476 check_include_file(intrin.h HAVE_INTRIN_H)
477 check_include_file(guiddef.h HAVE_GUIDDEF_H)
478 if(NOT HAVE_GUIDDEF_H)
479 check_include_file(initguid.h HAVE_INITGUID_H)
482 # Some systems need libm for some math functions to work
484 check_library_exists(m pow "" HAVE_LIBM)
486 set(MATH_LIB ${MATH_LIB} m)
487 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
490 # Some systems need to link with -lrt for clock_gettime as used by the common
493 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
498 # Check for the dlopen API (for dynamicly loading backend libs)
500 check_include_file(dlfcn.h HAVE_DLFCN_H)
501 check_library_exists(dl dlopen "" HAVE_LIBDL)
503 set(EXTRA_LIBS dl ${EXTRA_LIBS})
504 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
508 # Check for a cpuid intrinsic
510 check_c_source_compiles("#include <cpuid.h>
513 unsigned int eax, ebx, ecx, edx;
514 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
515 }" HAVE_GCC_GET_CPUID)
518 check_c_source_compiles("#include <intrin.h>
524 }" HAVE_CPUID_INTRINSIC)
527 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
528 check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
529 check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
532 # We need pthreads outside of Windows, for semaphores. It's also used to
533 # set the priority and name of threads, when possible.
534 check_include_file(pthread.h HAVE_PTHREAD_H)
535 if(NOT HAVE_PTHREAD_H)
536 message(FATAL_ERROR "PThreads is required for non-Windows builds!")
539 check_c_compiler_flag(-pthread HAVE_PTHREAD)
541 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
542 set(C_FLAGS ${C_FLAGS} -pthread)
543 set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
546 check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
548 # Some systems need pthread_np.h to get pthread_setname_np
549 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
550 if(HAVE_PTHREAD_NP_H)
551 check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
552 if(NOT HAVE_PTHREAD_SETNAME_NP)
553 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
555 check_c_source_compiles("
557 #include <pthread_np.h>
560 pthread_setname_np(\"testname\");
563 PTHREAD_SETNAME_NP_ONE_PARAM
565 check_c_source_compiles("
567 #include <pthread_np.h>
570 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
573 PTHREAD_SETNAME_NP_THREE_PARAMS
577 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
578 if(NOT HAVE_PTHREAD_SETNAME_NP)
579 check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
581 check_c_source_compiles("
585 pthread_setname_np(\"testname\");
588 PTHREAD_SETNAME_NP_ONE_PARAM
590 check_c_source_compiles("
594 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
597 PTHREAD_SETNAME_NP_THREE_PARAMS
603 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
606 # Common sources used by both the OpenAL implementation library, the OpenAL
607 # router, and certain tools and examples.
626 common/intrusive_ptr.h
629 common/polyphase_resampler.cpp
630 common/polyphase_resampler.h
632 common/ringbuffer.cpp
641 # Core library routines
649 core/bsinc_tables.cpp
658 core/filters/biquad.h
659 core/filters/biquad.cpp
662 core/filters/splitter.cpp
663 core/filters/splitter.h
675 core/mixer/hrtfbase.h
676 core/mixer/hrtfdefs.h
677 core/mixer/mixer_c.cpp)
679 # AL and related routines
687 al/effects/autowah.cpp
688 al/effects/chorus.cpp
689 al/effects/compressor.cpp
690 al/effects/convolution.cpp
691 al/effects/dedicated.cpp
692 al/effects/distortion.cpp
695 al/effects/equalizer.cpp
696 al/effects/fshifter.cpp
697 al/effects/modulator.cpp
699 al/effects/pshifter.cpp
700 al/effects/reverb.cpp
701 al/effects/vmorpher.cpp
714 # ALC and related routines
726 alc/buffer_storage.cpp
734 alc/effects/autowah.cpp
735 alc/effects/chorus.cpp
736 alc/effects/compressor.cpp
737 alc/effects/convolution.cpp
738 alc/effects/dedicated.cpp
739 alc/effects/distortion.cpp
741 alc/effects/equalizer.cpp
742 alc/effects/fshifter.cpp
743 alc/effects/modulator.cpp
745 alc/effects/pshifter.cpp
746 alc/effects/reverb.cpp
747 alc/effects/vmorpher.cpp
748 alc/front_stablizer.h
759 # Include SIMD mixers
760 set(CPU_EXTS "Default")
762 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse.cpp core/mixer/mixer_sse2.cpp)
763 set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
766 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
767 set(CPU_EXTS "${CPU_EXTS}, SSE3")
770 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
771 set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
774 set(CORE_OBJS ${CORE_OBJS} core/mixer/mixer_neon.cpp)
775 set(CPU_EXTS "${CPU_EXTS}, Neon")
786 set(HAVE_PORTAUDIO 0)
787 set(HAVE_PULSEAUDIO 0)
788 set(HAVE_COREAUDIO 0)
794 if(WIN32 OR HAVE_DLFCN_H)
796 macro(ADD_BACKEND_LIBS _LIBS)
799 set(IS_LINKED " (linked)")
800 macro(ADD_BACKEND_LIBS _LIBS)
801 set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
806 set(ALC_OBJS ${ALC_OBJS}
807 alc/backends/base.cpp
809 # Default backends, always available
810 alc/backends/loopback.cpp
811 alc/backends/loopback.h
812 alc/backends/null.cpp
817 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
820 option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
821 if(ALSOFT_BACKEND_ALSA)
823 set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
824 set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
825 add_backend_libs(${ALSA_LIBRARIES})
826 set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
829 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
830 message(FATAL_ERROR "Failed to enabled required ALSA backend")
834 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
837 option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
838 if(ALSOFT_BACKEND_OSS)
840 set(BACKENDS "${BACKENDS} OSS,")
841 set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
843 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
845 set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
848 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
849 message(FATAL_ERROR "Failed to enabled required OSS backend")
852 # Check Solaris backend
853 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
854 find_package(AudioIO)
856 option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
857 if(ALSOFT_BACKEND_SOLARIS)
859 set(BACKENDS "${BACKENDS} Solaris,")
860 set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
861 set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
864 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
865 message(FATAL_ERROR "Failed to enabled required Solaris backend")
868 # Check SndIO backend
869 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
870 find_package(SoundIO)
872 option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
873 if(ALSOFT_BACKEND_SNDIO)
875 set(BACKENDS "${BACKENDS} SndIO (linked),")
876 set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
877 set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
878 set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
881 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
882 message(FATAL_ERROR "Failed to enabled required SndIO backend")
885 # Check Windows-only backends
886 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
887 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
888 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
890 # Check MMSystem backend
891 option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
892 if(ALSOFT_BACKEND_WINMM)
894 set(BACKENDS "${BACKENDS} WinMM,")
895 set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
896 # There doesn't seem to be good way to search for winmm.lib for MSVC.
897 # find_library doesn't find it without being told to look in a specific
898 # place in the WindowsSDK, but it links anyway. If there ends up being
899 # Windows targets without this, another means to detect it is needed.
900 set(EXTRA_LIBS winmm ${EXTRA_LIBS})
903 # Check DSound backend
904 check_include_file(dsound.h HAVE_DSOUND_H)
906 find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
907 PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
908 DOC "The DirectSound include directory")
910 if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
911 option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
912 if(ALSOFT_BACKEND_DSOUND)
914 set(BACKENDS "${BACKENDS} DirectSound,")
915 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
917 if(NOT HAVE_DSOUND_H)
918 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIR})
923 # Check for WASAPI backend
924 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
925 if(HAVE_MMDEVICEAPI_H)
926 option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
927 if(ALSOFT_BACKEND_WASAPI)
929 set(BACKENDS "${BACKENDS} WASAPI,")
930 set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
934 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
935 message(FATAL_ERROR "Failed to enabled required WinMM backend")
937 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
938 message(FATAL_ERROR "Failed to enabled required DSound backend")
940 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
941 message(FATAL_ERROR "Failed to enabled required WASAPI backend")
944 # Check PortAudio backend
945 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
946 find_package(PortAudio)
948 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
949 if(ALSOFT_BACKEND_PORTAUDIO)
950 set(HAVE_PORTAUDIO 1)
951 set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
952 set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
953 add_backend_libs(${PORTAUDIO_LIBRARIES})
954 set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
957 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
958 message(FATAL_ERROR "Failed to enabled required PortAudio backend")
961 # Check PulseAudio backend
962 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
963 find_package(PulseAudio)
965 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
966 if(ALSOFT_BACKEND_PULSEAUDIO)
967 set(HAVE_PULSEAUDIO 1)
968 set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
969 set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
970 add_backend_libs(${PULSEAUDIO_LIBRARIES})
971 set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
974 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
975 message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
979 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
982 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
983 if(ALSOFT_BACKEND_JACK)
985 set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
986 set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
987 add_backend_libs(${JACK_LIBRARIES})
988 set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
991 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
992 message(FATAL_ERROR "Failed to enabled required JACK backend")
995 # Check CoreAudio backend
996 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
997 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
998 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
999 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
1000 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1001 if(ALSOFT_BACKEND_COREAUDIO)
1002 set(HAVE_COREAUDIO 1)
1003 set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1004 set(BACKENDS "${BACKENDS} CoreAudio,")
1005 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
1006 find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
1007 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
1009 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1010 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1013 # Some versions of OSX may need the AudioToolbox framework. Add it if
1015 find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1016 if(AUDIOTOOLBOX_LIBRARY)
1017 set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1020 set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1023 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1024 message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1027 # Check for OpenSL (Android) backend
1028 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1029 find_package(OpenSL)
1031 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1032 if(ALSOFT_BACKEND_OPENSL)
1034 set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1035 set(BACKENDS "${BACKENDS} OpenSL,")
1036 set(EXTRA_LIBS "OpenSL::OpenSLES" ${EXTRA_LIBS})
1039 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1040 message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1043 # Check for Oboe (Android) backend
1046 set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1048 # Force Oboe to build with hidden symbols. Don't want to be exporting
1050 set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1051 check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1052 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1053 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1055 add_subdirectory(${OBOE_SOURCE} ./oboe)
1056 set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1057 unset(OLD_CXX_FLAGS)
1059 set(OBOE_TARGET oboe)
1063 set(OBOE_TARGET "oboe::oboe")
1068 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1070 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1071 if(ALSOFT_BACKEND_OBOE)
1073 set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1074 set(BACKENDS "${BACKENDS} Oboe,")
1075 set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1078 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1079 message(FATAL_ERROR "Failed to enabled required Oboe backend")
1082 # Check for SDL2 backend
1083 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1086 # Off by default, since it adds a runtime dependency
1087 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1088 if(ALSOFT_BACKEND_SDL2)
1090 set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1091 set(BACKENDS "${BACKENDS} SDL2,")
1092 set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1093 set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1096 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1097 message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1100 # Optionally enable the Wave Writer backend
1101 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1102 if(ALSOFT_BACKEND_WAVE)
1104 set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1105 set(BACKENDS "${BACKENDS} WaveFile,")
1108 # This is always available
1109 set(BACKENDS "${BACKENDS} Null")
1113 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1114 # Get the current working branch and its latest abbreviated commit hash
1115 add_custom_target(build_version
1116 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1117 -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1118 -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1119 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1123 set(GIT_BRANCH "UNKNOWN")
1124 set(GIT_COMMIT_HASH "unknown")
1126 "${OpenAL_SOURCE_DIR}/version.h.in"
1127 "${OpenAL_BINARY_DIR}/version.h")
1131 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1132 if(ALSOFT_EMBED_HRTF_DATA)
1133 macro(make_hrtf_header FILENAME VARNAME)
1134 set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1135 set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1137 add_custom_command(OUTPUT "${outfile}"
1138 COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1139 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1140 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1141 DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1144 set(ALC_OBJS ${ALC_OBJS} "${outfile}")
1147 make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1151 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1152 find_package(Qt5Widgets)
1155 find_package(SndFile)
1158 find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1163 set(LIBNAME "openal")
1165 set(LIBNAME "OpenAL32")
1168 # Needed for openal.pc.in
1169 set(prefix ${CMAKE_INSTALL_PREFIX})
1170 set(exec_prefix "\${prefix}")
1171 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1172 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1173 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1174 set(PACKAGE_VERSION "${LIB_VERSION}")
1175 set(PKG_CONFIG_CFLAGS )
1176 set(PKG_CONFIG_PRIVATE_LIBS )
1177 if(LIBTYPE STREQUAL "STATIC")
1178 set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1179 foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1180 # If this is already a linker flag, or is a full path+file, add it
1181 # as-is. Otherwise, it's a name intended to be dressed as -lname.
1182 if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1183 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1185 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1192 "${OpenAL_SOURCE_DIR}/config.h.in"
1193 "${OpenAL_BINARY_DIR}/config.h")
1195 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1196 "${OpenAL_BINARY_DIR}/openal.pc"
1200 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1201 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1202 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1203 target_compile_options(common PRIVATE ${C_FLAGS})
1204 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1208 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1210 # Build main library
1211 if(LIBTYPE STREQUAL "STATIC")
1212 add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS})
1213 target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1214 target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1216 # This option is for static linking OpenAL Soft into another project
1217 # that already defines the IDs. It is up to that project to ensure all
1218 # required IDs are defined.
1219 option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1220 if(ALSOFT_NO_UID_DEFS)
1221 target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1225 set(RC_CONFIG resources/openal32.rc)
1226 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1227 add_library(OpenAL SHARED
1234 target_compile_definitions(OpenAL
1235 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1236 target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1237 target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1238 target_include_directories(OpenAL
1240 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1241 $<INSTALL_INTERFACE:include>
1243 ${OpenAL_SOURCE_DIR}/common
1244 ${OpenAL_BINARY_DIR}
1246 set_target_properties(OpenAL PROPERTIES PREFIX "")
1247 set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1248 if(TARGET build_version)
1249 add_dependencies(OpenAL build_version)
1253 set(LIBNAME "soft_oal")
1254 set(IMPL_TARGET soft_oal)
1255 set(RC_CONFIG resources/soft_oal.rc)
1258 # !important: for osx framework public header works, the headers must be in
1260 set(TARGET_PUBLIC_HEADERS include/AL/al.h include/AL/alc.h include/AL/alext.h include/AL/efx.h)
1261 add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${CORE_OBJS} ${RC_CONFIG}
1262 ${TARGET_PUBLIC_HEADERS})
1264 set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1266 target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1268 if(APPLE AND ALSOFT_OSX_FRAMEWORK)
1269 # Sets framework name to soft_oal to avoid ambiguity with the system OpenAL.framework
1270 set(LIBNAME "soft_oal")
1272 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1274 OUTPUT_VARIABLE BUNDLE_VERSION
1275 OUTPUT_STRIP_TRAILING_WHITESPACE)
1277 set(BUNDLE_VERSION 1)
1280 # Build: Fix rpath in iOS shared libraries
1281 # If this flag is not set, the final dylib binary ld path will be
1282 # /User/xxx/*/soft_oal.framework/soft_oal, which can't be loaded by iOS devices.
1283 # See also: https://github.com/libjpeg-turbo/libjpeg-turbo/commit/c80ddef7a4ce21ace9e3ca0fd190d320cc8cdaeb
1284 if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG)
1285 set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
1288 set_target_properties(${IMPL_TARGET} PROPERTIES
1291 MACOSX_FRAMEWORK_NAME "${IMPL_TARGET}"
1292 MACOSX_FRAMEWORK_IDENTIFIER "org.openal-soft.openal"
1293 MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${LIB_VERSION}
1294 MACOSX_FRAMEWORK_BUNDLE_VERSION ${BUNDLE_VERSION}
1295 XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ""
1296 XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "NO"
1297 XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO"
1298 PUBLIC_HEADER "${TARGET_PUBLIC_HEADERS}"
1303 target_include_directories(${IMPL_TARGET}
1305 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1306 $<INSTALL_INTERFACE:include>
1309 ${OpenAL_BINARY_DIR}
1310 ${OpenAL_SOURCE_DIR}
1311 ${OpenAL_SOURCE_DIR}/alc
1312 ${OpenAL_SOURCE_DIR}/common
1315 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1316 VERSION ${LIB_VERSION}
1317 SOVERSION ${LIB_MAJOR_VERSION}
1319 target_compile_definitions(${IMPL_TARGET}
1320 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1321 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1323 if(TARGET build_version)
1324 add_dependencies(${IMPL_TARGET} build_version)
1327 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1328 find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1329 if(NOT SED_EXECUTABLE OR NOT CMAKE_DLLTOOL)
1331 if(NOT SED_EXECUTABLE)
1332 message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1334 if(NOT CMAKE_DLLTOOL)
1335 message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1338 set_property(TARGET OpenAL APPEND_STRING PROPERTY
1339 LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1340 add_custom_command(TARGET OpenAL POST_BUILD
1341 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1342 COMMAND "${CMAKE_DLLTOOL}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1343 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1351 message(STATUS "Building DLL router")
1355 Building OpenAL with support for the following backends:
1358 Building with support for CPU extensions:
1362 message(STATUS "Building with SSE${FPMATH_SET} codegen
1366 if(ALSOFT_EMBED_HRTF_DATA)
1367 message(STATUS "Embedding HRTF datasets
1371 # Install main library
1373 install(TARGETS OpenAL EXPORT OpenAL
1374 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1375 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1376 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1377 FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR}
1378 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1379 export(TARGETS OpenAL
1381 FILE OpenALConfig.cmake)
1382 install(EXPORT OpenAL
1383 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1385 FILE OpenALConfig.cmake)
1386 install(DIRECTORY include/AL
1387 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1388 install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1389 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1391 install(TARGETS soft_oal
1392 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1394 message(STATUS "Installing library and headers")
1396 message(STATUS "NOT installing library and headers")
1399 if(ALSOFT_INSTALL_CONFIG)
1400 install(FILES alsoftrc.sample
1401 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1402 message(STATUS "Installing sample configuration")
1405 if(ALSOFT_INSTALL_HRTF_DATA)
1406 install(DIRECTORY hrtf
1407 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1408 message(STATUS "Installing HRTF data files")
1411 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1412 install(DIRECTORY presets
1413 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1414 message(STATUS "Installing AmbDec presets")
1420 set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1422 set(EXTRA_INSTALLS )
1424 add_executable(openal-info utils/openal-info.c)
1425 target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1426 target_compile_options(openal-info PRIVATE ${C_FLAGS})
1427 target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1428 if(ALSOFT_INSTALL_EXAMPLES)
1429 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1432 find_package(MySOFA)
1434 set(SOFA_SUPPORT_SRCS
1435 utils/sofa-support.cpp
1436 utils/sofa-support.h)
1437 add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1438 target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1439 target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1440 target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1441 target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1444 utils/makemhr/loaddef.cpp
1445 utils/makemhr/loaddef.h
1446 utils/makemhr/loadsofa.cpp
1447 utils/makemhr/loadsofa.h
1448 utils/makemhr/makemhr.cpp
1449 utils/makemhr/makemhr.h)
1451 set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1453 add_executable(makemhr ${MAKEMHR_SRCS})
1454 target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1455 target_include_directories(makemhr
1456 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1457 target_compile_options(makemhr PRIVATE ${C_FLAGS})
1458 target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1459 if(ALSOFT_INSTALL_EXAMPLES)
1460 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1463 set(SOFAINFO_SRCS utils/sofa-info.cpp)
1464 add_executable(sofa-info ${SOFAINFO_SRCS})
1465 target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1466 target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1467 target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1468 target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1470 message(STATUS "Building utility programs")
1472 if(NOT ALSOFT_NO_CONFIG_UTIL)
1473 add_subdirectory(utils/alsoft-config)
1479 # Add a static library with common functions used by multiple example targets
1480 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1481 examples/common/alhelpers.c
1482 examples/common/alhelpers.h)
1483 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1484 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1485 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1486 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1489 add_executable(altonegen examples/altonegen.c)
1490 target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1492 add_executable(alrecord examples/alrecord.c)
1493 target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1495 if(ALSOFT_INSTALL_EXAMPLES)
1496 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1499 message(STATUS "Building example programs")
1502 add_executable(alplay examples/alplay.c)
1503 target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1506 add_executable(alstream examples/alstream.c)
1507 target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1510 add_executable(alreverb examples/alreverb.c)
1511 target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1514 add_executable(almultireverb examples/almultireverb.c)
1515 target_link_libraries(almultireverb
1516 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1518 add_executable(allatency examples/allatency.c)
1519 target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1522 add_executable(alhrtf examples/alhrtf.c)
1523 target_link_libraries(alhrtf
1524 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1526 add_executable(alstreamcb examples/alstreamcb.cpp)
1527 target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1530 add_executable(alconvolve examples/alconvolve.c)
1531 target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1534 if(ALSOFT_INSTALL_EXAMPLES)
1535 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1539 message(STATUS "Building SndFile example programs")
1543 add_executable(alloopback examples/alloopback.c)
1544 target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1545 target_link_libraries(alloopback
1546 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1548 if(ALSOFT_INSTALL_EXAMPLES)
1549 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1552 message(STATUS "Building SDL example programs")
1557 if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1558 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1561 if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1562 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1565 if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1566 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1569 if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1570 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1573 if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1574 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1579 add_executable(alffplay examples/alffplay.cpp)
1580 target_include_directories(alffplay
1581 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1582 target_link_libraries(alffplay
1583 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1585 if(ALSOFT_INSTALL_EXAMPLES)
1586 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1588 message(STATUS "Building SDL+FFmpeg example programs")
1595 install(TARGETS ${EXTRA_INSTALLS}
1596 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1597 BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
1598 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1599 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})