Release 1.21.1
[openal-soft.git] / CMakeLists.txt
blob0cf0613d65d2d36425308128e566f700de812fd8
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
14 # report:
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
18 # deployment target
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"
25                 FORCE)
26         endif()
27     endif()
28 endif()
30 project(OpenAL)
32 if(COMMAND CMAKE_POLICY)
33     cmake_policy(SET CMP0003 NEW)
34     cmake_policy(SET CMP0005 NEW)
35     if(POLICY CMP0020)
36         cmake_policy(SET CMP0020 NEW)
37     endif(POLICY CMP0020)
38     if(POLICY CMP0042)
39         cmake_policy(SET CMP0042 NEW)
40     endif(POLICY CMP0042)
41     if(POLICY CMP0054)
42         cmake_policy(SET CMP0054 NEW)
43     endif(POLICY CMP0054)
44     if(POLICY CMP0075)
45         cmake_policy(SET CMP0075 NEW)
46     endif(POLICY CMP0075)
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."
52         FORCE)
53 endif()
54 if(NOT CMAKE_DEBUG_POSTFIX)
55     set(CMAKE_DEBUG_POSTFIX "" CACHE STRING
56         "Library postfix for debug builds. Normally left blank."
57         FORCE)
58 endif()
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}")
95 endif()
97 if(DEFINED LIB_SUFFIX)
98     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
99 endif()
100 if(DEFINED ALSOFT_CONFIG)
101     message(WARNING "ALSOFT_CONFIG is deprecated. Use ALSOFT_INSTALL_CONFIG instead")
102 endif()
103 if(DEFINED ALSOFT_HRTF_DEFS)
104     message(WARNING "ALSOFT_HRTF_DEFS is deprecated. Use ALSOFT_INSTALL_HRTF_DATA instead")
105 endif()
106 if(DEFINED ALSOFT_AMBDEC_PRESETS)
107     message(WARNING "ALSOFT_AMBDEC_PRESETS is deprecated. Use ALSOFT_INSTALL_AMBDEC_PRESETS instead")
108 endif()
111 set(CPP_DEFS ) # C pre-processor, not C++
112 set(INC_PATHS )
113 set(C_FLAGS )
114 set(LINKER_FLAGS )
115 set(EXTRA_LIBS )
117 if(WIN32)
118     set(CPP_DEFS ${CPP_DEFS} _WIN32)
119     if(MINGW)
120         set(CPP_DEFS ${CPP_DEFS} __USE_MINGW_ANSI_STDIO)
121     endif()
123     option(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
124     if(MINGW)
125         option(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
126     endif()
127 elseif(APPLE)
128     option(ALSOFT_OSX_FRAMEWORK "Build as macOS framework" OFF)
129 endif()
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)
136 endif()
138 # When the library is built for static linking, apps should define
139 # AL_LIBTYPE_STATIC when including the AL headers.
140 if(NOT LIBTYPE)
141     set(LIBTYPE SHARED)
142 endif()
144 set(LIB_MAJOR_VERSION "1")
145 set(LIB_MINOR_VERSION "21")
146 set(LIB_REVISION "1")
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)
150 set(EXPORT_DECL "")
153 # Require C++14
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)
160 if(NOT WIN32)
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})
169         else()
170             set(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
171         endif()
172     endif()
173     unset(OLD_REQUIRED_FLAGS)
174 endif()
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)
179 if(HAVE___RESTRICT)
180     set(CPP_DEFS ${CPP_DEFS} RESTRICT=__restrict)
181 else()
182     set(CPP_DEFS ${CPP_DEFS} "RESTRICT=")
183 endif()
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); }"
191 HAVE_LIBATOMIC)
192 if(NOT HAVE_LIBATOMIC)
193     set(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
194 else()
195     set(EXTRA_LIBS atomic ${EXTRA_LIBS})
196 endif()
197 unset(OLD_REQUIRED_LIBRARIES)
199 # Include liblog for Android logging
200 check_library_exists(log __android_log_print "" HAVE_LIBLOG)
201 if(HAVE_LIBLOG)
202     set(EXTRA_LIBS log ${EXTRA_LIBS})
203     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
204 endif()
206 if(MSVC)
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->)
211     endif()
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}}")
218         endif()
219     endforeach()
221     if(NOT DXSDK_DIR)
222         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
223     else()
224         string(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
225     endif()
226     if(DXSDK_DIR)
227         message(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
228     endif()
230     option(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
231     if(FORCE_STATIC_VCRT)
232         foreach(flag_var
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}}")
239             endif()
240         endforeach(flag_var)
241     endif()
242 else()
243     set(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align
244         -Wpedantic
245         $<$<COMPILE_LANGUAGE:CXX>:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>)
247     if(ALSOFT_WERROR)
248         set(C_FLAGS ${C_FLAGS} -Werror)
249     endif()
251     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
252     # instead of NDEBUG)
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}}")
256         endif()
257     endforeach()
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)
262     endif()
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")
274         endif()
275         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
276     endif()
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++")
288         endif()
289         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
290     endif()
292     if(WIN32)
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")
303             endif()
304             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
305         endif()
306     endif()
307 endif()
309 # Set visibility/export options if available
310 if(WIN32)
311     if(NOT LIBTYPE STREQUAL "STATIC")
312         set(EXPORT_DECL "__declspec(dllexport)")
313     endif()
314 else()
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\")))")
324         endif()
325     else()
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\")))")
331             endif()
332         endif()
333     endif()
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)
339         endif()
340     endif()
342     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
343 endif()
346 set(SSE2_SWITCH "")
348 set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
349 if(NOT MSVC)
350     # Yes GCC, really don't accept command line options you don't support
351     set(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
352 endif()
353 check_c_compiler_flag(-msse2 HAVE_MSSE2_SWITCH)
354 if(HAVE_MSSE2_SWITCH)
355     set(SSE2_SWITCH "-msse2")
356 endif()
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)
366 set(HAVE_SSE        0)
367 set(HAVE_SSE2       0)
368 set(HAVE_SSE3       0)
369 set(HAVE_SSE4_1     0)
370 set(HAVE_NEON       0)
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)
379         set(HAVE_SSE 1)
380         set(HAVE_SSE2 1)
381     endif()
382 endif()
383 if(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
384     message(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
385 endif()
386 if(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
387     message(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
388 endif()
390 option(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
391 if(HAVE_PMMINTRIN_H)
392     option(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
393     if(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
394         set(HAVE_SSE3 1)
395     endif()
396 endif()
397 if(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
398     message(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
399 endif()
401 option(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
402 if(HAVE_SMMINTRIN_H)
403     option(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
404     if(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
405         set(HAVE_SSE4_1 1)
406     endif()
407 endif()
408 if(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
409     message(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
410 endif()
412 # Check for ARM Neon support
413 option(ALSOFT_REQUIRE_NEON "Require ARM NEON support" OFF)
414 if(HAVE_ARM_NEON_H)
415     option(ALSOFT_CPUEXT_NEON "Enable ARM NEON support" ON)
416     if(ALSOFT_CPUEXT_NEON)
417         check_c_source_compiles("#include <arm_neon.h>
418             int main()
419             {
420                 int32x4_t ret4 = vdupq_n_s32(0);
421                 return vgetq_lane_s32(ret4, 0);
422             }" HAVE_NEON_INTRINSICS)
423         if(HAVE_NEON_INTRINSICS)
424             set(HAVE_NEON 1)
425         endif()
426     endif()
427 endif()
428 if(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
429     message(FATAL_ERROR "Failed to enabled required ARM NEON CPU extensions")
430 endif()
433 set(SSE_FLAGS )
434 set(FPMATH_SET "0")
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})
443                 set(FPMATH_SET 2)
444             endif()
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))")
450         elseif(MSVC)
451             check_c_compiler_flag("/arch:SSE2" HAVE_ARCH_SSE2)
452             if(HAVE_ARCH_SSE2)
453                 set(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
454                 set(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
455                 set(FPMATH_SET 2)
456             endif()
457         endif()
458     endif()
459 endif()
461 if(HAVE_SSE2)
462     set(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
463     foreach(flag_var ${SSE_FLAGS})
464         set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
465     endforeach()
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})
471 endif()
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)
480 endif()
482 # Some systems need libm for some math functions to work
483 set(MATH_LIB )
484 check_library_exists(m pow "" HAVE_LIBM)
485 if(HAVE_LIBM)
486     set(MATH_LIB ${MATH_LIB} m)
487     set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
488 endif()
490 # Some systems need to link with -lrt for clock_gettime as used by the common
491 # eaxmple functions.
492 set(RT_LIB )
493 check_library_exists(rt clock_gettime "" HAVE_LIBRT)
494 if(HAVE_LIBRT)
495     set(RT_LIB rt)
496 endif()
498 # Check for the dlopen API (for dynamicly loading backend libs)
499 if(ALSOFT_DLOPEN)
500     check_include_file(dlfcn.h HAVE_DLFCN_H)
501     check_library_exists(dl dlopen "" HAVE_LIBDL)
502     if(HAVE_LIBDL)
503         set(EXTRA_LIBS dl ${EXTRA_LIBS})
504         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
505     endif()
506 endif()
508 # Check for a cpuid intrinsic
509 if(HAVE_CPUID_H)
510     check_c_source_compiles("#include <cpuid.h>
511         int main()
512         {
513             unsigned int eax, ebx, ecx, edx;
514             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
515         }" HAVE_GCC_GET_CPUID)
516 endif()
517 if(HAVE_INTRIN_H)
518     check_c_source_compiles("#include <intrin.h>
519         int main()
520         {
521             int regs[4];
522             __cpuid(regs, 0);
523             return regs[0];
524         }" HAVE_CPUID_INTRINSIC)
525 endif()
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)
531 if(NOT WIN32)
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!")
537     endif()
539     check_c_compiler_flag(-pthread HAVE_PTHREAD)
540     if(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)
544     endif()
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)
554         else()
555             check_c_source_compiles("
556 #include <pthread.h>
557 #include <pthread_np.h>
558 int main()
560     pthread_setname_np(\"testname\");
561     return 0;
563                 PTHREAD_SETNAME_NP_ONE_PARAM
564             )
565             check_c_source_compiles("
566 #include <pthread.h>
567 #include <pthread_np.h>
568 int main()
570     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
571     return 0;
573                 PTHREAD_SETNAME_NP_THREE_PARAMS
574             )
575         endif()
576     else()
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)
580         else()
581             check_c_source_compiles("
582 #include <pthread.h>
583 int main()
585     pthread_setname_np(\"testname\");
586     return 0;
588                 PTHREAD_SETNAME_NP_ONE_PARAM
589             )
590             check_c_source_compiles("
591 #include <pthread.h>
592 int main()
594     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
595     return 0;
597                 PTHREAD_SETNAME_NP_THREE_PARAMS
598             )
599         endif()
600     endif()
601 endif()
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.
608 set(COMMON_OBJS
609     common/albit.h
610     common/albyte.h
611     common/alcomplex.cpp
612     common/alcomplex.h
613     common/aldeque.h
614     common/alfstream.cpp
615     common/alfstream.h
616     common/almalloc.cpp
617     common/almalloc.h
618     common/alnumeric.h
619     common/aloptional.h
620     common/alspan.h
621     common/alstring.cpp
622     common/alstring.h
623     common/atomic.h
624     common/dynload.cpp
625     common/dynload.h
626     common/intrusive_ptr.h
627     common/math_defs.h
628     common/opthelpers.h
629     common/polyphase_resampler.cpp
630     common/polyphase_resampler.h
631     common/pragmadefs.h
632     common/ringbuffer.cpp
633     common/ringbuffer.h
634     common/strutils.cpp
635     common/strutils.h
636     common/threads.cpp
637     common/threads.h
638     common/vecmat.h
639     common/vector.h)
641 # Core library routines
642 set(CORE_OBJS
643     core/ambdec.cpp
644     core/ambdec.h
645     core/ambidefs.h
646     core/bs2b.cpp
647     core/bs2b.h
648     core/bsinc_defs.h
649     core/bsinc_tables.cpp
650     core/bsinc_tables.h
651     core/bufferline.h
652     core/cpu_caps.cpp
653     core/cpu_caps.h
654     core/devformat.cpp
655     core/devformat.h
656     core/except.cpp
657     core/except.h
658     core/filters/biquad.h
659     core/filters/biquad.cpp
660     core/filters/nfc.cpp
661     core/filters/nfc.h
662     core/filters/splitter.cpp
663     core/filters/splitter.h
664     core/fmt_traits.cpp
665     core/fmt_traits.h
666     core/fpu_ctrl.cpp
667     core/fpu_ctrl.h
668     core/logging.cpp
669     core/logging.h
670     core/mastering.cpp
671     core/mastering.h
672     core/uhjfilter.cpp
673     core/uhjfilter.h
674     core/mixer/defs.h
675     core/mixer/hrtfbase.h
676     core/mixer/hrtfdefs.h
677     core/mixer/mixer_c.cpp)
679 # AL and related routines
680 set(OPENAL_OBJS
681     al/auxeffectslot.cpp
682     al/auxeffectslot.h
683     al/buffer.cpp
684     al/buffer.h
685     al/effect.cpp
686     al/effect.h
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
693     al/effects/echo.cpp
694     al/effects/effects.h
695     al/effects/equalizer.cpp
696     al/effects/fshifter.cpp
697     al/effects/modulator.cpp
698     al/effects/null.cpp
699     al/effects/pshifter.cpp
700     al/effects/reverb.cpp
701     al/effects/vmorpher.cpp
702     al/error.cpp
703     al/event.cpp
704     al/event.h
705     al/extension.cpp
706     al/filter.cpp
707     al/filter.h
708     al/listener.cpp
709     al/listener.h
710     al/source.cpp
711     al/source.h
712     al/state.cpp)
714 # ALC and related routines
715 set(ALC_OBJS
716     alc/alc.cpp
717     alc/alcmain.h
718     alc/alu.cpp
719     alc/alu.h
720     alc/alconfig.cpp
721     alc/alconfig.h
722     alc/alcontext.h
723     alc/async_event.h
724     alc/bformatdec.cpp
725     alc/bformatdec.h
726     alc/buffer_storage.cpp
727     alc/buffer_storage.h
728     alc/compat.h
729     alc/converter.cpp
730     alc/converter.h
731     alc/effectslot.cpp
732     alc/effectslot.h
733     alc/effects/base.h
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
740     alc/effects/echo.cpp
741     alc/effects/equalizer.cpp
742     alc/effects/fshifter.cpp
743     alc/effects/modulator.cpp
744     alc/effects/null.cpp
745     alc/effects/pshifter.cpp
746     alc/effects/reverb.cpp
747     alc/effects/vmorpher.cpp
748     alc/front_stablizer.h
749     alc/helpers.cpp
750     alc/hrtf.cpp
751     alc/hrtf.h
752     alc/inprogext.h
753     alc/panning.cpp
754     alc/uiddefs.cpp
755     alc/voice.cpp
756     alc/voice.h
757     alc/voice_change.h)
759 # Include SIMD mixers
760 set(CPU_EXTS "Default")
761 if(HAVE_SSE2)
762     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse.cpp core/mixer/mixer_sse2.cpp)
763     set(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
764 endif()
765 if(HAVE_SSE3)
766     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse3.cpp)
767     set(CPU_EXTS "${CPU_EXTS}, SSE3")
768 endif()
769 if(HAVE_SSE4_1)
770     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_sse41.cpp)
771     set(CPU_EXTS "${CPU_EXTS}, SSE4.1")
772 endif()
773 if(HAVE_NEON)
774     set(CORE_OBJS  ${CORE_OBJS} core/mixer/mixer_neon.cpp)
775     set(CPU_EXTS "${CPU_EXTS}, Neon")
776 endif()
779 set(HAVE_ALSA       0)
780 set(HAVE_OSS        0)
781 set(HAVE_SOLARIS    0)
782 set(HAVE_SNDIO      0)
783 set(HAVE_DSOUND     0)
784 set(HAVE_WASAPI     0)
785 set(HAVE_WINMM      0)
786 set(HAVE_PORTAUDIO  0)
787 set(HAVE_PULSEAUDIO 0)
788 set(HAVE_COREAUDIO  0)
789 set(HAVE_OPENSL     0)
790 set(HAVE_OBOE       0)
791 set(HAVE_WAVE       0)
792 set(HAVE_SDL2       0)
794 if(WIN32 OR HAVE_DLFCN_H)
795     set(IS_LINKED "")
796     macro(ADD_BACKEND_LIBS _LIBS)
797     endmacro()
798 else()
799     set(IS_LINKED " (linked)")
800     macro(ADD_BACKEND_LIBS _LIBS)
801         set(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
802     endmacro()
803 endif()
805 set(BACKENDS "")
806 set(ALC_OBJS  ${ALC_OBJS}
807     alc/backends/base.cpp
808     alc/backends/base.h
809     # Default backends, always available
810     alc/backends/loopback.cpp
811     alc/backends/loopback.h
812     alc/backends/null.cpp
813     alc/backends/null.h
816 # Check ALSA backend
817 option(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
818 find_package(ALSA)
819 if(ALSA_FOUND)
820     option(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
821     if(ALSOFT_BACKEND_ALSA)
822         set(HAVE_ALSA 1)
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})
827     endif()
828 endif()
829 if(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
830     message(FATAL_ERROR "Failed to enabled required ALSA backend")
831 endif()
833 # Check OSS backend
834 option(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
835 find_package(OSS)
836 if(OSS_FOUND)
837     option(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
838     if(ALSOFT_BACKEND_OSS)
839         set(HAVE_OSS 1)
840         set(BACKENDS  "${BACKENDS} OSS,")
841         set(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
842         if(OSS_LIBRARIES)
843             set(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
844         endif()
845         set(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
846     endif()
847 endif()
848 if(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
849     message(FATAL_ERROR "Failed to enabled required OSS backend")
850 endif()
852 # Check Solaris backend
853 option(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
854 find_package(AudioIO)
855 if(AUDIOIO_FOUND)
856     option(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
857     if(ALSOFT_BACKEND_SOLARIS)
858         set(HAVE_SOLARIS 1)
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})
862     endif()
863 endif()
864 if(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
865     message(FATAL_ERROR "Failed to enabled required Solaris backend")
866 endif()
868 # Check SndIO backend
869 option(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
870 find_package(SoundIO)
871 if(SOUNDIO_FOUND)
872     option(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
873     if(ALSOFT_BACKEND_SNDIO)
874         set(HAVE_SNDIO 1)
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})
879     endif()
880 endif()
881 if(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
882     message(FATAL_ERROR "Failed to enabled required SndIO backend")
883 endif()
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)
889 if(WIN32)
890     # Check MMSystem backend
891     option(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
892     if(ALSOFT_BACKEND_WINMM)
893         set(HAVE_WINMM 1)
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})
901     endif()
903     # Check DSound backend
904     check_include_file(dsound.h HAVE_DSOUND_H)
905     if(DXSDK_DIR)
906         find_path(DSOUND_INCLUDE_DIR NAMES "dsound.h"
907             PATHS "${DXSDK_DIR}" PATH_SUFFIXES include
908             DOC "The DirectSound include directory")
909     endif()
910     if(HAVE_DSOUND_H OR DSOUND_INCLUDE_DIR)
911         option(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
912         if(ALSOFT_BACKEND_DSOUND)
913             set(HAVE_DSOUND 1)
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})
919             endif()
920         endif()
921     endif()
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)
928             set(HAVE_WASAPI 1)
929             set(BACKENDS  "${BACKENDS} WASAPI,")
930             set(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
931         endif()
932     endif()
933 endif()
934 if(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
935     message(FATAL_ERROR "Failed to enabled required WinMM backend")
936 endif()
937 if(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
938     message(FATAL_ERROR "Failed to enabled required DSound backend")
939 endif()
940 if(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
941     message(FATAL_ERROR "Failed to enabled required WASAPI backend")
942 endif()
944 # Check PortAudio backend
945 option(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
946 find_package(PortAudio)
947 if(PORTAUDIO_FOUND)
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})
955     endif()
956 endif()
957 if(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
958     message(FATAL_ERROR "Failed to enabled required PortAudio backend")
959 endif()
961 # Check PulseAudio backend
962 option(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
963 find_package(PulseAudio)
964 if(PULSEAUDIO_FOUND)
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})
972     endif()
973 endif()
974 if(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
975     message(FATAL_ERROR "Failed to enabled required PulseAudio backend")
976 endif()
978 # Check JACK backend
979 option(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
980 find_package(JACK)
981 if(JACK_FOUND)
982     option(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
983     if(ALSOFT_BACKEND_JACK)
984         set(HAVE_JACK 1)
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})
989     endif()
990 endif()
991 if(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
992     message(FATAL_ERROR "Failed to enabled required JACK backend")
993 endif()
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})
1008         else()
1009             set(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} /System/Library/Frameworks/AudioUnit.framework
1010                 /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1011         endif()
1013         # Some versions of OSX may need the AudioToolbox framework. Add it if
1014         # it's found.
1015         find_library(AUDIOTOOLBOX_LIBRARY NAMES AudioToolbox)
1016         if(AUDIOTOOLBOX_LIBRARY)
1017             set(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1018         endif()
1020         set(INC_PATHS ${INC_PATHS} ${AUDIOUNIT_INCLUDE_DIR})
1021     endif()
1022 endif()
1023 if(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1024     message(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1025 endif()
1027 # Check for OpenSL (Android) backend
1028 option(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1029 find_package(OpenSL)
1030 if(OPENSL_FOUND)
1031     option(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1032     if(ALSOFT_BACKEND_OPENSL)
1033         set(HAVE_OPENSL 1)
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})
1037     endif()
1038 endif()
1039 if(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1040     message(FATAL_ERROR "Failed to enabled required OpenSL backend")
1041 endif()
1043 # Check for Oboe (Android) backend
1044 set(OBOE_TARGET )
1045 if(ANDROID)
1046     set(OBOE_SOURCE "" CACHE STRING "Source directory for Oboe.")
1047     if(OBOE_SOURCE)
1048         # Force Oboe to build with hidden symbols. Don't want to be exporting
1049         # them from OpenAL.
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")
1054         endif()
1055         add_subdirectory(${OBOE_SOURCE} ./oboe)
1056         set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS})
1057         unset(OLD_CXX_FLAGS)
1059         set(OBOE_TARGET oboe)
1060     else()
1061         find_package(Oboe)
1062         if(OBOE_FOUND)
1063             set(OBOE_TARGET "oboe::oboe")
1064         endif()
1065     endif()
1066 endif()
1068 option(ALSOFT_REQUIRE_OBOE "Require Oboe backend" OFF)
1069 if(OBOE_TARGET)
1070     option(ALSOFT_BACKEND_OBOE "Enable Oboe backend" ON)
1071     if(ALSOFT_BACKEND_OBOE)
1072         set(HAVE_OBOE 1)
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})
1076     endif()
1077 endif()
1078 if(ALSOFT_REQUIRE_OBOE AND NOT HAVE_OBOE)
1079     message(FATAL_ERROR "Failed to enabled required Oboe backend")
1080 endif()
1082 # Check for SDL2 backend
1083 option(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1084 find_package(SDL2)
1085 if(SDL2_FOUND)
1086     # Off by default, since it adds a runtime dependency
1087     option(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1088     if(ALSOFT_BACKEND_SDL2)
1089         set(HAVE_SDL2 1)
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})
1094     endif()
1095 endif()
1096 if(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1097     message(FATAL_ERROR "Failed to enabled required SDL2 backend")
1098 endif()
1100 # Optionally enable the Wave Writer backend
1101 option(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1102 if(ALSOFT_BACKEND_WAVE)
1103     set(HAVE_WAVE 1)
1104     set(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1105     set(BACKENDS  "${BACKENDS} WaveFile,")
1106 endif()
1108 # This is always available
1109 set(BACKENDS  "${BACKENDS} Null")
1112 find_package(Git)
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}"
1120         VERBATIM
1121     )
1122 else()
1123     set(GIT_BRANCH "UNKNOWN")
1124     set(GIT_COMMIT_HASH "unknown")
1125     configure_file(
1126         "${OpenAL_SOURCE_DIR}/version.h.in"
1127         "${OpenAL_BINARY_DIR}/version.h")
1128 endif()
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"
1142             VERBATIM
1143         )
1144         set(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1145     endmacro()
1147     make_hrtf_header("Default HRTF.mhr" "hrtf_default")
1148 endif()
1151 if(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1152     find_package(Qt5Widgets)
1153 endif()
1154 if(ALSOFT_EXAMPLES)
1155     find_package(SndFile)
1156     find_package(SDL2)
1157     if(SDL2_FOUND)
1158         find_package(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1159     endif()
1160 endif()
1162 if(NOT WIN32)
1163     set(LIBNAME "openal")
1164 else()
1165     set(LIBNAME "OpenAL32")
1166 endif()
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}")
1184         else()
1185             set(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1186         endif()
1187     endforeach()
1188 endif()
1190 # End configuration
1191 configure_file(
1192     "${OpenAL_SOURCE_DIR}/config.h.in"
1193     "${OpenAL_BINARY_DIR}/config.h")
1194 configure_file(
1195     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1196     "${OpenAL_BINARY_DIR}/openal.pc"
1197     @ONLY)
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)
1207 unset(HAS_ROUTER)
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})
1215     if(WIN32)
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)
1222         endif()
1223     endif()
1224 else()
1225     set(RC_CONFIG resources/openal32.rc)
1226     if(WIN32 AND ALSOFT_BUILD_ROUTER)
1227         add_library(OpenAL SHARED
1228             resources/router.rc
1229             router/router.cpp
1230             router/router.h
1231             router/alc.cpp
1232             router/al.cpp
1233         )
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
1239           PUBLIC
1240             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1241             $<INSTALL_INTERFACE:include>
1242           PRIVATE
1243             ${OpenAL_SOURCE_DIR}/common
1244             ${OpenAL_BINARY_DIR}
1245         )
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)
1250         endif()
1251         set(HAS_ROUTER 1)
1253         set(LIBNAME "soft_oal")
1254         set(IMPL_TARGET soft_oal)
1255         set(RC_CONFIG resources/soft_oal.rc)
1256     endif()
1258     # !important: for osx framework public header works, the headers must be in
1259     # the project
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})
1263     if(WIN32)
1264         set_target_properties(${IMPL_TARGET} PROPERTIES PREFIX "")
1265     endif()
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")
1271         if(GIT_FOUND)
1272             EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list --count head
1273                 TIMEOUT 5
1274                 OUTPUT_VARIABLE BUNDLE_VERSION
1275                 OUTPUT_STRIP_TRAILING_WHITESPACE)
1276         else()
1277             set(BUNDLE_VERSION 1)
1278         endif()
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,")
1286         endif()
1288         set_target_properties(${IMPL_TARGET} PROPERTIES
1289             FRAMEWORK TRUE
1290             FRAMEWORK_VERSION C
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}"
1299             MACOSX_RPATH TRUE)
1300     endif()
1301 endif()
1303 target_include_directories(${IMPL_TARGET}
1304   PUBLIC
1305     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1306     $<INSTALL_INTERFACE:include>
1307   PRIVATE
1308     ${INC_PATHS}
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)
1325 endif()
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)
1330         message(STATUS "")
1331         if(NOT SED_EXECUTABLE)
1332             message(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1333         endif()
1334         if(NOT CMAKE_DLLTOOL)
1335             message(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1336         endif()
1337     else()
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..."
1344             VERBATIM
1345         )
1346     endif()
1347 endif()
1349 if(HAS_ROUTER)
1350     message(STATUS "")
1351     message(STATUS "Building DLL router")
1352 endif()
1354 message(STATUS "
1355 Building OpenAL with support for the following backends:
1356     ${BACKENDS}
1358 Building with support for CPU extensions:
1359     ${CPU_EXTS}
1361 if(FPMATH_SET)
1362     message(STATUS "Building with SSE${FPMATH_SET} codegen
1364 endif()
1366 if(ALSOFT_EMBED_HRTF_DATA)
1367     message(STATUS "Embedding HRTF datasets
1369 endif()
1371 # Install main library
1372 if(ALSOFT_INSTALL)
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
1380         NAMESPACE OpenAL::
1381         FILE OpenALConfig.cmake)
1382     install(EXPORT OpenAL
1383         DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1384         NAMESPACE 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")
1390     if(TARGET soft_oal)
1391         install(TARGETS soft_oal
1392             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
1393     endif()
1394     message(STATUS "Installing library and headers")
1395 else()
1396     message(STATUS "NOT installing library and headers")
1397 endif()
1399 if(ALSOFT_INSTALL_CONFIG)
1400     install(FILES alsoftrc.sample
1401         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1402     message(STATUS "Installing sample configuration")
1403 endif()
1405 if(ALSOFT_INSTALL_HRTF_DATA)
1406     install(DIRECTORY hrtf
1407         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1408     message(STATUS "Installing HRTF data files")
1409 endif()
1411 if(ALSOFT_INSTALL_AMBDEC_PRESETS)
1412     install(DIRECTORY presets
1413         DESTINATION ${CMAKE_INSTALL_DATADIR}/openal)
1414     message(STATUS "Installing AmbDec presets")
1415 endif()
1416 message(STATUS "")
1418 set(UNICODE_FLAG )
1419 if(MINGW)
1420     set(UNICODE_FLAG ${UNICODE_FLAG} -municode)
1421 endif()
1422 set(EXTRA_INSTALLS )
1423 if(ALSOFT_UTILS)
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)
1430     endif()
1432     find_package(MySOFA)
1433     if(MYSOFA_FOUND)
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})
1443         set(MAKEMHR_SRCS
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)
1450         if(NOT HAVE_GETOPT)
1451             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1452         endif()
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)
1461         endif()
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})
1469     endif()
1470     message(STATUS "Building utility programs")
1472     if(NOT ALSOFT_NO_CONFIG_UTIL)
1473         add_subdirectory(utils/alsoft-config)
1474     endif()
1475     message(STATUS "")
1476 endif()
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})
1488 if(ALSOFT_EXAMPLES)
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)
1497     endif()
1499     message(STATUS "Building example programs")
1501     if(SNDFILE_FOUND)
1502         add_executable(alplay examples/alplay.c)
1503         target_link_libraries(alplay PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1504             ${UNICODE_FLAG})
1506         add_executable(alstream examples/alstream.c)
1507         target_link_libraries(alstream PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1508             ${UNICODE_FLAG})
1510         add_executable(alreverb examples/alreverb.c)
1511         target_link_libraries(alreverb PRIVATE ${LINKER_FLAGS} SndFile::SndFile ex-common
1512             ${UNICODE_FLAG})
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
1520             ${UNICODE_FLAG})
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
1528             ${UNICODE_FLAG})
1530         add_executable(alconvolve examples/alconvolve.c)
1531         target_link_libraries(alconvolve PRIVATE ${LINKER_FLAGS} common SndFile::SndFile ex-common
1532             ${UNICODE_FLAG})
1534         if(ALSOFT_INSTALL_EXAMPLES)
1535             set(EXTRA_INSTALLS ${EXTRA_INSTALLS} alplay alstream alreverb almultireverb allatency
1536                 alhrtf)
1537         endif()
1539         message(STATUS "Building SndFile example programs")
1540     endif()
1542     if(SDL2_FOUND)
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)
1550         endif()
1552         message(STATUS "Building SDL example programs")
1554         set(FFVER_OK FALSE)
1555         if(FFMPEG_FOUND)
1556             set(FFVER_OK TRUE)
1557             if(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1558                 message(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1559                 set(FFVER_OK FALSE)
1560             endif()
1561             if(AVCODEC_VERSION VERSION_LESS "57.64.101")
1562                 message(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1563                 set(FFVER_OK FALSE)
1564             endif()
1565             if(AVUTIL_VERSION VERSION_LESS "55.34.101")
1566                 message(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1567                 set(FFVER_OK FALSE)
1568             endif()
1569             if(SWSCALE_VERSION VERSION_LESS "4.2.100")
1570                 message(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1571                 set(FFVER_OK FALSE)
1572             endif()
1573             if(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1574                 message(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1575                 set(FFVER_OK FALSE)
1576             endif()
1577         endif()
1578         if(FFVER_OK)
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)
1587             endif()
1588             message(STATUS "Building SDL+FFmpeg example programs")
1589         endif()
1590     endif()
1591     message(STATUS "")
1592 endif()
1594 if(EXTRA_INSTALLS)
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})
1600 endif()