Remove some unnecessary local spans
[openal-soft.git] / CMakeLists.txt
blob7626c1efbfbc97774f55c6f6636ee48094e32e2d
1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 3.0.2)
5 PROJECT(OpenAL)
7 IF(COMMAND CMAKE_POLICY)
8     CMAKE_POLICY(SET CMP0003 NEW)
9     CMAKE_POLICY(SET CMP0005 NEW)
10     IF(POLICY CMP0020)
11         CMAKE_POLICY(SET CMP0020 NEW)
12     ENDIF(POLICY CMP0020)
13     IF(POLICY CMP0042)
14         CMAKE_POLICY(SET CMP0042 NEW)
15     ENDIF(POLICY CMP0042)
16     IF(POLICY CMP0054)
17         CMAKE_POLICY(SET CMP0054 NEW)
18     ENDIF(POLICY CMP0054)
19     IF(POLICY CMP0075)
20         CMAKE_POLICY(SET CMP0075 NEW)
21     ENDIF(POLICY CMP0075)
22 ENDIF(COMMAND CMAKE_POLICY)
24 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
26 INCLUDE(CheckFunctionExists)
27 INCLUDE(CheckLibraryExists)
28 INCLUDE(CheckIncludeFile)
29 INCLUDE(CheckIncludeFiles)
30 INCLUDE(CheckSymbolExists)
31 INCLUDE(CheckCCompilerFlag)
32 INCLUDE(CheckCXXCompilerFlag)
33 INCLUDE(CheckCSourceCompiles)
34 INCLUDE(CheckCXXSourceCompiles)
35 INCLUDE(CheckTypeSize)
36 include(CheckStructHasMember)
37 include(CheckFileOffsetBits)
38 include(GNUInstallDirs)
40 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
43 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
45 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
47 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
48 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
50 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
51 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
53 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
54 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
55 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
56 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
58 if(DEFINED SHARE_INSTALL_DIR)
59     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
60     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
61 endif()
63 if(DEFINED LIB_SUFFIX)
64     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
65 endif()
68 SET(CPP_DEFS ) # C pre-process, not C++
69 SET(INC_PATHS )
70 SET(C_FLAGS )
71 SET(LINKER_FLAGS )
72 SET(EXTRA_LIBS )
74 IF(WIN32)
75     SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
77     OPTION(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
79     # This option is mainly for static linking OpenAL Soft into another project
80     # that already defines the IDs. It is up to that project to ensure all
81     # required IDs are defined.
82     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
84     IF(MINGW)
85         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
86         IF(NOT DLLTOOL)
87             IF(HOST)
88                 SET(DLLTOOL "${HOST}-dlltool")
89             ELSE()
90                 SET(DLLTOOL "dlltool")
91             ENDIF()
92         ENDIF()
93     ENDIF()
94 ENDIF()
97 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
98 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
99     SET(INC_PATHS ${INC_PATHS} /usr/include)
100     SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
101 ENDIF()
103 IF(NOT LIBTYPE)
104     SET(LIBTYPE SHARED)
105 ENDIF()
107 SET(LIB_MAJOR_VERSION "1")
108 SET(LIB_MINOR_VERSION "19")
109 SET(LIB_REVISION "1")
110 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
111 SET(LIB_VERSION_NUM ${LIB_MAJOR_VERSION},${LIB_MINOR_VERSION},${LIB_REVISION},0)
113 SET(EXPORT_DECL "")
116 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
117 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
120 # Require C++11
121 SET(CMAKE_CXX_STANDARD 11)
122 SET(CMAKE_CXX_STANDARD_REQUIRED TRUE)
124 # Prefer C11, but support C99 and C90 too.
125 SET(CMAKE_C_STANDARD 11)
128 if(NOT WIN32)
129     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
130     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
131     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
132         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
133         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
134         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
135         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
136             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
137         ELSE()
138             SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
139         ENDIF()
140     ENDIF()
141     UNSET(OLD_REQUIRED_FLAGS)
142 ENDIF()
144 # Set defines for large file support. Don't set this for Android targets. See:
145 # https://android-developers.googleblog.com/2017/09/introducing-android-native-development.html
146 IF(NOT ANDROID)
147     CHECK_FILE_OFFSET_BITS()
148     IF(_FILE_OFFSET_BITS)
149         SET(CPP_DEFS ${CPP_DEFS} "_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
150         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
151     ENDIF()
152     SET(CPP_DEFS ${CPP_DEFS} _LARGEFILE_SOURCE _LARGE_FILES)
153     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
154 ENDIF()
156 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
157 SET(RESTRICT_DECL )
158 CHECK_C_SOURCE_COMPILES("int *__restrict foo;
159                          int main() {return 0;}" HAVE___RESTRICT)
160 IF(HAVE___RESTRICT)
161     SET(RESTRICT_DECL "__restrict")
162 ENDIF()
164 # Some systems may need libatomic for C11 atomic functions to work
165 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
166 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
167 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
168 int _Atomic foo = ATOMIC_VAR_INIT(0);
169 int main()
171     return atomic_fetch_add(&foo, 2);
173 HAVE_LIBATOMIC)
174 IF(NOT HAVE_LIBATOMIC)
175     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
176 ELSE()
177     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
178 ENDIF()
179 UNSET(OLD_REQUIRED_LIBRARIES)
181 # Include liblog for Android logging
182 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
183 IF(HAVE_LIBLOG)
184     SET(EXTRA_LIBS log ${EXTRA_LIBS})
185     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
186 ENDIF()
188 IF(NOT CMAKE_BUILD_TYPE)
189     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
190         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
191         FORCE)
192 ENDIF()
193 IF(NOT CMAKE_DEBUG_POSTFIX)
194     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
195         "Library postfix for debug builds. Normally left blank."
196         FORCE)
197 ENDIF()
199 IF(MSVC)
200     SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS NOMINMAX)
201     SET(C_FLAGS ${C_FLAGS} /wd4065 /wd4200)
203     IF(NOT DXSDK_DIR)
204         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
205     ELSE()
206         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
207     ENDIF()
208     IF(DXSDK_DIR)
209         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
210     ENDIF()
212     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
213     IF(FORCE_STATIC_VCRT)
214         FOREACH(flag_var
215                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
216                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
217             IF(${flag_var} MATCHES "/MD")
218                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
219             ENDIF()
220         ENDFOREACH(flag_var)
221     ENDIF()
222 ELSE()
223     SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
224     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
225     IF(HAVE_W_EXTRA)
226         SET(C_FLAGS ${C_FLAGS} -Wextra)
227     ENDIF()
229     IF(ALSOFT_WERROR)
230         SET(C_FLAGS ${C_FLAGS} -Werror)
231     ENDIF()
233     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
234     # instead of NDEBUG)
235     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
236         IF(${flag_var} MATCHES "-DNDEBUG")
237             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
238         ENDIF()
239     ENDFOREACH()
241     CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
242     IF(HAVE_FNO_MATH_ERRNO)
243         SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
244     ENDIF()
246     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
247     if(ALSOFT_STATIC_LIBGCC)
248         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
249         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
250         check_c_source_compiles(
251 "#include <stdlib.h>
252 int main()
254     return 0;
256             HAVE_STATIC_LIBGCC_SWITCH
257         )
258         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
259         unset(OLD_REQUIRED_LIBRARIES)
261         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
262             message(FATAL_ERROR "Cannot static link libgcc")
263         endif()
264         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
265     endif()
267     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
268     if(ALSOFT_STATIC_STDCXX)
269         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
270         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
271         check_cxx_source_compiles(
272 "#include <cstdlib>
273 int main()
275     return 0;
277             HAVE_STATIC_LIBSTDCXX_SWITCH
278         )
279         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
280         unset(OLD_REQUIRED_LIBRARIES)
282         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
283             message(FATAL_ERROR "Cannot static link libstdc++")
284         endif()
285         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
286     endif()
288     if(WIN32)
289         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
290         if(ALSOFT_STATIC_WINPTHREAD)
291             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
292             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
293             check_cxx_source_compiles(
294 "#include <cstdlib>
295 int main()
297     return 0;
299                 HAVE_STATIC_LIBWINPTHREAD_SWITCH
300             )
301             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
302             unset(OLD_REQUIRED_LIBRARIES)
304             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
305                 message(FATAL_ERROR "Cannot static link libwinpthread")
306             endif()
307             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
308         endif()
309     endif()
310 ENDIF()
312 # Set visibility/export options if available
313 IF(WIN32)
314     SET(EXPORT_DECL "__declspec(dllexport)")
315 ELSE()
316     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
317     # Yes GCC, really don't accept visibility modes you don't support
318     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
320     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
321                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
322     IF(HAVE_GCC_PROTECTED_VISIBILITY)
323         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
324     ELSE()
325         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
326                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
327         IF(HAVE_GCC_DEFAULT_VISIBILITY)
328             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
329         ENDIF()
330     ENDIF()
332     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
333         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
334         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
335             SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
336         ENDIF()
337     ENDIF()
339     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
340 ENDIF()
342 SET(SSE2_SWITCH "")
343 SET(SSE3_SWITCH "")
344 SET(SSE4_1_SWITCH "")
345 SET(FPU_NEON_SWITCH "")
347 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
348 IF(HAVE_MSSE2_SWITCH)
349     SET(SSE2_SWITCH "-msse2")
350 ENDIF()
351 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
352 IF(HAVE_MSSE3_SWITCH)
353     SET(SSE3_SWITCH "-msse3")
354 ENDIF()
355 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
356 IF(HAVE_MSSE4_1_SWITCH)
357     SET(SSE4_1_SWITCH "-msse4.1")
358 ENDIF()
359 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
360 IF(HAVE_MFPU_NEON_SWITCH)
361     SET(FPU_NEON_SWITCH "-mfpu=neon")
362 ENDIF()
364 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE2_SWITCH}")
365 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
366 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
367 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
368 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H "${FPU_NEON_SWITCH}")
370 SET(SSE_FLAGS )
371 SET(FPMATH_SET "0")
372 IF(CMAKE_SIZEOF_VOID_P MATCHES "4")
373     IF(SSE2_SWITCH OR MSVC)
374         OPTION(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
375     ENDIF()
377     IF(ALSOFT_ENABLE_SSE2_CODEGEN)
378         IF(SSE2_SWITCH)
379             CHECK_C_COMPILER_FLAG("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
380             IF(HAVE_MFPMATH_SSE_2)
381                 SET(SSE_FLAGS ${SSE_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
382                 SET(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
383                 SET(FPMATH_SET 2)
384             ENDIF()
385         ELSEIF(MSVC)
386             CHECK_C_COMPILER_FLAG("/arch:SSE2" HAVE_ARCH_SSE2)
387             IF(HAVE_ARCH_SSE2)
388                 SET(SSE_FLAGS ${SSE_FLAGS} "/arch:SSE2")
389                 SET(C_FLAGS ${C_FLAGS} ${SSE_FLAGS})
390                 SET(FPMATH_SET 2)
391             ENDIF()
392         ENDIF()
393     ENDIF()
394 ENDIF()
396 IF(HAVE_EMMINTRIN_H)
397     SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
398     FOREACH(flag_var ${SSE_FLAGS})
399         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag_var}")
400     ENDFOREACH()
402     CHECK_C_SOURCE_COMPILES("#include <emmintrin.h>
403                              int main() {_mm_pause(); return 0;}" HAVE_SSE_INTRINSICS)
405     SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
406 ENDIF()
409 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
410                          int main() {return 0;}" HAVE_GCC_FORMAT)
412 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
413 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
414 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
415 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
416 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
417 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
418 IF(NOT HAVE_GUIDDEF_H)
419     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
420 ENDIF()
422 # Some systems need libm for some math functions to work
423 SET(MATH_LIB )
424 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
425 IF(HAVE_LIBM)
426     SET(MATH_LIB ${MATH_LIB} m)
427     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
428 ENDIF()
430 # Check for the dlopen API (for dynamicly loading backend libs)
431 IF(ALSOFT_DLOPEN)
432     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
433     IF(HAVE_LIBDL)
434         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
435         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
436     ENDIF()
438     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
439 ENDIF()
441 # Check for a cpuid intrinsic
442 IF(HAVE_CPUID_H)
443     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
444         int main()
445         {
446             unsigned int eax, ebx, ecx, edx;
447             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
448         }" HAVE_GCC_GET_CPUID)
449 ENDIF()
450 IF(HAVE_INTRIN_H)
451     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
452         int main()
453         {
454             int regs[4];
455             __cpuid(regs, 0);
456             return regs[0];
457         }" HAVE_CPUID_INTRINSIC)
458     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
459         int main()
460         {
461             unsigned long idx = 0;
462             _BitScanForward64(&idx, 1);
463             return idx;
464         }" HAVE_BITSCANFORWARD64_INTRINSIC)
465     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
466         int main()
467         {
468             unsigned long idx = 0;
469             _BitScanForward(&idx, 1);
470             return idx;
471         }" HAVE_BITSCANFORWARD_INTRINSIC)
472 ENDIF()
474 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
475 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
476 CHECK_SYMBOL_EXISTS(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
478 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
479 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
480 IF(NOT HAVE_STRCASECMP)
481     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
482     IF(NOT HAVE__STRICMP)
483         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
484     ENDIF()
486     SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
487 ENDIF()
489 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
490 IF(NOT HAVE_STRNCASECMP)
491     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
492     IF(NOT HAVE__STRNICMP)
493         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
494     ENDIF()
496     SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
497 ENDIF()
500 IF(NOT WIN32)
501     # We need pthreads outside of Windows, for semaphores. It's also used to
502     # set the priority and name of threads, when possible.
503     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
504     IF(NOT HAVE_PTHREAD_H)
505         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
506     ENDIF()
508     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
509     IF(HAVE_PTHREAD)
510         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
511         SET(C_FLAGS ${C_FLAGS} -pthread)
512         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
513     ENDIF()
515     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
516     IF(HAVE_LIBPTHREAD)
517         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
518     ENDIF()
520     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
522     # Some systems need pthread_np.h to get pthread_setname_np
523     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
524     IF(HAVE_PTHREAD_NP_H)
525         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
526         IF(NOT HAVE_PTHREAD_SETNAME_NP)
527             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
528         ELSE()
529             CHECK_C_SOURCE_COMPILES("
530 #include <pthread.h>
531 #include <pthread_np.h>
532 int main()
534     pthread_setname_np(\"testname\");
535     return 0;
537                 PTHREAD_SETNAME_NP_ONE_PARAM
538             )
539             CHECK_C_SOURCE_COMPILES("
540 #include <pthread.h>
541 #include <pthread_np.h>
542 int main()
544     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
545     return 0;
547                 PTHREAD_SETNAME_NP_THREE_PARAMS
548             )
549         ENDIF()
550     ELSE()
551         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
552         IF(NOT HAVE_PTHREAD_SETNAME_NP)
553             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
554         ELSE()
555             CHECK_C_SOURCE_COMPILES("
556 #include <pthread.h>
557 int main()
559     pthread_setname_np(\"testname\");
560     return 0;
562                 PTHREAD_SETNAME_NP_ONE_PARAM
563             )
564             CHECK_C_SOURCE_COMPILES("
565 #include <pthread.h>
566 int main()
568     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
569     return 0;
571                 PTHREAD_SETNAME_NP_THREE_PARAMS
572             )
573         ENDIF()
574     ENDIF()
575 ENDIF()
577 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
579 # Check for a 64-bit type
580 IF(NOT SIZEOF_LONG MATCHES "8")
581     IF(NOT SIZEOF_LONG_LONG MATCHES "8")
582         MESSAGE(FATAL_ERROR "No 64-bit type found, please report!")
583     ENDIF()
584 ENDIF()
587 # Common sources used by both the OpenAL implementation library and potentially
588 # the OpenAL router.
589 SET(COMMON_OBJS
590     common/albyte.h
591     common/alcomplex.cpp
592     common/alcomplex.h
593     common/alexcpt.cpp
594     common/alexcpt.h
595     common/almalloc.cpp
596     common/almalloc.h
597     common/alnumeric.h
598     common/aloptional.h
599     common/alspan.h
600     common/atomic.h
601     common/dynload.cpp
602     common/dynload.h
603     common/endiantest.h
604     common/intrusive_ptr.h
605     common/math_defs.h
606     common/opthelpers.h
607     common/strutils.cpp
608     common/strutils.h
609     common/threads.cpp
610     common/threads.h
611     common/vecmat.h
612     common/vector.h
614 SET(OPENAL_OBJS
615     al/auxeffectslot.cpp
616     al/auxeffectslot.h
617     al/buffer.cpp
618     al/buffer.h
619     al/effect.cpp
620     al/effect.h
621     al/error.cpp
622     al/event.cpp
623     al/event.h
624     al/extension.cpp
625     al/filter.cpp
626     al/filter.h
627     al/listener.cpp
628     al/listener.h
629     al/source.cpp
630     al/source.h
631     al/state.cpp
633 SET(ALC_OBJS
634     alc/alc.cpp
635     alc/alcmain.h
636     alc/alu.cpp
637     alc/alu.h
638     alc/alconfig.cpp
639     alc/alconfig.h
640     alc/alcontext.h
641     alc/ambdec.cpp
642     alc/ambdec.h
643     alc/ambidefs.h
644     alc/bformatdec.cpp
645     alc/bformatdec.h
646     alc/bs2b.cpp
647     alc/bs2b.h
648     alc/compat.h
649     alc/converter.cpp
650     alc/converter.h
651     alc/cpu_caps.h
652     alc/devformat.h
653     alc/effects/base.h
654     alc/effects/autowah.cpp
655     alc/effects/chorus.cpp
656     alc/effects/compressor.cpp
657     alc/effects/dedicated.cpp
658     alc/effects/distortion.cpp
659     alc/effects/echo.cpp
660     alc/effects/equalizer.cpp
661     alc/effects/fshifter.cpp
662     alc/effects/modulator.cpp
663     alc/effects/null.cpp
664     alc/effects/pshifter.cpp
665     alc/effects/reverb.cpp
666     alc/effects/vmorpher.cpp
667     alc/filters/biquad.h
668     alc/filters/biquad.cpp
669     alc/filters/nfc.cpp
670     alc/filters/nfc.h
671     alc/filters/splitter.cpp
672     alc/filters/splitter.h
673     alc/fpu_modes.h
674     alc/helpers.cpp
675     alc/hrtf.cpp
676     alc/hrtf.h
677     alc/inprogext.h
678     alc/logging.h
679     alc/mastering.cpp
680     alc/mastering.h
681     alc/mixvoice.cpp
682     alc/panning.cpp
683     alc/ringbuffer.cpp
684     alc/ringbuffer.h
685     alc/uhjfilter.cpp
686     alc/uhjfilter.h
687     alc/uiddefs.cpp
688     alc/mixer/defs.h
689     alc/mixer/hrtfbase.h
690     alc/mixer/mixer_c.cpp
694 SET(CPU_EXTS "Default")
695 SET(HAVE_SSE        0)
696 SET(HAVE_SSE2       0)
697 SET(HAVE_SSE3       0)
698 SET(HAVE_SSE4_1     0)
699 SET(HAVE_NEON       0)
701 # Check for SSE+SSE2 support
702 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
703 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
704 IF(HAVE_XMMINTRIN_H AND HAVE_EMMINTRIN_H)
705     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
706     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
707     IF(ALSOFT_CPUEXT_SSE AND ALSOFT_CPUEXT_SSE2)
708         SET(HAVE_SSE 1)
709         SET(HAVE_SSE2 1)
710         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp)
711         IF(SSE2_SWITCH)
712             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse.cpp alc/mixer/mixer_sse2.cpp
713                 PROPERTIES COMPILE_FLAGS "${SSE2_SWITCH}")
714         ENDIF()
715         SET(CPU_EXTS "${CPU_EXTS}, SSE, SSE2")
716     ENDIF()
717 ENDIF()
718 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
719     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
720 ENDIF()
721 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
722     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
723 ENDIF()
725 OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
726 IF(HAVE_EMMINTRIN_H)
727     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
728     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
729         SET(HAVE_SSE3 1)
730         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse3.cpp)
731         IF(SSE2_SWITCH)
732             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse3.cpp PROPERTIES
733                                         COMPILE_FLAGS "${SSE3_SWITCH}")
734         ENDIF()
735         SET(CPU_EXTS "${CPU_EXTS}, SSE3")
736     ENDIF()
737 ENDIF()
738 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
739     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
740 ENDIF()
742 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
743 IF(HAVE_SMMINTRIN_H)
744     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
745     IF(HAVE_SSE3 AND ALSOFT_CPUEXT_SSE4_1)
746         SET(HAVE_SSE4_1 1)
747         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_sse41.cpp)
748         IF(SSE4_1_SWITCH)
749             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_sse41.cpp PROPERTIES
750                                         COMPILE_FLAGS "${SSE4_1_SWITCH}")
751         ENDIF()
752         SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
753     ENDIF()
754 ENDIF()
755 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
756     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
757 ENDIF()
759 # Check for ARM Neon support
760 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
761 IF(HAVE_ARM_NEON_H)
762     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
763     IF(ALSOFT_CPUEXT_NEON)
764         SET(HAVE_NEON 1)
765         SET(ALC_OBJS  ${ALC_OBJS} alc/mixer/mixer_neon.cpp)
766         IF(FPU_NEON_SWITCH)
767             SET_SOURCE_FILES_PROPERTIES(alc/mixer/mixer_neon.cpp PROPERTIES
768                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
769         ENDIF()
770         SET(CPU_EXTS "${CPU_EXTS}, Neon")
771     ENDIF()
772 ENDIF()
773 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
774     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
775 ENDIF()
778 SET(HAVE_ALSA       0)
779 SET(HAVE_OSS        0)
780 SET(HAVE_SOLARIS    0)
781 SET(HAVE_SNDIO      0)
782 SET(HAVE_QSA        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_WAVE       0)
791 SET(HAVE_SDL2       0)
793 IF(WIN32 OR HAVE_DLFCN_H)
794     SET(IS_LINKED "")
795     MACRO(ADD_BACKEND_LIBS _LIBS)
796     ENDMACRO()
797 ELSE()
798     SET(IS_LINKED " (linked)")
799     MACRO(ADD_BACKEND_LIBS _LIBS)
800         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
801     ENDMACRO()
802 ENDIF()
804 SET(BACKENDS "")
805 SET(ALC_OBJS  ${ALC_OBJS}
806     alc/backends/base.cpp
807     alc/backends/base.h
808     # Default backends, always available
809     alc/backends/loopback.cpp
810     alc/backends/loopback.h
811     alc/backends/null.cpp
812     alc/backends/null.h
815 # Check ALSA backend
816 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
817 FIND_PACKAGE(ALSA)
818 IF(ALSA_FOUND)
819     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
820     IF(ALSOFT_BACKEND_ALSA)
821         SET(HAVE_ALSA 1)
822         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
823         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/alsa.cpp alc/backends/alsa.h)
824         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
825         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
826     ENDIF()
827 ENDIF()
828 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
829     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
830 ENDIF()
832 # Check OSS backend
833 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
834 FIND_PACKAGE(OSS)
835 IF(OSS_FOUND)
836     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
837     IF(ALSOFT_BACKEND_OSS)
838         SET(HAVE_OSS 1)
839         SET(BACKENDS  "${BACKENDS} OSS,")
840         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/oss.cpp alc/backends/oss.h)
841         IF(OSS_LIBRARIES)
842             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
843         ENDIF()
844         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
845     ENDIF()
846 ENDIF()
847 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
848     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
849 ENDIF()
851 # Check Solaris backend
852 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
853 FIND_PACKAGE(AudioIO)
854 IF(AUDIOIO_FOUND)
855     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
856     IF(ALSOFT_BACKEND_SOLARIS)
857         SET(HAVE_SOLARIS 1)
858         SET(BACKENDS  "${BACKENDS} Solaris,")
859         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/solaris.cpp alc/backends/solaris.h)
860         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
861     ENDIF()
862 ENDIF()
863 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
864     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
865 ENDIF()
867 # Check SndIO backend
868 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
869 FIND_PACKAGE(SoundIO)
870 IF(SOUNDIO_FOUND)
871     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
872     IF(ALSOFT_BACKEND_SNDIO)
873         SET(HAVE_SNDIO 1)
874         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
875         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/sndio.cpp alc/backends/sndio.h)
876         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
877         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
878     ENDIF()
879 ENDIF()
880 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
881     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
882 ENDIF()
884 # Check QSA backend
885 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
886 FIND_PACKAGE(QSA)
887 IF(QSA_FOUND)
888     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
889     IF(ALSOFT_BACKEND_QSA)
890         SET(HAVE_QSA 1)
891         SET(BACKENDS  "${BACKENDS} QSA (linked),")
892         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/qsa.cpp alc/backends/qsa.h)
893         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
894         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
895     ENDIF()
896 ENDIF()
897 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
898     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
899 ENDIF()
901 # Check Windows-only backends
902 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
903 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
904 OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
905 IF(WIN32)
906     SET(WINSDK_LIB_DIRS )
907     SET(WINSDK_INCLUDE_DIRS )
908     FIND_PACKAGE(WindowsSDK)
909     IF(WINDOWSSDK_FOUND)
910         get_windowssdk_library_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_LIB_DIRS)
911         get_windowssdk_include_dirs(${WINDOWSSDK_PREFERRED_DIR} WINSDK_INCLUDE_DIRS)
912     ENDIF()
914     SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
915     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
917     # Check MMSystem backend
918     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
919     FIND_LIBRARY(WINMM_LIBRARY NAMES winmm
920         PATHS ${WINSDK_LIB_DIRS}
921         PATH_SUFFIXES lib lib/x86 lib/x64)
922     IF(HAVE_MMSYSTEM_H AND WINMM_LIBRARY)
923         OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
924         IF(ALSOFT_BACKEND_WINMM)
925             SET(HAVE_WINMM 1)
926             SET(BACKENDS  "${BACKENDS} WinMM,")
927             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/winmm.cpp alc/backends/winmm.h)
928             SET(EXTRA_LIBS ${WINMM_LIBRARY} ${EXTRA_LIBS})
929         ENDIF()
930     ENDIF()
932     # Check DSound backend
933     FIND_PACKAGE(DSound)
934     IF(DSOUND_FOUND)
935         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
936         IF(ALSOFT_BACKEND_DSOUND)
937             SET(HAVE_DSOUND 1)
938             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
939             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/dsound.cpp alc/backends/dsound.h)
940             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
941             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
942         ENDIF()
943     ENDIF()
945     # Check for WASAPI backend
946     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
947     IF(HAVE_MMDEVICEAPI_H)
948         OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
949         IF(ALSOFT_BACKEND_WASAPI)
950             SET(HAVE_WASAPI 1)
951             SET(BACKENDS  "${BACKENDS} WASAPI,")
952             SET(ALC_OBJS  ${ALC_OBJS} alc/backends/wasapi.cpp alc/backends/wasapi.h)
953         ENDIF()
954     ENDIF()
956     SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
957     UNSET(OLD_REQUIRED_DEFINITIONS)
958 ENDIF()
959 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
960     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
961 ENDIF()
962 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
963     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
964 ENDIF()
965 IF(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
966     MESSAGE(FATAL_ERROR "Failed to enabled required WASAPI backend")
967 ENDIF()
969 # Check PortAudio backend
970 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
971 FIND_PACKAGE(PortAudio)
972 IF(PORTAUDIO_FOUND)
973     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
974     IF(ALSOFT_BACKEND_PORTAUDIO)
975         SET(HAVE_PORTAUDIO 1)
976         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
977         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/portaudio.cpp alc/backends/portaudio.h)
978         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
979         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
980     ENDIF()
981 ENDIF()
982 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
983     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
984 ENDIF()
986 # Check PulseAudio backend
987 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
988 FIND_PACKAGE(PulseAudio)
989 IF(PULSEAUDIO_FOUND)
990     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
991     IF(ALSOFT_BACKEND_PULSEAUDIO)
992         SET(HAVE_PULSEAUDIO 1)
993         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
994         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/pulseaudio.cpp alc/backends/pulseaudio.h)
995         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
996         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
997     ENDIF()
998 ENDIF()
999 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1000     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1001 ENDIF()
1003 # Check JACK backend
1004 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1005 FIND_PACKAGE(JACK)
1006 IF(JACK_FOUND)
1007     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1008     IF(ALSOFT_BACKEND_JACK)
1009         SET(HAVE_JACK 1)
1010         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1011         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/jack.cpp alc/backends/jack.h)
1012         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1013         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1014     ENDIF()
1015 ENDIF()
1016 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1017     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1018 ENDIF()
1020 # Check CoreAudio backend
1021 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1022 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1023              NAMES CoreAudio
1024              PATHS /System/Library/Frameworks
1026 IF(COREAUDIO_FRAMEWORK)
1027     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1028     IF(ALSOFT_BACKEND_COREAUDIO)
1029         SET(HAVE_COREAUDIO 1)
1030         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/coreaudio.cpp alc/backends/coreaudio.h)
1031         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1032         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1033         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1034         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1036         # Some versions of OSX may need the AudioToolbox framework. Add it if
1037         # it's found.
1038         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1039                      NAMES AudioToolbox
1040                      PATHS ~/Library/Frameworks
1041                            /Library/Frameworks
1042                            /System/Library/Frameworks
1043                     )
1044         IF(AUDIOTOOLBOX_LIBRARY)
1045             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1046         ENDIF()
1047     ENDIF()
1048 ENDIF()
1049 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1050     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1051 ENDIF()
1053 # Check for OpenSL (Android) backend
1054 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1055 FIND_PACKAGE(OpenSL)
1056 IF(OPENSL_FOUND)
1057     OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1058     IF(ALSOFT_BACKEND_OPENSL)
1059         SET(HAVE_OPENSL 1)
1060         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/opensl.cpp alc/backends/opensl.h)
1061         SET(BACKENDS  "${BACKENDS} OpenSL,")
1062         SET(EXTRA_LIBS ${OPENSL_LIBRARIES} ${EXTRA_LIBS})
1063         SET(INC_PATHS ${INC_PATHS} ${OPENSL_INCLUDE_DIRS})
1064     ENDIF()
1065 ENDIF()
1066 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1067     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1068 ENDIF()
1070 # Check for SDL2 backend
1071 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1072 FIND_PACKAGE(SDL2)
1073 IF(SDL2_FOUND)
1074     # Off by default, since it adds a runtime dependency
1075     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1076     IF(ALSOFT_BACKEND_SDL2)
1077         SET(HAVE_SDL2 1)
1078         SET(ALC_OBJS  ${ALC_OBJS} alc/backends/sdl2.cpp alc/backends/sdl2.h)
1079         SET(BACKENDS  "${BACKENDS} SDL2,")
1080         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1081         SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1082     ENDIF()
1083 ENDIF()
1084 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1085     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1086 ENDIF()
1088 # Optionally enable the Wave Writer backend
1089 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1090 IF(ALSOFT_BACKEND_WAVE)
1091     SET(HAVE_WAVE 1)
1092     SET(ALC_OBJS  ${ALC_OBJS} alc/backends/wave.cpp alc/backends/wave.h)
1093     SET(BACKENDS  "${BACKENDS} WaveFile,")
1094 ENDIF()
1096 # This is always available
1097 SET(BACKENDS  "${BACKENDS} Null")
1100 FIND_PACKAGE(Git)
1101 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1102     # Get the current working branch and its latest abbreviated commit hash
1103     ADD_CUSTOM_TARGET(build_version
1104         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1105                          -D LIB_VERSION=${LIB_VERSION}
1106                          -D LIB_VERSION_NUM=${LIB_VERSION_NUM}
1107                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1108                          -D DST=${OpenAL_BINARY_DIR}/version.h
1109                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1110         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1111         VERBATIM
1112     )
1113 ELSE()
1114     SET(GIT_BRANCH "UNKNOWN")
1115     SET(GIT_COMMIT_HASH "unknown")
1116     CONFIGURE_FILE(
1117         "${OpenAL_SOURCE_DIR}/version.h.in"
1118         "${OpenAL_BINARY_DIR}/version.h")
1119 ENDIF()
1122 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools")
1124 SET(ALSOFT_NATIVE_TOOLS_PATH "" CACHE STRING "Path to prebuilt native tools (leave blank to auto-build)")
1125 IF(ALSOFT_NATIVE_TOOLS_PATH)
1126     find_program(BIN2H_NATIVE_COMMAND NAMES bin2h
1127         PATHS "${ALSOFT_NATIVE_TOOLS_PATH}"
1128         NO_DEFAULT_PATH)
1129     find_program(BSINCGEN_NATIVE_COMMAND NAMES bsincgen
1130         PATHS "${ALSOFT_NATIVE_TOOLS_PATH}"
1131         NO_DEFAULT_PATH)
1132     if(NOT BIN2H_NATIVE_COMMAND OR NOT BSINCGEN_NATIVE_COMMAND)
1133         message(FATAL_ERROR "Failed to find native tools in ${ALSOFT_NATIVE_TOOLS_PATH}.
1134 bin2h: ${BIN2H_NATIVE_COMMAND}
1135 bsincgen: ${BSINCGEN_NATIVE_COMMAND}")
1136     endif()
1137     SET(BIN2H_COMMAND  ${BIN2H_NATIVE_COMMAND})
1138     SET(BSINCGEN_COMMAND  ${BSINCGEN_NATIVE_COMMAND})
1139 ELSE()
1140     SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools")
1141     FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1143     SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}/bin2h")
1144     SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}/bsincgen")
1145     ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1146         COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1147         COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1148         COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1149         WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1150         DEPENDS "${NATIVE_SRC_DIR}/CMakeLists.txt"
1151         IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}/bin2h.c"
1152                          C "${NATIVE_SRC_DIR}/bsincgen.c"
1153         VERBATIM
1154     )
1155 ENDIF()
1156 ADD_CUSTOM_TARGET(native-tools
1157     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1158     VERBATIM
1161 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1162 if(ALSOFT_EMBED_HRTF_DATA)
1163     MACRO(make_hrtf_header FILENAME VARNAME)
1164         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1165         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1167         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1168             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1169             DEPENDS native-tools "${infile}"
1170             VERBATIM
1171         )
1172         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1173     ENDMACRO()
1175     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1176     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1177 endif()
1179 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1180     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1181     DEPENDS native-tools "${NATIVE_SRC_DIR}/bsincgen.c"
1182     VERBATIM
1184 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1187 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1188     add_subdirectory(utils/alsoft-config)
1189 ENDIF()
1190 IF(ALSOFT_EXAMPLES)
1191     IF(NOT SDL2_FOUND)
1192         FIND_PACKAGE(SDL2)
1193     ENDIF()
1194     IF(SDL2_FOUND)
1195         FIND_PACKAGE(SDL_sound)
1196         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1197     ENDIF()
1198 ENDIF()
1200 IF(NOT WIN32)
1201     SET(LIBNAME "openal")
1202 ELSE()
1203     SET(LIBNAME "OpenAL32")
1204 ENDIF()
1206 # Needed for openal.pc.in
1207 SET(prefix ${CMAKE_INSTALL_PREFIX})
1208 SET(exec_prefix "\${prefix}")
1209 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1210 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1211 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1212 SET(PACKAGE_VERSION "${LIB_VERSION}")
1213 SET(PKG_CONFIG_CFLAGS )
1214 SET(PKG_CONFIG_PRIVATE_LIBS )
1215 IF(LIBTYPE STREQUAL "STATIC")
1216     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1217     FOREACH(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1218         # If this is already a linker flag, or is a full path+file, add it
1219         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1220         IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1221             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1222         ELSE()
1223             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1224         ENDIF()
1225     ENDFOREACH()
1226 ENDIF()
1228 # End configuration
1229 CONFIGURE_FILE(
1230     "${OpenAL_SOURCE_DIR}/config.h.in"
1231     "${OpenAL_BINARY_DIR}/config.h")
1232 CONFIGURE_FILE(
1233     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1234     "${OpenAL_BINARY_DIR}/openal.pc"
1235     @ONLY)
1238 UNSET(HAS_ROUTER)
1239 SET(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal.
1240 SET(SUBSYS_FLAG )
1242 # Build main library
1243 IF(LIBTYPE STREQUAL "STATIC")
1244     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1245     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1246         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1247     ENDIF()
1248     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1249 ELSE()
1251     IF(WIN32)
1252         IF(MSVC)
1253             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1254         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1255             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1256         ENDIF()
1257     ENDIF()
1259     SET(RC_CONFIG resources/openal32.rc)
1260     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1261         ADD_LIBRARY(OpenAL SHARED
1262             resources/router.rc
1263             router/router.cpp
1264             router/router.h
1265             router/alc.cpp
1266             router/al.cpp
1267             ${COMMON_OBJS}
1268         )
1269         TARGET_COMPILE_DEFINITIONS(OpenAL
1270             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1271         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1272         TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS})
1273         TARGET_INCLUDE_DIRECTORIES(OpenAL
1274           PUBLIC
1275             $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1276             $<INSTALL_INTERFACE:include>
1277           PRIVATE
1278             ${OpenAL_SOURCE_DIR}/common
1279             ${OpenAL_BINARY_DIR}
1280         )
1281         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1282         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1283         IF(TARGET build_version)
1284             ADD_DEPENDENCIES(OpenAL build_version)
1285         ENDIF()
1286         SET(HAS_ROUTER 1)
1288         SET(LIBNAME "soft_oal")
1289         SET(IMPL_TARGET soft_oal)
1290         SET(RC_CONFIG resources/soft_oal.rc)
1291     ENDIF()
1293     ADD_LIBRARY(${IMPL_TARGET} SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS} ${RC_CONFIG})
1294     IF(WIN32)
1295         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1296     ENDIF()
1297 ENDIF()
1299 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1300     PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1302 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1303   PUBLIC
1304     $<BUILD_INTERFACE:${OpenAL_SOURCE_DIR}/include>
1305     $<INSTALL_INTERFACE:include>
1306   PRIVATE
1307     ${INC_PATHS}
1308     ${OpenAL_BINARY_DIR}
1309     ${OpenAL_SOURCE_DIR}
1310     ${OpenAL_SOURCE_DIR}/alc
1311     ${OpenAL_SOURCE_DIR}/common
1314 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1315     VERSION ${LIB_VERSION}
1316     SOVERSION ${LIB_MAJOR_VERSION}
1318 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1319     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1320 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1322 IF(TARGET build_version)
1323     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1324 ENDIF()
1326 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1327     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1328     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1329     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1330         MESSAGE(STATUS "")
1331         IF(NOT SED_EXECUTABLE)
1332             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1333         ENDIF()
1334         IF(NOT DLLTOOL_EXECUTABLE)
1335             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1336         ENDIF()
1337     ELSE()
1338         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1339                         " -Wl,--output-def,OpenAL32.def")
1340         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1341             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1342             COMMAND "${DLLTOOL_EXECUTABLE}" -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(ALSOFT_INSTALL)
1350     INSTALL(TARGETS OpenAL EXPORT OpenAL
1351             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1352             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1353             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1354             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1355     )
1356     EXPORT(TARGETS OpenAL
1357            NAMESPACE OpenAL::
1358            FILE OpenALConfig.cmake)
1359     INSTALL(EXPORT OpenAL
1360             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1361             NAMESPACE OpenAL::
1362             FILE OpenALConfig.cmake)
1363     INSTALL(FILES include/AL/al.h
1364                   include/AL/alc.h
1365                   include/AL/alext.h
1366                   include/AL/efx.h
1367                   include/AL/efx-creative.h
1368                   include/AL/efx-presets.h
1369             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1370     )
1371     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1372             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1373     IF(TARGET soft_oal)
1374         INSTALL(TARGETS soft_oal
1375                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1376         )
1377     ENDIF()
1378 ENDIF()
1381 if(HAS_ROUTER)
1382     message(STATUS "")
1383     message(STATUS "Building DLL router")
1384 endif()
1386 MESSAGE(STATUS "")
1387 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1388 MESSAGE(STATUS "    ${BACKENDS}")
1389 MESSAGE(STATUS "")
1390 MESSAGE(STATUS "Building with support for CPU extensions:")
1391 MESSAGE(STATUS "    ${CPU_EXTS}")
1392 MESSAGE(STATUS "")
1393 IF(FPMATH_SET)
1394     MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
1395     MESSAGE(STATUS "")
1396 ENDIF()
1398 IF(WIN32)
1399     IF(NOT HAVE_DSOUND)
1400         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1401         MESSAGE(STATUS "         This is probably NOT what you want!")
1402         MESSAGE(STATUS "")
1403     ENDIF()
1404 ENDIF()
1406 if(ALSOFT_EMBED_HRTF_DATA)
1407     message(STATUS "Embedding HRTF datasets")
1408     message(STATUS "")
1409 endif()
1411 # Install alsoft.conf configuration file
1412 IF(ALSOFT_CONFIG)
1413     INSTALL(FILES alsoftrc.sample
1414             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1415     )
1416     MESSAGE(STATUS "Installing sample configuration")
1417     MESSAGE(STATUS "")
1418 ENDIF()
1420 # Install HRTF definitions
1421 IF(ALSOFT_HRTF_DEFS)
1422     INSTALL(FILES hrtf/default-44100.mhr
1423                   hrtf/default-48000.mhr
1424             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1425     )
1426     MESSAGE(STATUS "Installing HRTF definitions")
1427     MESSAGE(STATUS "")
1428 ENDIF()
1430 # Install AmbDec presets
1431 IF(ALSOFT_AMBDEC_PRESETS)
1432     INSTALL(FILES presets/3D7.1.ambdec
1433                   presets/hexagon.ambdec
1434                   presets/itu5.1.ambdec
1435                   presets/itu5.1-nocenter.ambdec
1436                   presets/rectangle.ambdec
1437                   presets/square.ambdec
1438                   presets/presets.txt
1439             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1440     )
1441     MESSAGE(STATUS "Installing AmbDec presets")
1442     MESSAGE(STATUS "")
1443 ENDIF()
1445 IF(ALSOFT_UTILS)
1446     set(UTIL_TARGETS )
1448     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1449     TARGET_INCLUDE_DIRECTORIES(openal-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1450     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1451     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1452     set(UTIL_TARGETS ${UTIL_TARGETS} openal-info)
1454     find_package(MySOFA)
1455     if(MYSOFA_FOUND)
1456         set(MAKEMHR_SRCS
1457             utils/makemhr/loaddef.cpp
1458             utils/makemhr/loaddef.h
1459             utils/makemhr/loadsofa.cpp
1460             utils/makemhr/loadsofa.h
1461             utils/makemhr/makemhr.cpp
1462             utils/makemhr/makemhr.h)
1463         if(NOT HAVE_GETOPT)
1464             set(MAKEMHR_SRCS  ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
1465         endif()
1466         add_executable(makemhr ${MAKEMHR_SRCS})
1467         target_compile_definitions(makemhr PRIVATE ${CPP_DEFS})
1468         target_include_directories(makemhr
1469             PRIVATE ${OpenAL_SOURCE_DIR}/common ${OpenAL_BINARY_DIR})
1470         target_compile_options(makemhr PRIVATE ${C_FLAGS})
1471         target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} MySOFA::MySOFA)
1472         set(UTIL_TARGETS ${UTIL_TARGETS} makemhr)
1474         set(SOFAINFO_SRCS  utils/sofa-info.cpp)
1475         add_executable(sofa-info ${SOFAINFO_SRCS})
1476         target_compile_definitions(sofa-info PRIVATE ${CPP_DEFS})
1477         target_include_directories(sofa-info PRIVATE ${OpenAL_SOURCE_DIR}/common)
1478         target_compile_options(sofa-info PRIVATE ${C_FLAGS})
1479         target_link_libraries(sofa-info PRIVATE ${LINKER_FLAGS} MySOFA::MySOFA)
1480     endif()
1482     IF(ALSOFT_INSTALL)
1483         INSTALL(TARGETS ${UTIL_TARGETS}
1484                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1485                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1486                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1487         )
1488     ENDIF()
1490     MESSAGE(STATUS "Building utility programs")
1491     IF(TARGET alsoft-config)
1492         MESSAGE(STATUS "Building configuration program")
1493     ENDIF()
1494     MESSAGE(STATUS "")
1495 ENDIF()
1497 IF(ALSOFT_EXAMPLES OR ALSOFT_TESTS)
1498     # Add a static library with common functions used by multiple targets
1499     ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1500     TARGET_COMPILE_DEFINITIONS(ex-common PUBLIC ${CPP_DEFS})
1501     TARGET_INCLUDE_DIRECTORIES(ex-common PUBLIC ${OpenAL_SOURCE_DIR}/common)
1502     TARGET_COMPILE_OPTIONS(ex-common PUBLIC ${C_FLAGS})
1503     TARGET_LINK_LIBRARIES(ex-common PUBLIC OpenAL)
1504 ENDIF()
1506 IF(ALSOFT_TESTS)
1507     ADD_EXECUTABLE(altonegen examples/altonegen.c)
1508     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1509     TARGET_INCLUDE_DIRECTORIES(altonegen PRIVATE ${OpenAL_SOURCE_DIR}/common)
1510     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1511     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} ${MATH_LIB} ex-common)
1513     IF(ALSOFT_INSTALL)
1514         INSTALL(TARGETS altonegen
1515                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1516                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1517                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1518         )
1519     ENDIF()
1521     MESSAGE(STATUS "Building test programs")
1522     MESSAGE(STATUS "")
1523 ENDIF()
1525 IF(ALSOFT_EXAMPLES)
1526     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1527     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common)
1529     IF(ALSOFT_INSTALL)
1530         INSTALL(TARGETS alrecord
1531                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1532                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1533                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1534         )
1535     ENDIF()
1537     MESSAGE(STATUS "Building example programs")
1539     IF(SDL2_FOUND)
1540         IF(SDL_SOUND_FOUND)
1541             ADD_EXECUTABLE(alplay examples/alplay.c)
1542             TARGET_INCLUDE_DIRECTORIES(alplay
1543                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1544             TARGET_LINK_LIBRARIES(alplay
1545                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1547             ADD_EXECUTABLE(alstream examples/alstream.c)
1548             TARGET_INCLUDE_DIRECTORIES(alstream
1549                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1550             TARGET_LINK_LIBRARIES(alstream
1551                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1553             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1554             TARGET_INCLUDE_DIRECTORIES(alreverb
1555                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1556             TARGET_LINK_LIBRARIES(alreverb
1557                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1559             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1560             TARGET_INCLUDE_DIRECTORIES(almultireverb
1561                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1562             TARGET_LINK_LIBRARIES(almultireverb
1563                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common
1564                 ${MATH_LIB})
1566             ADD_EXECUTABLE(allatency examples/allatency.c)
1567             TARGET_INCLUDE_DIRECTORIES(allatency
1568                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1569             TARGET_LINK_LIBRARIES(allatency
1570                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common)
1572             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1573             TARGET_INCLUDE_DIRECTORIES(alloopback
1574                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1575             TARGET_LINK_LIBRARIES(alloopback
1576                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1578             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1579             TARGET_INCLUDE_DIRECTORIES(alhrtf
1580                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1581             TARGET_LINK_LIBRARIES(alhrtf
1582                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB})
1584             IF(ALSOFT_INSTALL)
1585                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1586                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1587                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1588                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1589                 )
1590             ENDIF()
1592             MESSAGE(STATUS "Building SDL_sound example programs")
1593         ENDIF()
1595         SET(FFVER_OK FALSE)
1596         IF(FFMPEG_FOUND)
1597             SET(FFVER_OK TRUE)
1598             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1599                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1600                 SET(FFVER_OK FALSE)
1601             ENDIF()
1602             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1603                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1604                 SET(FFVER_OK FALSE)
1605             ENDIF()
1606             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1607                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1608                 SET(FFVER_OK FALSE)
1609             ENDIF()
1610             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1611                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1612                 SET(FFVER_OK FALSE)
1613             ENDIF()
1614             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1615                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1616                 SET(FFVER_OK FALSE)
1617             ENDIF()
1618         ENDIF()
1619         IF(FFVER_OK)
1620             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1621             TARGET_INCLUDE_DIRECTORIES(alffplay
1622                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1623             TARGET_LINK_LIBRARIES(alffplay
1624                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common)
1626             IF(ALSOFT_INSTALL)
1627                 INSTALL(TARGETS alffplay
1628                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1629                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1630                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1631                 )
1632             ENDIF()
1633             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1634         ENDIF()
1635         MESSAGE(STATUS "")
1636     ENDIF()
1637 ENDIF()