1 # CMake build file list for OpenAL
3 cmake_minimum_required(VERSION 3.0.2)
7 if(COMMAND CMAKE_POLICY)
8 cmake_policy(SET CMP0003 NEW)
9 cmake_policy(SET CMP0005 NEW)
11 cmake_policy(SET CMP0020 NEW)
14 cmake_policy(SET CMP0042 NEW)
17 cmake_policy(SET CMP0054 NEW)
20 cmake_policy(SET CMP0075 NEW)
22 endif(COMMAND CMAKE_POLICY)
24 if(NOT CMAKE_BUILD_TYPE)
25 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
26 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
29 if(NOT CMAKE_DEBUG_POSTFIX)
30 set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
31 "Library postfix for debug builds. Normally left blank."
35 set(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
38 include(CheckFunctionExists)
39 include(CheckLibraryExists)
40 include(CheckIncludeFile)
41 include(CheckIncludeFiles)
42 include(CheckSymbolExists)
43 include(CheckCCompilerFlag)
44 include(CheckCXXCompilerFlag)
45 include(CheckCSourceCompiles)
46 include(CheckCXXSourceCompiles)
47 include(CheckTypeSize)
48 include(CheckStructHasMember)
49 include(GNUInstallDirs)
52 option(ALSOFT_DLOPEN "Check for the dlopen API for loading optional libs" ON)
54 option(ALSOFT_WERROR "Treat compile warnings as errors" OFF)
56 option(ALSOFT_UTILS "Build utility programs" ON)
57 option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
59 option(ALSOFT_EXAMPLES "Build example programs" ON)
61 option(ALSOFT_INSTALL "Install main library" ON)
62 option(ALSOFT_INSTALL_CONFIG "Install alsoft.conf sample configuration file" ON)
63 option(ALSOFT_INSTALL_HRTF_DEFS "Install HRTF definition files" ON)
64 option(ALSOFT_INSTALL_AMBDEC_PRESETS "Install AmbDec preset files" ON)
65 option(ALSOFT_INSTALL_EXAMPLES "Install example programs (alplay, alstream, ...)" ON)
66 option(ALSOFT_INSTALL_UTILS "Install utility programs (openal-info, alsoft-config, ...)" ON)
67 option(ALSOFT_UPDATE_BUILD_VERSION "Update git build version info" ON)
69 if(DEFINED SHARE_INSTALL_DIR)
70 message(WARNING "SHARE_INSTALL_DIR is deprecated. Use the variables provided by the GNUInstallDirs module instead")
71 set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
74 if(DEFINED LIB_SUFFIX)
75 message(WARNING "LIB_SUFFIX is deprecated. Use the variables provided by the GNUInstallDirs module instead")
77 if(DEFINED ALSOFT_CONFIG)
78 message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
80 if(DEFINED ALSOFT_HRTF_DEFS)
81 message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DEFS instead")
83 if(DEFINED ALSOFT_AMBDEC_PRESETS)
84 message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
88 set(CPP_DEFS ) # C pre-processor, not C++
95 set(CPP_DEFS ${CPP_DEFS} _WIN32)
97 option(ALSOFT_BUILD_ROUTER "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)" OFF)
100 option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
103 set(DLLTOOL "${HOST}-dlltool")
105 set(DLLTOOL "dlltool")
112 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
113 if("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
114 set(INC_PATHS ${INC_PATHS} /usr/include)
115 set(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
122 set(LIB_MAJOR_VERSION "1")
123 set(LIB_MINOR_VERSION "20")
124 set(LIB_REVISION "1")
125 set(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
126 set(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
131 check_type_size("long" SIZEOF_LONG)
135 set(CMAKE_CXX_STANDARD 14)
136 set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
138 # Prefer C11, but support C99 and C90 too.
139 set(CMAKE_C_STANDARD 11)
143 # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
144 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
145 if(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
146 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
147 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
148 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
149 if(NOT HAVE_POSIX_MEMALIGN_POSIX)
150 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
152 set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
155 unset(OLD_REQUIRED_FLAGS)
158 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
160 check_cxx_source_compiles("int *__restrict foo;
161 int main() { return 0; }" HAVE___RESTRICT)
163 set(RESTRICT_DECL "__restrict")
166 # Some systems may need libatomic for atomic functions to work
167 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
168 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
169 check_cxx_source_compiles("#include <atomic>
170 std::atomic<int> foo{0};
171 int main() { return foo.fetch_add(2); }"
173 if(NOT HAVE_LIBATOMIC)
174 set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
176 set(EXTRA_LIBS atomic ${EXTRA_LIBS})
178 unset(OLD_REQUIRED_LIBRARIES)
180 # Include liblog for Android logging
181 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
183 set(EXTRA_LIBS log ${EXTRA_LIBS})
184 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
188 set(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
189 check_cxx_compiler_flag(/permissive- HAVE_PERMISSIVE_SWITCH)
190 if(HAVE_PERMISSIVE_SWITCH)
191 set(C_FLAGS ${C_FLAGS} $<$<COMPILE_LANGUAGE:CXX>:/permissive->)
193 set(C_FLAGS ${C_FLAGS} /W4 /w14640 /wd4065 /wd4268 /wd4324 /wd5030)
196 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
198 string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
201 message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
204 option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
205 if(FORCE_STATIC_VCRT)
207 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
208 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
209 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
210 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
211 if(${flag_var} MATCHES "/MD")
212 string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
217 set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
219 $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
222 set(C_FLAGS ${C_FLAGS} -Werror)
225 # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
227 foreach(flag_var CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
228 if(${flag_var} MATCHES "-DNDEBUG")
229 string(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
233 check_c_compiler_flag(-fno-math-errno HAVE_FNO_MATH_ERRNO)
234 if(HAVE_FNO_MATH_ERRNO)
235 set(C_FLAGS ${C_FLAGS} -fno-math-errno)
238 option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
239 if(ALSOFT_STATIC_LIBGCC)
240 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
241 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
242 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBGCC_SWITCH)
243 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
244 unset(OLD_REQUIRED_LIBRARIES)
246 if(NOT HAVE_STATIC_LIBGCC_SWITCH)
247 message(FATAL_ERROR "Cannot static link libgcc")
249 set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
252 option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
253 if(ALSOFT_STATIC_STDCXX)
254 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
255 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
256 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBSTDCXX_SWITCH)
257 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
258 unset(OLD_REQUIRED_LIBRARIES)
260 if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
261 message(FATAL_ERROR "Cannot static link libstdc++")
263 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
267 option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
268 if(ALSOFT_STATIC_WINPTHREAD)
269 set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
270 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
271 check_cxx_source_compiles("int main() { }" HAVE_STATIC_LIBWINPTHREAD_SWITCH)
272 set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
273 unset(OLD_REQUIRED_LIBRARIES)
275 if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
276 message(FATAL_ERROR "Cannot static link libwinpthread")
278 set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
283 # Set visibility/export options if available
285 if(NOT LIBTYPE STREQUAL "STATIC")
286 set(EXPORT_DECL "__declspec(dllexport)")
289 set(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
290 # Yes GCC, really don't accept visibility modes you don't support
291 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
293 check_c_source_compiles("int foo() __attribute__((visibility(\"protected\")));
294 int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
295 if(HAVE_GCC_PROTECTED_VISIBILITY)
296 if(NOT LIBTYPE STREQUAL "STATIC")
297 set(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
300 check_c_source_compiles("int foo() __attribute__((visibility(\"default\")));
301 int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
302 if(HAVE_GCC_DEFAULT_VISIBILITY)
303 if(NOT LIBTYPE STREQUAL "STATIC")
304 set(EXPORT_DECL "__attribute__((visibility(\"default\")))")
309 if(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
310 check_c_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
311 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
312 set(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
316 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
322 set(SSE4_1_SWITCH "")
323 set(FPU_NEON_SWITCH "")
325 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
327 # Yes GCC, really don't accept command line options you don't support
328 set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
330 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
331 if(HAVE_MSSE2_SWITCH)
332 set(SSE2_SWITCH "-msse2")
333 check_c_compiler_flag(-msse3 HAVE_MSSE3_SWITCH)
334 if(HAVE_MSSE3_SWITCH)
335 set(SSE3_SWITCH "-msse3")
336 check_c_compiler_flag(-msse4.1 HAVE_MSSE4_1_SWITCH)
337 if(HAVE_MSSE4_1_SWITCH)
338 set(SSE4_1_SWITCH "-msse4.1")
342 check_c_compiler_flag(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
343 if(HAVE_MFPU_NEON_SWITCH)
344 set(FPU_NEON_SWITCH "-mfpu=neon")
346 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
347 unset(OLD_REQUIRED_FLAGS)
349 check_include_file(xmmintrin.h HAVE_XMMINTRIN_H ${SSE2_SWITCH})
350 check_include_file(emmintrin.h HAVE_EMMINTRIN_H ${SSE2_SWITCH})
351 check_include_file(pmmintrin.h HAVE_PMMINTRIN_H ${SSE3_SWITCH})
352 check_include_file(smmintrin.h HAVE_SMMINTRIN_H ${SSE4_1_SWITCH})
353 check_include_file(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
357 if(CMAKE_SIZEOF_VOID_P MATCHES "4" AND (SSE2_SWITCH OR MSVC))
358 option(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
359 if(ALSOFT_ENABLE_SSE2_CODEGEN)
361 check_c_compiler_flag("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
362 if(HAVE_MFPMATH_SSE_2)
363 set(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
364 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
367 # SSE depends on a 16-byte aligned stack, and by default, GCC
368 # assumes the stack is suitably aligned. Older Linux code or other
369 # OSs don't guarantee this on 32-bit, so externally-callable
370 # functions need to ensure an aligned stack.
371 set(EXPORT_DECL "${EXPORT_DECL} __attribute__((force_align_arg_pointer))")
373 check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
375 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
376 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
384 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
385 foreach(flag_var ${SSE_FLAGS})
386 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
389 check_c_source_compiles("#include <emmintrin.h>
390 int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
392 set(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
396 check_include_file(malloc.h HAVE_MALLOC_H)
397 check_include_file(cpuid.h HAVE_CPUID_H)
398 check_include_file(intrin.h HAVE_INTRIN_H)
399 check_include_file(guiddef.h HAVE_GUIDDEF_H)
400 if(NOT HAVE_GUIDDEF_H)
401 check_include_file(initguid.h HAVE_INITGUID_H)
404 # Some systems need libm for some math functions to work
406 check_library_exists(m pow "" HAVE_LIBM)
408 set(MATH_LIB ${MATH_LIB} m)
409 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
412 # Some systems need to link with -lrt for clock_gettime as used by the common
415 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
420 # Check for the dlopen API (for dynamicly loading backend libs)
422 check_include_file(dlfcn.h HAVE_DLFCN_H)
423 check_library_exists(dl dlopen "" HAVE_LIBDL)
425 set(EXTRA_LIBS dl ${EXTRA_LIBS})
426 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
430 # Check for a cpuid intrinsic
432 check_c_source_compiles("#include <cpuid.h>
435 unsigned int eax, ebx, ecx, edx;
436 return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
437 }" HAVE_GCC_GET_CPUID)
440 check_c_source_compiles("#include <intrin.h>
446 }" HAVE_CPUID_INTRINSIC)
449 check_cxx_source_compiles("#include <cstdlib>
452 void *ptr{std::aligned_alloc(alignof(int), sizeof(int))};
455 }" HAVE_STD_ALIGNED_ALLOC)
456 check_symbol_exists(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
457 check_symbol_exists(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
458 check_symbol_exists(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
461 # We need pthreads outside of Windows, for semaphores. It's also used to
462 # set the priority and name of threads, when possible.
463 check_include_file(pthread.h HAVE_PTHREAD_H)
464 if(NOT HAVE_PTHREAD_H)
465 message(FATAL_ERROR "PThreads is required for non-Windows builds!")
468 check_c_compiler_flag(-pthread HAVE_PTHREAD)
470 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
471 set(C_FLAGS ${C_FLAGS} -pthread)
472 set(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
475 check_symbol_exists(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
477 # Some systems need pthread_np.h to get pthread_setname_np
478 check_include_files("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
479 if(HAVE_PTHREAD_NP_H)
480 check_symbol_exists(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
481 if(NOT HAVE_PTHREAD_SETNAME_NP)
482 check_symbol_exists(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
484 check_c_source_compiles("
486 #include <pthread_np.h>
489 pthread_setname_np(\"testname\");
492 PTHREAD_SETNAME_NP_ONE_PARAM
494 check_c_source_compiles("
496 #include <pthread_np.h>
499 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
502 PTHREAD_SETNAME_NP_THREE_PARAMS
506 check_symbol_exists(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
507 if(NOT HAVE_PTHREAD_SETNAME_NP)
508 check_symbol_exists(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
510 check_c_source_compiles("
514 pthread_setname_np(\"testname\");
517 PTHREAD_SETNAME_NP_ONE_PARAM
519 check_c_source_compiles("
523 pthread_setname_np(pthread_self(), \"%s\", \"testname\");
526 PTHREAD_SETNAME_NP_THREE_PARAMS
532 check_symbol_exists(getopt unistd.h HAVE_GETOPT)
535 # Common sources used by both the OpenAL implementation library and potentially
556 common/intrusive_ptr.h
559 common/polyphase_resampler.cpp
560 common/polyphase_resampler.h
614 alc/effects/autowah.cpp
615 alc/effects/chorus.cpp
616 alc/effects/compressor.cpp
617 alc/effects/dedicated.cpp
618 alc/effects/distortion.cpp
620 alc/effects/equalizer.cpp
621 alc/effects/fshifter.cpp
622 alc/effects/modulator.cpp
624 alc/effects/pshifter.cpp
625 alc/effects/reverb.cpp
626 alc/effects/vmorpher.cpp
628 alc/filters/biquad.cpp
631 alc/filters/splitter.cpp
632 alc/filters/splitter.h
635 alc/front_stablizer.h
653 alc/mixer/mixer_c.cpp
657 set(CPU_EXTS "Default")
664 # Check for SSE+SSE2 support
665 option(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
666 option(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
667 if(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
668 option(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
669 option(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
670 if(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
673 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
675 set_source_files_properties(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
676 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
678 set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
681 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
682 message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
684 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
685 message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
688 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
690 option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
691 if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
693 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
695 set_source_files_properties(alc/mixer/mixer_sse3.cpp PROPERTIES
696 COMPILE_FLAGS "${SSE3_SWITCH}")
698 set(CPU_EXTS "${CPU_EXTS}, SSE3")
701 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
702 message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
705 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
707 option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
708 if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
710 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
712 set_source_files_properties(alc/mixer/mixer_sse41.cpp PROPERTIES
713 COMPILE_FLAGS "${SSE4_1_SWITCH}")
715 set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
718 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
719 message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
722 # Check for ARM Neon support
723 option(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
725 option(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
726 if(ALSOFT_CPUEXT_NEON)
728 set(ALC_OBJS ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
730 set_source_files_properties(alc/mixer/mixer_neon.cpp PROPERTIES
731 COMPILE_FLAGS "${FPU_NEON_SWITCH}")
733 set(CPU_EXTS "${CPU_EXTS}, Neon")
736 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
737 message(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
748 set(HAVE_PORTAUDIO 0)
749 set(HAVE_PULSEAUDIO 0)
750 set(HAVE_COREAUDIO 0)
756 if(WIN32 OR HAVE_DLFCN_H)
758 macro(ADD_BACKEND_LIBS _LIBS)
761 set(IS_LINKED " (linked)")
762 macro(ADD_BACKEND_LIBS _LIBS)
763 set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
768 set(ALC_OBJS ${ALC_OBJS}
769 alc/backends/base.cpp
771 # Default backends, always available
772 alc/backends/loopback.cpp
773 alc/backends/loopback.h
774 alc/backends/null.cpp
779 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
782 option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
783 if(ALSOFT_BACKEND_ALSA)
785 set(BACKENDS "${BACKENDS} ALSA${IS_LINKED},")
786 set(ALC_OBJS ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
787 add_backend_libs(${ALSA_LIBRARIES})
788 set(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
791 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
792 message(FATAL_ERROR "Failed to enabled required ALSA backend")
796 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
799 option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
800 if(ALSOFT_BACKEND_OSS)
802 set(BACKENDS "${BACKENDS} OSS,")
803 set(ALC_OBJS ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
805 set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
807 set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
810 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
811 message(FATAL_ERROR "Failed to enabled required OSS backend")
814 # Check Solaris backend
815 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
816 find_package(AudioIO)
818 option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
819 if(ALSOFT_BACKEND_SOLARIS)
821 set(BACKENDS "${BACKENDS} Solaris,")
822 set(ALC_OBJS ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
823 set(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
826 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
827 message(FATAL_ERROR "Failed to enabled required Solaris backend")
830 # Check SndIO backend
831 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
832 find_package(SoundIO)
834 option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
835 if(ALSOFT_BACKEND_SNDIO)
837 set(BACKENDS "${BACKENDS} SndIO (linked),")
838 set(ALC_OBJS ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
839 set(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
840 set(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
843 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
844 message(FATAL_ERROR "Failed to enabled required SndIO backend")
847 # Check Windows-only backends
848 option(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
849 option(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
850 option(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
852 set(WINSDK_LIB_DIRS )
853 set(WINSDK_INCLUDE_DIRS )
854 find_package(WindowsSDK)
856 get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
857 get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
860 # Check MMSystem backend
861 check_include_files("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
862 find_library(WINMM_LIBRARY NAMES winmm
863 PATHS ${WINSDK_LIB_DIRS})
864 if(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
865 option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
866 if(ALSOFT_BACKEND_WINMM)
868 set(BACKENDS "${BACKENDS} WinMM,")
869 set(ALC_OBJS ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
870 set(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
874 # Check DSound backend
877 option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
878 if(ALSOFT_BACKEND_DSOUND)
880 set(BACKENDS "${BACKENDS} DirectSound${IS_LINKED},")
881 set(ALC_OBJS ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
882 add_backend_libs(${DSOUND_LIBRARIES})
883 set(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
887 # Check for WASAPI backend
888 check_include_file(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
889 if(HAVE_MMDEVICEAPI_H)
890 option(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
891 if(ALSOFT_BACKEND_WASAPI)
893 set(BACKENDS "${BACKENDS} WASAPI,")
894 set(ALC_OBJS ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
898 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
899 message(FATAL_ERROR "Failed to enabled required WinMM backend")
901 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
902 message(FATAL_ERROR "Failed to enabled required DSound backend")
904 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
905 message(FATAL_ERROR "Failed to enabled required WASAPI backend")
908 # Check PortAudio backend
909 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
910 find_package(PortAudio)
912 option(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
913 if(ALSOFT_BACKEND_PORTAUDIO)
914 set(HAVE_PORTAUDIO 1)
915 set(BACKENDS "${BACKENDS} PortAudio${IS_LINKED},")
916 set(ALC_OBJS ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
917 add_backend_libs(${PORTAUDIO_LIBRARIES})
918 set(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
921 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
922 message(FATAL_ERROR "Failed to enabled required PortAudio backend")
925 # Check PulseAudio backend
926 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
927 find_package(PulseAudio)
929 option(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
930 if(ALSOFT_BACKEND_PULSEAUDIO)
931 set(HAVE_PULSEAUDIO 1)
932 set(BACKENDS "${BACKENDS} PulseAudio${IS_LINKED},")
933 set(ALC_OBJS ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
934 add_backend_libs(${PULSEAUDIO_LIBRARIES})
935 set(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
938 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
939 message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
943 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
946 option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
947 if(ALSOFT_BACKEND_JACK)
949 set(BACKENDS "${BACKENDS} JACK${IS_LINKED},")
950 set(ALC_OBJS ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
951 add_backend_libs(${JACK_LIBRARIES})
952 set(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
955 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
956 message(FATAL_ERROR "Failed to enabled required JACK backend")
959 # Check CoreAudio backend
960 option(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
961 find_library(COREAUDIO_FRAMEWORK NAMES CoreAudio)
962 find_path(AUDIOUNIT_INCLUDE_DIR NAMES AudioUnit/AudioUnit.h)
963 if(COREAUDIO_FRAMEWORK AND AUDIOUNIT_INCLUDE_DIR)
964 option(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
965 if(ALSOFT_BACKEND_COREAUDIO)
966 set(HAVE_COREAUDIO 1)
967 set(ALC_OBJS ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
968 set(BACKENDS "${BACKENDS} CoreAudio,")
969 if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
970 find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation)
971 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${EXTRA_LIBS})
973 set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
974 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
977 # Some versions of OSX may need the AudioToolbox framework. Add it if
979 find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
980 if(AUDIOTOOLBOX_LIBRARY)
981 set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
984 set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
987 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
988 message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
991 # Check for OpenSL (Android) backend
992 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
995 option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
996 if(ALSOFT_BACKEND_OPENSL)
998 set(ALC_OBJS ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
999 set(BACKENDS "${BACKENDS} OpenSL,")
1000 set(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1001 set(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1004 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1005 message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1008 # Check for Oboe (Android) backend
1011 set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1013 # Force Oboe to build with hidden symbols. Don't want to be exporting
1015 set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS})
1016 check_cxx_compiler_flag(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
1017 if(HAVE_VISIBILITY_HIDDEN_SWITCH)
1018 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
1020 add_subdirectory(${OBOE_SOURCE} ./oboe)
1021 set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1022 unset(OLD_CXX_FLAGS)
1024 set(OBOE_TARGET oboe)
1028 set(OBOE_TARGET "oboe::oboe")
1033 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1035 option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1036 if(ALSOFT_BACKEND_OBOE)
1038 set(ALC_OBJS ${ALC_OBJS} alc/backends/oboe.cpp alc/backends/oboe.h)
1039 set(BACKENDS "${BACKENDS} Oboe,")
1040 set(EXTRA_LIBS ${OBOE_TARGET} ${EXTRA_LIBS})
1043 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1044 message(FATAL_ERROR "Failed to enabled required Oboe backend")
1047 # Check for SDL2 backend
1048 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1051 # Off by default, since it adds a runtime dependency
1052 option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1053 if(ALSOFT_BACKEND_SDL2)
1055 set(ALC_OBJS ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1056 set(BACKENDS "${BACKENDS} SDL2,")
1057 set(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1058 set(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1061 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1062 message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1065 # Optionally enable the Wave Writer backend
1066 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1067 if(ALSOFT_BACKEND_WAVE)
1069 set(ALC_OBJS ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1070 set(BACKENDS "${BACKENDS} WaveFile,")
1073 # This is always available
1074 set(BACKENDS "${BACKENDS} Null")
1078 if(ALSOFT_UPDATE_BUILD_VERSION AND GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1079 # Get the current working branch and its latest abbreviated commit hash
1080 add_custom_target(build_version
1081 ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE} -D LIB_VERSION=${LIB_VERSION}
1082 -D LIB_VERSION_NUM=${LIB_VERSION_NUM} -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1083 -D DST=${OpenAL_BINARY_DIR}/version.h -P ${OpenAL_SOURCE_DIR}/version.cmake
1084 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1088 set(GIT_BRANCH "UNKNOWN")
1089 set(GIT_COMMIT_HASH "unknown")
1091 "${OpenAL_SOURCE_DIR}/version.h.in"
1092 "${OpenAL_BINARY_DIR}/version.h")
1096 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1097 if(ALSOFT_EMBED_HRTF_DATA)
1098 macro(make_hrtf_header FILENAME VARNAME)
1099 set(infile "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1100 set(outfile "${OpenAL_BINARY_DIR}/${VARNAME}.h")
1102 add_custom_command(OUTPUT "${outfile}"
1103 COMMAND ${CMAKE_COMMAND} -D "INPUT_FILE=${infile}" -D "OUTPUT_FILE=${outfile}"
1104 -D "VARIABLE_NAME=${VARNAME}" -P "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1105 WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1106 DEPENDS "${infile}" "${CMAKE_MODULE_PATH}/bin2h.script.cmake"
1109 set(ALC_OBJS ${ALC_OBJS} "${outfile}")
1112 make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1116 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1117 find_package(Qt5Widgets)
1120 find_package(SndFile)
1123 find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1128 set(LIBNAME "openal")
1130 set(LIBNAME "OpenAL32")
1133 # Needed for openal.pc.in
1134 set(prefix ${CMAKE_INSTALL_PREFIX})
1135 set(exec_prefix "\${prefix}")
1136 set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1137 set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1138 set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1139 set(PACKAGE_VERSION "${LIB_VERSION}")
1140 set(PKG_CONFIG_CFLAGS )
1141 set(PKG_CONFIG_PRIVATE_LIBS )
1142 if(LIBTYPE STREQUAL "STATIC")
1143 set(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1144 foreach(FLAG ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1145 # If this is already a linker flag, or is a full path+file, add it
1146 # as-is. Otherwise, it's a name intended to be dressed as -lname.
1147 if(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1148 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1150 set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1157 "${OpenAL_SOURCE_DIR}/config.h.in"
1158 "${OpenAL_BINARY_DIR}/config.h")
1160 "${OpenAL_SOURCE_DIR}/openal.pc.in"
1161 "${OpenAL_BINARY_DIR}/openal.pc"
1165 add_library(common STATIC EXCLUDE_FROM_ALL ${COMMON_OBJS})
1166 target_include_directories(common PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/include)
1167 target_compile_definitions(common PRIVATE ${CPP_DEFS})
1168 target_compile_options(common PRIVATE ${C_FLAGS})
1169 set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
1173 set(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1175 # Build main library
1176 if(LIBTYPE STREQUAL "STATIC")
1177 add_library(${IMPL_TARGET} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1178 target_compile_definitions(${IMPL_TARGET} PUBLIC AL_LIBTYPE_STATIC)
1179 target_link_libraries(${IMPL_TARGET} PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1181 # This option is for static linking OpenAL Soft into another project
1182 # that already defines the IDs. It is up to that project to ensure all
1183 # required IDs are defined.
1184 option(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
1185 if(ALSOFT_NO_UID_DEFS)
1186 target_compile_definitions(${IMPL_TARGET} PRIVATE AL_NO_UID_DEFS)
1190 set(RC_CONFIG resources/openal32.rc)
1191 if(WIN32 AND ALSOFT_BUILD_ROUTER)
1192 add_library(OpenAL SHARED
1199 target_compile_definitions(OpenAL
1200 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1201 target_compile_options(OpenAL PRIVATE ${C_FLAGS})
1202 target_link_libraries(OpenAL PRIVATE common ${LINKER_FLAGS})
1203 target_include_directories(OpenAL
1205 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1206 $<INSTALL_INTERFACE:include>
1208 ${OpenAL_SOURCE_DIR}/common
1209 ${OpenAL_BINARY_DIR}
1211 set_target_properties(OpenAL PROPERTIES PREFIX "")
1212 set_target_properties(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1213 if(TARGET build_version)
1214 add_dependencies(OpenAL build_version)
1218 set(LIBNAME "soft_oal")
1219 set(IMPL_TARGET soft_oal)
1220 set(RC_CONFIG resources/soft_oal.rc)
1223 add_library(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG})
1225 set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1227 target_link_libraries(${IMPL_TARGET} PRIVATE common ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1230 target_include_directories(${IMPL_TARGET}
1232 $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1233 $<INSTALL_INTERFACE:include>
1236 ${OpenAL_BINARY_DIR}
1237 ${OpenAL_SOURCE_DIR}
1238 ${OpenAL_SOURCE_DIR}/alc
1239 ${OpenAL_SOURCE_DIR}/common
1242 set_target_properties(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1243 VERSION ${LIB_VERSION}
1244 SOVERSION ${LIB_MAJOR_VERSION}
1246 target_compile_definitions(${IMPL_TARGET}
1247 PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1248 target_compile_options(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1250 if(TARGET build_version)
1251 add_dependencies(${IMPL_TARGET} build_version)
1254 if(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1255 find_program(SED_EXECUTABLE NAMES sed DOC "sed executable")
1256 find_program(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1257 if(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1259 if(NOT SED_EXECUTABLE)
1260 message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1262 if(NOT DLLTOOL_EXECUTABLE)
1263 message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1266 set_property(TARGET OpenAL APPEND_STRING PROPERTY
1267 LINK_FLAGS " -Wl,--output-def,OpenAL32.def")
1268 add_custom_command(TARGET OpenAL POST_BUILD
1269 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1270 COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1271 COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1279 message(STATUS "Building DLL router")
1283 Building OpenAL with support for the following backends:
1286 Building with support for CPU extensions:
1290 message(STATUS "Building with SSE${FPMATH_SET} codegen
1294 if(ALSOFT_EMBED_HRTF_DATA)
1295 message(STATUS "Embedding HRTF datasets
1299 # Install main library
1301 install(TARGETS OpenAL EXPORT OpenAL
1302 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1303 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1304 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1305 INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL)
1306 export(TARGETS OpenAL
1308 FILE OpenALConfig.cmake)
1309 install(EXPORT OpenAL
1310 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1312 FILE OpenALConfig.cmake)
1313 install(DIRECTORY include/AL
1314 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1315 install(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1316 DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1318 install(TARGETS soft_oal
1319 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1321 message(STATUS "Installing library and headers")
1323 message(STATUS "NOT installing library and headers")
1326 if(ALSOFT_INSTALL_CONFIG)
1327 install(FILES alsoftrc.sample
1328 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1329 message(STATUS "Installing sample configuration")
1332 if(ALSOFT_INSTALL_HRTF_DEFS)
1333 install(DIRECTORY hrtf
1334 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1335 message(STATUS "Installing HRTF definitions")
1338 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1339 install(DIRECTORY presets
1340 DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1341 message(STATUS "Installing AmbDec presets")
1347 set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1349 set(EXTRA_INSTALLS )
1351 add_executable(openal-info utils/openal-info.c)
1352 target_include_directories(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1353 target_compile_options(openal-info PRIVATE ${C_FLAGS})
1354 target_link_libraries(openal-info PRIVATE ${LINKER_FLAGS} OpenAL ${UNICODE_FLAG})
1355 if(ALSOFT_INSTALL_EXAMPLES)
1356 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} openal-info)
1359 find_package(MySOFA)
1361 set(SOFA_SUPPORT_SRCS
1362 utils/sofa-support.cpp
1363 utils/sofa-support.h)
1364 add_library(sofa-support STATIC EXCLUDE_FROM_ALL ${SOFA_SUPPORT_SRCS})
1365 target_compile_definitions(sofa-support PRIVATE ${CPP_DEFS})
1366 target_include_directories(sofa-support PUBLIC ${OpenAL_SOURCE_DIR}/common)
1367 target_compile_options(sofa-support PRIVATE ${C_FLAGS})
1368 target_link_libraries(sofa-support PUBLIC common MySOFA::MySOFA PRIVATE ${LINKER_FLAGS})
1371 utils/makemhr/loaddef.cpp
1372 utils/makemhr/loaddef.h
1373 utils/makemhr/loadsofa.cpp
1374 utils/makemhr/loadsofa.h
1375 utils/makemhr/makemhr.cpp
1376 utils/makemhr/makemhr.h)
1378 set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1380 add_executable(makemhr ${MAKEMHR_SRCS})
1381 target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1382 target_include_directories(makemhr
1383 PRIVATE ${OpenAL_BINARY_DIR} ${OpenAL_SOURCE_DIR}/utils)
1384 target_compile_options(makemhr PRIVATE ${C_FLAGS})
1385 target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1386 if(ALSOFT_INSTALL_EXAMPLES)
1387 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} makemhr)
1390 set(SOFAINFO_SRCS utils/sofa-info.cpp)
1391 add_executable(sofa-info ${SOFAINFO_SRCS})
1392 target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1393 target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/utils)
1394 target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1395 target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} sofa-support ${UNICODE_FLAG})
1397 message(STATUS "Building utility programs")
1399 if(NOT ALSOFT_NO_CONFIG_UTIL)
1400 add_subdirectory(utils/alsoft-config)
1406 # Add a static library with common functions used by multiple example targets
1407 add_library(ex-common STATIC EXCLUDE_FROM_ALL
1408 examples/common/alhelpers.c
1409 examples/common/alhelpers.h)
1410 target_compile_definitions(ex-common PUBLIC ${CPP_DEFS})
1411 target_include_directories(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1412 target_compile_options(ex-common PUBLIC ${C_FLAGS})
1413 target_link_libraries(ex-common PUBLIC OpenAL PRIVATE ${RT_LIB})
1416 add_executable(altonegen examples/altonegen.c)
1417 target_link_libraries(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common ${UNICODE_FLAG})
1419 add_executable(alrecord examples/alrecord.c)
1420 target_link_libraries(alrecord PRIVATE ${LINKER_FLAGS} ex-common ${UNICODE_FLAG})
1422 if(ALSOFT_INSTALL_EXAMPLES)
1423 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} altonegen alrecord)
1426 message(STATUS "Building example programs")
1429 add_executable(alplay examples/alplay.c)
1430 target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1433 add_executable(alstream examples/alstream.c)
1434 target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1437 add_executable(alreverb examples/alreverb.c)
1438 target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1441 add_executable(almultireverb examples/almultireverb.c)
1442 target_link_libraries(almultireverb
1443 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1445 add_executable(allatency examples/allatency.c)
1446 target_link_libraries(allatency PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1449 add_executable(alhrtf examples/alhrtf.c)
1450 target_link_libraries(alhrtf
1451 PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common ${MATH_LIB} ${UNICODE_FLAG})
1453 add_executable(alstreamcb examples/alstreamcb.cpp)
1454 target_link_libraries(alstreamcb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1457 if(ALSOFT_INSTALL_EXAMPLES)
1458 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1462 message(STATUS "Building SndFile example programs")
1466 add_executable(alloopback examples/alloopback.c)
1467 target_include_directories(alloopback PRIVATE ${SDL2_INCLUDE_DIR})
1468 target_link_libraries(alloopback
1469 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1471 if(ALSOFT_INSTALL_EXAMPLES)
1472 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alloopback)
1475 message(STATUS "Building SDL example programs")
1480 if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1481 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1484 if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1485 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1488 if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1489 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1492 if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1493 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1496 if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1497 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1502 add_executable(alffplay examples/alffplay.cpp)
1503 target_include_directories(alffplay
1504 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1505 target_link_libraries(alffplay
1506 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1508 if(ALSOFT_INSTALL_EXAMPLES)
1509 set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alffplay)
1511 message(STATUS "Building SDL+FFmpeg example programs")
1518 install(TARGETS ${EXTRA_INSTALLS}
1519 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1520 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1521 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})