Clean up MixSource
[openal-soft.git] / CMakeLists.txt
blob6bbbc5613e388804117019642cdb314e6aabcf90
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(CheckSharedFunctionExists)
29 INCLUDE(CheckIncludeFile)
30 INCLUDE(CheckIncludeFiles)
31 INCLUDE(CheckSymbolExists)
32 INCLUDE(CheckCCompilerFlag)
33 INCLUDE(CheckCXXCompilerFlag)
34 INCLUDE(CheckCSourceCompiles)
35 INCLUDE(CheckCXXSourceCompiles)
36 INCLUDE(CheckTypeSize)
37 include(CheckStructHasMember)
38 include(CheckFileOffsetBits)
39 include(GNUInstallDirs)
41 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
44 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
46 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
48 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
49 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
51 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
52 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
54 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
55 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
56 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
57 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
59 if(DEFINED SHARE_INSTALL_DIR)
60     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
61     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
62 endif()
64 if(DEFINED LIB_SUFFIX)
65     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
66 endif()
69 SET(CPP_DEFS ) # C pre-process, not C++
70 SET(INC_PATHS )
71 SET(C_FLAGS )
72 SET(LINKER_FLAGS )
73 SET(EXTRA_LIBS )
75 IF(WIN32)
76     SET(CPP_DEFS ${CPP_DEFS} _WIN32 _WIN32_WINNT=0x0502)
78     OPTION(ALSOFT_BUILD_ROUTER  "Build the router (EXPERIMENTAL; creates OpenAL32.dll and soft_oal.dll)"  OFF)
80     # This option is mainly for static linking OpenAL Soft into another project
81     # that already defines the IDs. It is up to that project to ensure all
82     # required IDs are defined.
83     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
85     IF(MINGW)
86         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
87         IF(NOT DLLTOOL)
88             IF(HOST)
89                 SET(DLLTOOL "${HOST}-dlltool")
90             ELSE()
91                 SET(DLLTOOL "dlltool")
92             ENDIF()
93         ENDIF()
94     ENDIF()
95 ENDIF()
98 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
99 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
100     SET(INC_PATHS ${INC_PATHS} /usr/include)
101     SET(LINKER_FLAGS ${LINKER_FLAGS} -L/usr/lib)
102 ENDIF()
104 IF(NOT LIBTYPE)
105     SET(LIBTYPE SHARED)
106 ENDIF()
108 SET(LIB_MAJOR_VERSION "1")
109 SET(LIB_MINOR_VERSION "19")
110 SET(LIB_REVISION "1")
111 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
113 SET(EXPORT_DECL "")
114 SET(ALIGN_DECL "")
117 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
118 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
121 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
122 IF(HAVE_STD_C11)
123     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
124 ELSE()
125     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
126     IF(HAVE_STD_C99)
127         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
128     ENDIF()
129 ENDIF()
131 CHECK_CXX_COMPILER_FLAG(-std=c++11 HAVE_STD_CXX11)
132 IF(HAVE_STD_CXX11)
133     SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
134 ENDIF()
136 if(NOT WIN32)
137     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
138     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
139     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
140         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
141         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600")
142         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
143         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
144             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
145         ELSE()
146             SET(CPP_DEFS ${CPP_DEFS} _POSIX_C_SOURCE=200112L _XOPEN_SOURCE=600)
147         ENDIF()
148     ENDIF()
149     UNSET(OLD_REQUIRED_FLAGS)
150 ENDIF()
152 # Set defines for large file support. Don't set this for Android targets. See:
153 # https://android-developers.googleblog.com/2017/09/introducing-android-native-development.html
154 IF(NOT ANDROID)
155     CHECK_FILE_OFFSET_BITS()
156     IF(_FILE_OFFSET_BITS)
157         SET(CPP_DEFS ${CPP_DEFS} "_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
158         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
159     ENDIF()
160     SET(CPP_DEFS ${CPP_DEFS} _LARGEFILE_SOURCE _LARGE_FILES)
161     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
162 ENDIF()
164 # C99 has restrict, but C++ does not, so we can only utilize __restrict.
165 SET(RESTRICT_DECL )
166 CHECK_C_SOURCE_COMPILES("int *__restrict foo;
167                          int main() {return 0;}" HAVE___RESTRICT)
168 IF(HAVE___RESTRICT)
169     SET(RESTRICT_DECL "__restrict")
170 ENDIF()
172 # MSVC may need workarounds for C99 inline
173 IF(MSVC)
174     # TODO: Once we truly require C99, this inline check should go away.
175     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
176                              int main() {return 0;}" HAVE_INLINE)
177     IF(NOT HAVE_INLINE)
178         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
179                                  int main() {return 0;}" HAVE___INLINE)
180         IF(NOT HAVE___INLINE)
181             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
182         ENDIF()
184         SET(CPP_DEFS ${CPP_DEFS} inline=__inline)
185         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
186     ENDIF()
187 ENDIF()
189 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
190 IF(CMAKE_COMPILER_IS_GNUCC)
191     SET(CMAKE_C_FLAGS "-fno-gnu89-inline ${CMAKE_C_FLAGS}")
193     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
194     # Force no inlining for the next test.
195     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
197     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
198                              int main() {return foo();}" INLINE_IS_C99)
199     IF(NOT INLINE_IS_C99)
200         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
201                              Please update your compiler for better C99 compliance.")
202     ENDIF()
204     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
205 ENDIF()
207 # Check if we have a proper timespec declaration
208 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
209 IF(HAVE_STRUCT_TIMESPEC)
210     # Define it here so we don't have to include config.h for it
211     SET(CPP_DEFS ${CPP_DEFS} HAVE_STRUCT_TIMESPEC)
212 ENDIF()
214 # Some systems may need libatomic for C11 atomic functions to work
215 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
216 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
217 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
218 int _Atomic foo = ATOMIC_VAR_INIT(0);
219 int main()
221     return atomic_fetch_add(&foo, 2);
223 HAVE_LIBATOMIC)
224 IF(NOT HAVE_LIBATOMIC)
225     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
226 ELSE()
227     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
228 ENDIF()
229 UNSET(OLD_REQUIRED_LIBRARIES)
231 # Include liblog for Android logging
232 CHECK_LIBRARY_EXISTS(log __android_log_print "" HAVE_LIBLOG)
233 IF(HAVE_LIBLOG)
234     SET(EXTRA_LIBS log ${EXTRA_LIBS})
235     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log)
236 ENDIF()
238 # Add definitions, compiler switches, etc.
239 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}")
241 IF(NOT CMAKE_BUILD_TYPE)
242     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
243         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
244         FORCE)
245 ENDIF()
246 IF(NOT CMAKE_DEBUG_POSTFIX)
247     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
248         "Library postfix for debug builds. Normally left blank."
249         FORCE)
250 ENDIF()
252 IF(MSVC)
253     SET(CPP_DEFS ${CPP_DEFS} _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE NOMINMAX)
254     SET(C_FLAGS ${C_FLAGS} /wd4098 /wd4200)
256     IF(NOT DXSDK_DIR)
257         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
258     ELSE()
259         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
260     ENDIF()
261     IF(DXSDK_DIR)
262         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
263     ENDIF()
265     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
266     IF(FORCE_STATIC_VCRT)
267         FOREACH(flag_var
268                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
269                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
270             IF(${flag_var} MATCHES "/MD")
271                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
272             ENDIF()
273         ENDFOREACH(flag_var)
274     ENDIF()
275 ELSE()
276     SET(C_FLAGS ${C_FLAGS} -Winline -Wall)
277     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
278     IF(HAVE_W_EXTRA)
279         SET(C_FLAGS ${C_FLAGS} -Wextra)
280     ENDIF()
282     IF(ALSOFT_WERROR)
283         SET(C_FLAGS ${C_FLAGS} -Werror)
284     ENDIF()
286     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
287     # instead of NDEBUG)
288     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
289         IF(${flag_var} MATCHES "-DNDEBUG")
290             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
291         ENDIF()
292     ENDFOREACH()
294     CHECK_C_COMPILER_FLAG(-fno-math-errno HAVE_FNO_MATH_ERRNO)
295     IF(HAVE_FNO_MATH_ERRNO)
296         SET(C_FLAGS ${C_FLAGS} -fno-math-errno)
297     ENDIF()
299     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
300                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
302     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
303     if(ALSOFT_STATIC_LIBGCC)
304         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
305         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
306         check_c_source_compiles(
307 "#include <stdlib.h>
308 int main()
310     return 0;
312             HAVE_STATIC_LIBGCC_SWITCH
313         )
314         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
315         unset(OLD_REQUIRED_LIBRARIES)
317         if(NOT HAVE_STATIC_LIBGCC_SWITCH)
318             message(FATAL_ERROR "Cannot static link libgcc")
319         endif()
320         set(LINKER_FLAGS ${LINKER_FLAGS} -static-libgcc)
321     endif()
323     option(ALSOFT_STATIC_STDCXX "Static link libstdc++" OFF)
324     if(ALSOFT_STATIC_STDCXX)
325         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
326         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
327         check_cxx_source_compiles(
328 "#include <cstdlib>
329 int main()
331     return 0;
333             HAVE_STATIC_LIBSTDCXX_SWITCH
334         )
335         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
336         unset(OLD_REQUIRED_LIBRARIES)
338         if(NOT HAVE_STATIC_LIBSTDCXX_SWITCH)
339             message(FATAL_ERROR "Cannot static link libstdc++")
340         endif()
341         set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lstdc++,--pop-state")
342     endif()
344     if(WIN32)
345         option(ALSOFT_STATIC_WINPTHREAD "Static link libwinpthread" OFF)
346         if(ALSOFT_STATIC_WINPTHREAD)
347             set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
348             set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
349             check_cxx_source_compiles(
350 "#include <cstdlib>
351 int main()
353     return 0;
355                 HAVE_STATIC_LIBWINPTHREAD_SWITCH
356             )
357             set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
358             unset(OLD_REQUIRED_LIBRARIES)
360             if(NOT HAVE_STATIC_LIBWINPTHREAD_SWITCH)
361                 message(FATAL_ERROR "Cannot static link libwinpthread")
362             endif()
363             set(LINKER_FLAGS ${LINKER_FLAGS} "-Wl,--push-state,-Bstatic,-lwinpthread,--pop-state")
364         endif()
365     endif()
366 ENDIF()
368 # Set visibility/export options if available
369 IF(WIN32)
370     SET(EXPORT_DECL "__declspec(dllexport)")
371     IF(NOT MINGW)
372         SET(ALIGN_DECL "__declspec(align(x))")
373     ELSE()
374         SET(ALIGN_DECL "__declspec(aligned(x))")
375     ENDIF()
376 ELSE()
377     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
378     # Yes GCC, really don't accept visibility modes you don't support
379     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
381     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
382                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
383     IF(HAVE_GCC_PROTECTED_VISIBILITY)
384         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
385     ELSE()
386         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
387                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
388         IF(HAVE_GCC_DEFAULT_VISIBILITY)
389             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
390         ENDIF()
391     ENDIF()
393     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
394         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
395         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
396             SET(C_FLAGS ${C_FLAGS} -fvisibility=hidden)
397         ENDIF()
398     ENDIF()
400     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
401                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
402     IF(HAVE_ATTRIBUTE_ALIGNED)
403         SET(ALIGN_DECL "__attribute__((aligned(x)))")
404     ENDIF()
406     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
407 ENDIF()
409 SET(SSE_SWITCH "")
410 SET(SSE2_SWITCH "")
411 SET(SSE3_SWITCH "")
412 SET(SSE4_1_SWITCH "")
413 SET(FPU_NEON_SWITCH "")
415 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
416 IF(HAVE_MSSE_SWITCH)
417     SET(SSE_SWITCH "-msse")
418 ENDIF()
419 CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
420 IF(HAVE_MSSE2_SWITCH)
421     SET(SSE2_SWITCH "-msse2")
422 ENDIF()
423 CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
424 IF(HAVE_MSSE3_SWITCH)
425     SET(SSE3_SWITCH "-msse3")
426 ENDIF()
427 CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
428 IF(HAVE_MSSE4_1_SWITCH)
429     SET(SSE4_1_SWITCH "-msse4.1")
430 ENDIF()
431 CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
432 IF(HAVE_MFPU_NEON_SWITCH)
433     SET(FPU_NEON_SWITCH "-mfpu=neon")
434 ENDIF()
436 SET(FPMATH_SET "0")
437 IF(CMAKE_SIZEOF_VOID_P MATCHES "4")
438     IF(SSE_SWITCH OR MSVC)
439         OPTION(ALSOFT_ENABLE_SSE_CODEGEN "Enable SSE code generation instead of x87 for 32-bit targets." TRUE)
440     ENDIF()
441     IF(SSE2_SWITCH OR MSVC)
442         OPTION(ALSOFT_ENABLE_SSE2_CODEGEN "Enable SSE2 code generation instead of x87 for 32-bit targets." TRUE)
443     ENDIF()
445     IF(ALSOFT_ENABLE_SSE2_CODEGEN)
446         IF(SSE2_SWITCH)
447             CHECK_C_COMPILER_FLAG("${SSE2_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE_2)
448             IF(HAVE_MFPMATH_SSE_2)
449                 SET(C_FLAGS ${C_FLAGS} ${SSE2_SWITCH} -mfpmath=sse)
450                 SET(FPMATH_SET 2)
451             ENDIF()
452         ELSEIF(MSVC)
453             CHECK_C_COMPILER_FLAG("/arch:SSE2" HAVE_ARCH_SSE2)
454             IF(HAVE_ARCH_SSE2)
455                 SET(C_FLAGS ${C_FLAGS} "/arch:SSE2")
456                 SET(FPMATH_SET 2)
457             ENDIF()
458         ENDIF()
459     ENDIF()
460     IF(ALSOFT_ENABLE_SSE_CODEGEN AND NOT FPMATH_SET)
461         IF(SSE_SWITCH)
462             CHECK_C_COMPILER_FLAG("${SSE_SWITCH} -mfpmath=sse" HAVE_MFPMATH_SSE)
463             IF(HAVE_MFPMATH_SSE)
464                 SET(C_FLAGS ${C_FLAGS} ${SSE_SWITCH} -mfpmath=sse)
465                 SET(FPMATH_SET 1)
466             ENDIF()
467         ELSEIF(MSVC)
468             CHECK_C_COMPILER_FLAG("/arch:SSE" HAVE_ARCH_SSE)
469             IF(HAVE_ARCH_SSE)
470                 SET(C_FLAGS ${C_FLAGS} "/arch:SSE")
471                 SET(FPMATH_SET 1)
472             ENDIF()
473         ENDIF()
474     ENDIF()
475 ENDIF()
478 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
479                          int main() {return 0;}" HAVE_GCC_FORMAT)
481 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
482 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
483 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
484 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
485 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
486 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
487 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
488 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
489 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
490 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
491 IF(NOT HAVE_GUIDDEF_H)
492     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
493 ENDIF()
495 # Some systems need libm for some of the following math functions to work
496 SET(MATH_LIB )
497 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
498 IF(HAVE_LIBM)
499     SET(MATH_LIB ${MATH_LIB} m)
500     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
501 ENDIF()
503 # Check for the dlopen API (for dynamicly loading backend libs)
504 IF(ALSOFT_DLOPEN)
505     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
506     IF(HAVE_LIBDL)
507         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
508         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
509     ENDIF()
511     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
512 ENDIF()
514 # Check for a cpuid intrinsic
515 IF(HAVE_CPUID_H)
516     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
517         int main()
518         {
519             unsigned int eax, ebx, ecx, edx;
520             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
521         }" HAVE_GCC_GET_CPUID)
522 ENDIF()
523 IF(HAVE_INTRIN_H)
524     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
525         int main()
526         {
527             int regs[4];
528             __cpuid(regs, 0);
529             return regs[0];
530         }" HAVE_CPUID_INTRINSIC)
531     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
532         int main()
533         {
534             unsigned long idx = 0;
535             _BitScanForward64(&idx, 1);
536             return idx;
537         }" HAVE_BITSCANFORWARD64_INTRINSIC)
538     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
539         int main()
540         {
541             unsigned long idx = 0;
542             _BitScanForward(&idx, 1);
543             return idx;
544         }" HAVE_BITSCANFORWARD_INTRINSIC)
545 ENDIF()
547 CHECK_SYMBOL_EXISTS(sysconf          unistd.h HAVE_SYSCONF)
548 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
549 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
550 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
551 CHECK_SYMBOL_EXISTS(proc_pidpath     libproc.h HAVE_PROC_PIDPATH)
553 IF(HAVE_FLOAT_H)
554     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
555     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
556 ENDIF()
558 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
559 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
560 IF(NOT HAVE_STRCASECMP)
561     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
562     IF(NOT HAVE__STRICMP)
563         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
564     ENDIF()
566     SET(CPP_DEFS ${CPP_DEFS} strcasecmp=_stricmp)
567 ENDIF()
569 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
570 IF(NOT HAVE_STRNCASECMP)
571     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
572     IF(NOT HAVE__STRNICMP)
573         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
574     ENDIF()
576     SET(CPP_DEFS ${CPP_DEFS} strncasecmp=_strnicmp)
577 ENDIF()
580 # Check if we have Windows headers
581 SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
582 SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
583 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
584 SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
585 UNSET(OLD_REQUIRED_DEFINITIONS)
587 IF(NOT HAVE_WINDOWS_H)
588     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
589     IF(NOT HAVE_GETTIMEOFDAY)
590         MESSAGE(FATAL_ERROR "No timing function found!")
591     ENDIF()
593     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
594     IF(NOT HAVE_NANOSLEEP)
595         MESSAGE(FATAL_ERROR "No sleep function found!")
596     ENDIF()
598     # We need pthreads outside of Windows
599     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
600     IF(NOT HAVE_PTHREAD_H)
601         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
602     ENDIF()
603     # Some systems need pthread_np.h to get recursive mutexes
604     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
606     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
607     IF(HAVE_PTHREAD)
608         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
609         SET(C_FLAGS ${C_FLAGS} -pthread)
610         SET(LINKER_FLAGS ${LINKER_FLAGS} -pthread)
611     ENDIF()
613     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
614     IF(HAVE_LIBPTHREAD)
615         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
616     ENDIF()
618     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
620     IF(HAVE_PTHREAD_NP_H)
621         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
622         IF(NOT HAVE_PTHREAD_SETNAME_NP)
623             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
624         ELSE()
625             CHECK_C_SOURCE_COMPILES("
626 #include <pthread.h>
627 #include <pthread_np.h>
628 int main()
630     pthread_setname_np(\"testname\");
631     return 0;
633                 PTHREAD_SETNAME_NP_ONE_PARAM
634             )
635             CHECK_C_SOURCE_COMPILES("
636 #include <pthread.h>
637 #include <pthread_np.h>
638 int main()
640     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
641     return 0;
643                 PTHREAD_SETNAME_NP_THREE_PARAMS
644             )
645         ENDIF()
646         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
647     ELSE()
648         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
649         IF(NOT HAVE_PTHREAD_SETNAME_NP)
650             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
651         ELSE()
652             CHECK_C_SOURCE_COMPILES("
653 #include <pthread.h>
654 int main()
656     pthread_setname_np(\"testname\");
657     return 0;
659                 PTHREAD_SETNAME_NP_ONE_PARAM
660             )
661             CHECK_C_SOURCE_COMPILES("
662 #include <pthread.h>
663 int main()
665     pthread_setname_np(pthread_self(), \"%s\", \"testname\");
666     return 0;
668                 PTHREAD_SETNAME_NP_THREE_PARAMS
669             )
670         ENDIF()
671         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
672     ENDIF()
674     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
676     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
677     IF(HAVE_LIBRT)
678         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
679     ENDIF()
680 ENDIF()
682 CHECK_SYMBOL_EXISTS(getopt unistd.h HAVE_GETOPT)
684 # Check for a 64-bit type
685 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
686 IF(NOT HAVE_STDINT_H)
687     IF(HAVE_WINDOWS_H)
688         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
689                                  #include <windows.h>
690                                  __int64 foo;
691                                  int main() {return 0;}" HAVE___INT64)
692     ENDIF()
693     IF(NOT HAVE___INT64)
694         IF(NOT SIZEOF_LONG MATCHES "8")
695             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
696                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
697             ENDIF()
698         ENDIF()
699     ENDIF()
700 ENDIF()
703 SET(COMMON_OBJS
704     common/alcomplex.cpp
705     common/alcomplex.h
706     common/almalloc.cpp
707     common/almalloc.h
708     common/atomic.h
709     common/math_defs.h
710     common/threads.cpp
711     common/threads.h
712     common/uintmap.h
713     common/vecmat.cpp
714     common/vecmat.h
716 SET(OPENAL_OBJS
717     OpenAL32/Include/alMain.h
718     OpenAL32/Include/alu.h
720     OpenAL32/Include/alAuxEffectSlot.h
721     OpenAL32/alAuxEffectSlot.cpp
722     OpenAL32/Include/alBuffer.h
723     OpenAL32/alBuffer.cpp
724     OpenAL32/Include/alEffect.h
725     OpenAL32/alEffect.cpp
726     OpenAL32/Include/alError.h
727     OpenAL32/alError.cpp
728     OpenAL32/alExtension.cpp
729     OpenAL32/Include/alFilter.h
730     OpenAL32/alFilter.cpp
731     OpenAL32/Include/alListener.h
732     OpenAL32/alListener.cpp
733     OpenAL32/Include/alSource.h
734     OpenAL32/alSource.cpp
735     OpenAL32/alState.cpp
736     OpenAL32/event.cpp
737     OpenAL32/Include/sample_cvt.h
738     OpenAL32/sample_cvt.cpp
740 SET(ALC_OBJS
741     Alc/alc.cpp
742     Alc/alu.cpp
743     Alc/alconfig.cpp
744     Alc/alconfig.h
745     Alc/alcontext.h
746     Alc/bs2b.cpp
747     Alc/bs2b.h
748     Alc/converter.cpp
749     Alc/converter.h
750     Alc/inprogext.h
751     Alc/mastering.cpp
752     Alc/mastering.h
753     Alc/ringbuffer.cpp
754     Alc/ringbuffer.h
755     Alc/effects/autowah.cpp
756     Alc/effects/chorus.cpp
757     Alc/effects/compressor.cpp
758     Alc/effects/dedicated.cpp
759     Alc/effects/distortion.cpp
760     Alc/effects/echo.cpp
761     Alc/effects/equalizer.cpp
762     Alc/effects/fshifter.cpp
763     Alc/effects/modulator.cpp
764     Alc/effects/null.cpp
765     Alc/effects/pshifter.cpp
766     Alc/effects/reverb.cpp
767     Alc/filters/defs.h
768     Alc/filters/filter.cpp
769     Alc/filters/nfc.cpp
770     Alc/filters/nfc.h
771     Alc/filters/splitter.cpp
772     Alc/filters/splitter.h
773     Alc/helpers.cpp
774     Alc/compat.h
775     Alc/cpu_caps.h
776     Alc/fpu_modes.h
777     Alc/logging.h
778     Alc/vector.h
779     Alc/hrtf.cpp
780     Alc/hrtf.h
781     Alc/uhjfilter.cpp
782     Alc/uhjfilter.h
783     Alc/ambdec.cpp
784     Alc/ambdec.h
785     Alc/bformatdec.cpp
786     Alc/bformatdec.h
787     Alc/panning.cpp
788     Alc/polymorphism.h
789     Alc/mixvoice.cpp
790     Alc/mixer/defs.h
791     Alc/mixer/mixer_c.cpp
795 SET(CPU_EXTS "Default")
796 SET(HAVE_SSE        0)
797 SET(HAVE_SSE2       0)
798 SET(HAVE_SSE3       0)
799 SET(HAVE_SSE4_1     0)
800 SET(HAVE_NEON       0)
802 SET(HAVE_ALSA       0)
803 SET(HAVE_OSS        0)
804 SET(HAVE_SOLARIS    0)
805 SET(HAVE_SNDIO      0)
806 SET(HAVE_QSA        0)
807 SET(HAVE_DSOUND     0)
808 SET(HAVE_WASAPI     0)
809 SET(HAVE_WINMM      0)
810 SET(HAVE_PORTAUDIO  0)
811 SET(HAVE_PULSEAUDIO 0)
812 SET(HAVE_COREAUDIO  0)
813 SET(HAVE_OPENSL     0)
814 SET(HAVE_WAVE       0)
815 SET(HAVE_SDL2       0)
817 # Check for SSE support
818 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
819 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
820 IF(HAVE_XMMINTRIN_H)
821     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
822     IF(ALSOFT_CPUEXT_SSE)
823         SET(HAVE_SSE 1)
824         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse.cpp)
825         IF(SSE_SWITCH)
826             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse.cpp PROPERTIES
827                                         COMPILE_FLAGS "${SSE_SWITCH}")
828         ENDIF()
829         SET(CPU_EXTS "${CPU_EXTS}, SSE")
830     ENDIF()
831 ENDIF()
832 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
833     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
834 ENDIF()
836 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
837 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
838 IF(HAVE_EMMINTRIN_H)
839     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
840     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
841         SET(HAVE_SSE2 1)
842         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse2.cpp)
843         IF(SSE2_SWITCH)
844             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse2.cpp PROPERTIES
845                                         COMPILE_FLAGS "${SSE2_SWITCH}")
846         ENDIF()
847         SET(CPU_EXTS "${CPU_EXTS}, SSE2")
848     ENDIF()
849 ENDIF()
850 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
851     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
852 ENDIF()
854 OPTION(ALSOFT_REQUIRE_SSE3 "Require SSE3 support" OFF)
855 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
856 IF(HAVE_EMMINTRIN_H)
857     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
858     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
859         SET(HAVE_SSE3 1)
860         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse3.cpp)
861         IF(SSE2_SWITCH)
862             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse3.cpp PROPERTIES
863                                         COMPILE_FLAGS "${SSE3_SWITCH}")
864         ENDIF()
865         SET(CPU_EXTS "${CPU_EXTS}, SSE3")
866     ENDIF()
867 ENDIF()
868 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
869     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
870 ENDIF()
872 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
873 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
874 IF(HAVE_SMMINTRIN_H)
875     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
876     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
877         SET(HAVE_SSE4_1 1)
878         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_sse41.cpp)
879         IF(SSE4_1_SWITCH)
880             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_sse41.cpp PROPERTIES
881                                         COMPILE_FLAGS "${SSE4_1_SWITCH}")
882         ENDIF()
883         SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
884     ENDIF()
885 ENDIF()
886 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
887     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
888 ENDIF()
890 # Check for ARM Neon support
891 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
892 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H ${FPU_NEON_SWITCH})
893 IF(HAVE_ARM_NEON_H)
894     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
895     IF(ALSOFT_CPUEXT_NEON)
896         SET(HAVE_NEON 1)
897         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer/mixer_neon.cpp)
898         IF(FPU_NEON_SWITCH)
899             SET_SOURCE_FILES_PROPERTIES(Alc/mixer/mixer_neon.cpp PROPERTIES
900                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
901         ENDIF()
902         SET(CPU_EXTS "${CPU_EXTS}, Neon")
903     ENDIF()
904 ENDIF()
905 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
906     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
907 ENDIF()
910 IF(WIN32 OR HAVE_DLFCN_H)
911     SET(IS_LINKED "")
912     MACRO(ADD_BACKEND_LIBS _LIBS)
913     ENDMACRO()
914 ELSE()
915     SET(IS_LINKED " (linked)")
916     MACRO(ADD_BACKEND_LIBS _LIBS)
917         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
918     ENDMACRO()
919 ENDIF()
921 SET(BACKENDS "")
922 SET(ALC_OBJS  ${ALC_OBJS}
923     Alc/backends/base.cpp
924     Alc/backends/base.h
925     # Default backends, always available
926     Alc/backends/loopback.cpp
927     Alc/backends/loopback.h
928     Alc/backends/null.cpp
929     Alc/backends/null.h
932 # Check ALSA backend
933 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
934 FIND_PACKAGE(ALSA)
935 IF(ALSA_FOUND)
936     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
937     IF(ALSOFT_BACKEND_ALSA)
938         SET(HAVE_ALSA 1)
939         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
940         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.cpp Alc/backends/alsa.h)
941         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
942         SET(INC_PATHS ${INC_PATHS} ${ALSA_INCLUDE_DIRS})
943     ENDIF()
944 ENDIF()
945 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
946     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
947 ENDIF()
949 # Check OSS backend
950 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
951 FIND_PACKAGE(OSS)
952 IF(OSS_FOUND)
953     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
954     IF(ALSOFT_BACKEND_OSS)
955         SET(HAVE_OSS 1)
956         SET(BACKENDS  "${BACKENDS} OSS,")
957         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.cpp Alc/backends/oss.h)
958         IF(OSS_LIBRARIES)
959             SET(EXTRA_LIBS ${OSS_LIBRARIES} ${EXTRA_LIBS})
960         ENDIF()
961         SET(INC_PATHS ${INC_PATHS} ${OSS_INCLUDE_DIRS})
962     ENDIF()
963 ENDIF()
964 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
965     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
966 ENDIF()
968 # Check Solaris backend
969 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
970 FIND_PACKAGE(AudioIO)
971 IF(AUDIOIO_FOUND)
972     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
973     IF(ALSOFT_BACKEND_SOLARIS)
974         SET(HAVE_SOLARIS 1)
975         SET(BACKENDS  "${BACKENDS} Solaris,")
976         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.cpp Alc/backends/solaris.h)
977         SET(INC_PATHS ${INC_PATHS} ${AUDIOIO_INCLUDE_DIRS})
978     ENDIF()
979 ENDIF()
980 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
981     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
982 ENDIF()
984 # Check SndIO backend
985 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
986 FIND_PACKAGE(SoundIO)
987 IF(SOUNDIO_FOUND)
988     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
989     IF(ALSOFT_BACKEND_SNDIO)
990         SET(HAVE_SNDIO 1)
991         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
992         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.cpp Alc/backends/sndio.h)
993         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
994         SET(INC_PATHS ${INC_PATHS} ${SOUNDIO_INCLUDE_DIRS})
995     ENDIF()
996 ENDIF()
997 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
998     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
999 ENDIF()
1001 # Check QSA backend
1002 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
1003 FIND_PACKAGE(QSA)
1004 IF(QSA_FOUND)
1005     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
1006     IF(ALSOFT_BACKEND_QSA)
1007         SET(HAVE_QSA 1)
1008         SET(BACKENDS  "${BACKENDS} QSA (linked),")
1009         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.cpp Alc/backends/qsa.h)
1010         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
1011         SET(INC_PATHS ${INC_PATHS} ${QSA_INCLUDE_DIRS})
1012     ENDIF()
1013 ENDIF()
1014 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
1015     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
1016 ENDIF()
1018 # Check Windows-only backends
1019 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
1020 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
1021 OPTION(ALSOFT_REQUIRE_WASAPI "Require WASAPI backend" OFF)
1022 IF(HAVE_WINDOWS_H)
1023     SET(OLD_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS})
1024     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_WIN32_WINNT=0x0502)
1026     # Check MMSystem backend
1027     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
1028     IF(HAVE_MMSYSTEM_H)
1029         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
1030         IF(HAVE_LIBWINMM)
1031             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
1032             IF(ALSOFT_BACKEND_WINMM)
1033                 SET(HAVE_WINMM 1)
1034                 SET(BACKENDS  "${BACKENDS} WinMM,")
1035                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.cpp Alc/backends/winmm.h)
1036                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
1037             ENDIF()
1038         ENDIF()
1039     ENDIF()
1041     # Check DSound backend
1042     FIND_PACKAGE(DSound)
1043     IF(DSOUND_FOUND)
1044         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
1045         IF(ALSOFT_BACKEND_DSOUND)
1046             SET(HAVE_DSOUND 1)
1047             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
1048             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.cpp Alc/backends/dsound.h)
1049             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
1050             SET(INC_PATHS ${INC_PATHS} ${DSOUND_INCLUDE_DIRS})
1051         ENDIF()
1052     ENDIF()
1054     # Check for WASAPI backend
1055     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
1056     IF(HAVE_MMDEVICEAPI_H)
1057         OPTION(ALSOFT_BACKEND_WASAPI "Enable WASAPI backend" ON)
1058         IF(ALSOFT_BACKEND_WASAPI)
1059             SET(HAVE_WASAPI 1)
1060             SET(BACKENDS  "${BACKENDS} WASAPI,")
1061             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wasapi.cpp Alc/backends/wasapi.h)
1062         ENDIF()
1063     ENDIF()
1065     SET(CMAKE_REQUIRED_DEFINITIONS ${OLD_REQUIRED_DEFINITIONS})
1066     UNSET(OLD_REQUIRED_DEFINITIONS)
1067 ENDIF()
1068 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
1069     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
1070 ENDIF()
1071 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
1072     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
1073 ENDIF()
1074 IF(ALSOFT_REQUIRE_WASAPI AND NOT HAVE_WASAPI)
1075     MESSAGE(FATAL_ERROR "Failed to enabled required WASAPI backend")
1076 ENDIF()
1078 # Check PortAudio backend
1079 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
1080 FIND_PACKAGE(PortAudio)
1081 IF(PORTAUDIO_FOUND)
1082     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
1083     IF(ALSOFT_BACKEND_PORTAUDIO)
1084         SET(HAVE_PORTAUDIO 1)
1085         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
1086         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.cpp Alc/backends/portaudio.h)
1087         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
1088         SET(INC_PATHS ${INC_PATHS} ${PORTAUDIO_INCLUDE_DIRS})
1089     ENDIF()
1090 ENDIF()
1091 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1092     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1093 ENDIF()
1095 # Check PulseAudio backend
1096 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1097 FIND_PACKAGE(PulseAudio)
1098 IF(PULSEAUDIO_FOUND)
1099     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1100     IF(ALSOFT_BACKEND_PULSEAUDIO)
1101         SET(HAVE_PULSEAUDIO 1)
1102         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1103         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.cpp Alc/backends/pulseaudio.h)
1104         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1105         SET(INC_PATHS ${INC_PATHS} ${PULSEAUDIO_INCLUDE_DIRS})
1106     ENDIF()
1107 ENDIF()
1108 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1109     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1110 ENDIF()
1112 # Check JACK backend
1113 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1114 FIND_PACKAGE(JACK)
1115 IF(JACK_FOUND)
1116     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1117     IF(ALSOFT_BACKEND_JACK)
1118         SET(HAVE_JACK 1)
1119         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1120         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.cpp Alc/backends/jack.h)
1121         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1122         SET(INC_PATHS ${INC_PATHS} ${JACK_INCLUDE_DIRS})
1123     ENDIF()
1124 ENDIF()
1125 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1126     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1127 ENDIF()
1129 # Check CoreAudio backend
1130 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1131 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1132              NAMES CoreAudio
1133              PATHS /System/Library/Frameworks
1135 IF(COREAUDIO_FRAMEWORK)
1136     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1137     IF(ALSOFT_BACKEND_COREAUDIO)
1138         SET(HAVE_COREAUDIO 1)
1139         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.cpp Alc/backends/coreaudio.h)
1140         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1141         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1142         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1143         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1145         # Some versions of OSX may need the AudioToolbox framework. Add it if
1146         # it's found.
1147         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1148                      NAMES AudioToolbox
1149                      PATHS ~/Library/Frameworks
1150                            /Library/Frameworks
1151                            /System/Library/Frameworks
1152                     )
1153         IF(AUDIOTOOLBOX_LIBRARY)
1154             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1155         ENDIF()
1156     ENDIF()
1157 ENDIF()
1158 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1159     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1160 ENDIF()
1162 # Check for OpenSL (Android) backend
1163 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1164 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1165 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1166     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1167     IF(HAVE_LIBOPENSLES)
1168         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1169         IF(ALSOFT_BACKEND_OPENSL)
1170             SET(HAVE_OPENSL 1)
1171             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.cpp Alc/backends/opensl.h)
1172             SET(BACKENDS  "${BACKENDS} OpenSL,")
1173             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1174         ENDIF()
1175     ENDIF()
1176 ENDIF()
1177 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1178     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1179 ENDIF()
1181 # Check for SDL2 backend
1182 OPTION(ALSOFT_REQUIRE_SDL2 "Require SDL2 backend" OFF)
1183 FIND_PACKAGE(SDL2)
1184 IF(SDL2_FOUND)
1185     # Off by default, since it adds a runtime dependency
1186     OPTION(ALSOFT_BACKEND_SDL2 "Enable SDL2 backend" OFF)
1187     IF(ALSOFT_BACKEND_SDL2)
1188         SET(HAVE_SDL2 1)
1189         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sdl2.cpp Alc/backends/sdl2.h)
1190         SET(BACKENDS  "${BACKENDS} SDL2,")
1191         SET(EXTRA_LIBS ${SDL2_LIBRARY} ${EXTRA_LIBS})
1192         SET(INC_PATHS ${INC_PATHS} ${SDL2_INCLUDE_DIR})
1193     ENDIF()
1194 ENDIF()
1195 IF(ALSOFT_REQUIRE_SDL2 AND NOT SDL2_FOUND)
1196     MESSAGE(FATAL_ERROR "Failed to enabled required SDL2 backend")
1197 ENDIF()
1199 # Optionally enable the Wave Writer backend
1200 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1201 IF(ALSOFT_BACKEND_WAVE)
1202     SET(HAVE_WAVE 1)
1203     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.cpp Alc/backends/wave.h)
1204     SET(BACKENDS  "${BACKENDS} WaveFile,")
1205 ENDIF()
1207 # This is always available
1208 SET(BACKENDS  "${BACKENDS} Null")
1211 FIND_PACKAGE(Git)
1212 IF(GIT_FOUND AND EXISTS "${OpenAL_SOURCE_DIR}/.git")
1213     # Get the current working branch and its latest abbreviated commit hash
1214     ADD_CUSTOM_TARGET(build_version
1215         ${CMAKE_COMMAND} -D GIT_EXECUTABLE=${GIT_EXECUTABLE}
1216                          -D LIB_VERSION=${LIB_VERSION}
1217                          -D SRC=${OpenAL_SOURCE_DIR}/version.h.in
1218                          -D DST=${OpenAL_BINARY_DIR}/version.h
1219                          -P ${OpenAL_SOURCE_DIR}/version.cmake
1220         WORKING_DIRECTORY "${OpenAL_SOURCE_DIR}"
1221         VERBATIM
1222     )
1223 ELSE()
1224     SET(GIT_BRANCH "UNKNOWN")
1225     SET(GIT_COMMIT_HASH "unknown")
1226     CONFIGURE_FILE(
1227         "${OpenAL_SOURCE_DIR}/version.h.in"
1228         "${OpenAL_BINARY_DIR}/version.h")
1229 ENDIF()
1231 SET(NATIVE_SRC_DIR  "${OpenAL_SOURCE_DIR}/native-tools/")
1232 SET(NATIVE_BIN_DIR  "${OpenAL_BINARY_DIR}/native-tools/")
1233 FILE(MAKE_DIRECTORY "${NATIVE_BIN_DIR}")
1235 SET(BIN2H_COMMAND  "${NATIVE_BIN_DIR}bin2h")
1236 SET(BSINCGEN_COMMAND  "${NATIVE_BIN_DIR}bsincgen")
1237 ADD_CUSTOM_COMMAND(OUTPUT "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1238     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" "${NATIVE_SRC_DIR}"
1239     COMMAND ${CMAKE_COMMAND} -E remove "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1240     COMMAND ${CMAKE_COMMAND} --build . --config "Release"
1241     WORKING_DIRECTORY "${NATIVE_BIN_DIR}"
1242     DEPENDS "${NATIVE_SRC_DIR}CMakeLists.txt"
1243     IMPLICIT_DEPENDS C "${NATIVE_SRC_DIR}bin2h.c"
1244                      C "${NATIVE_SRC_DIR}bsincgen.c"
1245     VERBATIM
1247 ADD_CUSTOM_TARGET(native-tools
1248     DEPENDS "${BIN2H_COMMAND}" "${BSINCGEN_COMMAND}"
1249     VERBATIM
1252 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" ON)
1253 if(ALSOFT_EMBED_HRTF_DATA)
1254     MACRO(make_hrtf_header FILENAME VARNAME)
1255         SET(infile  "${OpenAL_SOURCE_DIR}/hrtf/${FILENAME}")
1256         SET(outfile  "${OpenAL_BINARY_DIR}/${FILENAME}.h")
1258         ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
1259             COMMAND "${BIN2H_COMMAND}" "${infile}" "${outfile}" ${VARNAME}
1260             DEPENDS native-tools "${infile}"
1261             VERBATIM
1262         )
1263         SET(ALC_OBJS  ${ALC_OBJS} "${outfile}")
1264     ENDMACRO()
1266     make_hrtf_header(default-44100.mhr "hrtf_default_44100")
1267     make_hrtf_header(default-48000.mhr "hrtf_default_48000")
1268 endif()
1270 ADD_CUSTOM_COMMAND(OUTPUT "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1271     COMMAND "${BSINCGEN_COMMAND}" "${OpenAL_BINARY_DIR}/bsinc_inc.h"
1272     DEPENDS native-tools "${NATIVE_SRC_DIR}bsincgen.c"
1273     VERBATIM
1275 SET(ALC_OBJS  ${ALC_OBJS} "${OpenAL_BINARY_DIR}/bsinc_inc.h")
1278 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1279     add_subdirectory(utils/alsoft-config)
1280 ENDIF()
1281 IF(ALSOFT_EXAMPLES)
1282     IF(NOT SDL2_FOUND)
1283         FIND_PACKAGE(SDL2)
1284     ENDIF()
1285     IF(SDL2_FOUND)
1286         FIND_PACKAGE(SDL_sound)
1287         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1288     ENDIF()
1289 ENDIF()
1291 IF(NOT WIN32)
1292     SET(LIBNAME "openal")
1293 ELSE()
1294     SET(LIBNAME "OpenAL32")
1295 ENDIF()
1297 # Needed for openal.pc.in
1298 SET(prefix ${CMAKE_INSTALL_PREFIX})
1299 SET(exec_prefix "\${prefix}")
1300 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1301 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1302 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1303 SET(PACKAGE_VERSION "${LIB_VERSION}")
1304 SET(PKG_CONFIG_CFLAGS )
1305 SET(PKG_CONFIG_PRIVATE_LIBS )
1306 IF(LIBTYPE STREQUAL "STATIC")
1307     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC)
1308     FOREACH(FLAG  ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1309         # If this is already a linker flag, or is a full path+file, add it
1310         # as-is. Otherwise, it's a name intended to be dressed as -lname.
1311         IF(FLAG MATCHES "^-.*" OR EXISTS "${FLAG}")
1312             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} ${FLAG}")
1313         ELSE()
1314             SET(PKG_CONFIG_PRIVATE_LIBS "${PKG_CONFIG_PRIVATE_LIBS} -l${FLAG}")
1315         ENDIF()
1316     ENDFOREACH()
1317 ENDIF()
1319 # End configuration
1320 CONFIGURE_FILE(
1321     "${OpenAL_SOURCE_DIR}/config.h.in"
1322     "${OpenAL_BINARY_DIR}/config.h")
1323 CONFIGURE_FILE(
1324     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1325     "${OpenAL_BINARY_DIR}/openal.pc"
1326     @ONLY)
1329 # Add a static library with common functions used by multiple targets
1330 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1331 TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS})
1332 TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS})
1335 UNSET(HAS_ROUTER)
1336 SET(IMPL_TARGET OpenAL)
1337 SET(COMMON_LIB )
1338 SET(SUBSYS_FLAG )
1340 # Build main library
1341 IF(LIBTYPE STREQUAL "STATIC")
1342     SET(CPP_DEFS ${CPP_DEFS} AL_LIBTYPE_STATIC)
1343     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1344         SET(CPP_DEFS ${CPP_DEFS} AL_NO_UID_DEFS)
1345     ENDIF()
1346     ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1347 ELSE()
1348     # Make sure to compile the common code with PIC, since it'll be linked into
1349     # shared libs that needs it.
1350     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1351     SET(COMMON_LIB common)
1353     IF(WIN32)
1354         IF(MSVC)
1355             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "/SUBSYSTEM:WINDOWS")
1356         ELSEIF(CMAKE_COMPILER_IS_GNUCC)
1357             SET(SUBSYS_FLAG ${SUBSYS_FLAG} "-mwindows")
1358         ENDIF()
1359     ENDIF()
1361     IF(WIN32 AND ALSOFT_BUILD_ROUTER)
1362         ADD_LIBRARY(OpenAL SHARED router/router.cpp router/router.h router/alc.cpp router/al.cpp)
1363         TARGET_COMPILE_DEFINITIONS(OpenAL
1364             PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1365         TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS})
1366         TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${COMMON_LIB} ${LINKER_FLAGS})
1367         SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "")
1368         SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME})
1369         IF(TARGET build_version)
1370             ADD_DEPENDENCIES(OpenAL build_version)
1371         ENDIF()
1372         SET(HAS_ROUTER 1)
1374         SET(LIBNAME "soft_oal")
1375         SET(IMPL_TARGET soft_oal)
1376     ENDIF()
1378     ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1379     IF(WIN32)
1380         SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "")
1381     ENDIF()
1382 ENDIF()
1383 SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME}
1384     VERSION ${LIB_VERSION}
1385     SOVERSION ${LIB_MAJOR_VERSION}
1387 TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET}
1388     PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS})
1389 TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET}
1390     PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS})
1391 TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS})
1392 TARGET_LINK_LIBRARIES(${IMPL_TARGET}
1393     PRIVATE ${COMMON_LIB} ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB})
1394 IF(TARGET build_version)
1395     ADD_DEPENDENCIES(${IMPL_TARGET} build_version)
1396 ENDIF()
1398 IF(WIN32 AND MINGW AND ALSOFT_BUILD_IMPORT_LIB AND NOT LIBTYPE STREQUAL "STATIC")
1399     FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1400     FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1401     IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1402         MESSAGE(STATUS "")
1403         IF(NOT SED_EXECUTABLE)
1404             MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1405         ENDIF()
1406         IF(NOT DLLTOOL_EXECUTABLE)
1407             MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1408         ENDIF()
1409     ELSE()
1410         SET_PROPERTY(TARGET OpenAL APPEND_STRING PROPERTY LINK_FLAGS
1411                         " -Wl,--output-def,OpenAL32.def")
1412         ADD_CUSTOM_COMMAND(TARGET OpenAL POST_BUILD
1413             COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" OpenAL32.def
1414             COMMAND "${DLLTOOL_EXECUTABLE}" -d OpenAL32.def -l OpenAL32.lib -D OpenAL32.dll
1415             COMMENT "Stripping ordinals from OpenAL32.def and generating OpenAL32.lib..."
1416             VERBATIM
1417         )
1418     ENDIF()
1419 ENDIF()
1421 IF(ALSOFT_INSTALL)
1422     INSTALL(TARGETS OpenAL EXPORT OpenAL
1423             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1424             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1425             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1426             INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_INSTALL_INCLUDEDIR}/AL
1427     )
1428     EXPORT(TARGETS OpenAL
1429            NAMESPACE OpenAL::
1430            FILE OpenALConfig.cmake)
1431     INSTALL(EXPORT OpenAL
1432             DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OpenAL
1433             NAMESPACE OpenAL::
1434             FILE OpenALConfig.cmake)
1435     INSTALL(FILES include/AL/al.h
1436                   include/AL/alc.h
1437                   include/AL/alext.h
1438                   include/AL/efx.h
1439                   include/AL/efx-creative.h
1440                   include/AL/efx-presets.h
1441             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1442     )
1443     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1444             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1445     IF(TARGET soft_oal)
1446         INSTALL(TARGETS soft_oal
1447                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1448         )
1449     ENDIF()
1450 ENDIF()
1453 if(HAS_ROUTER)
1454     message(STATUS "")
1455     message(STATUS "Building DLL router")
1456 endif()
1458 MESSAGE(STATUS "")
1459 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1460 MESSAGE(STATUS "    ${BACKENDS}")
1461 MESSAGE(STATUS "")
1462 MESSAGE(STATUS "Building with support for CPU extensions:")
1463 MESSAGE(STATUS "    ${CPU_EXTS}")
1464 MESSAGE(STATUS "")
1465 IF(FPMATH_SET)
1466     MESSAGE(STATUS "Building with SSE${FPMATH_SET} codegen")
1467     MESSAGE(STATUS "")
1468 ENDIF()
1470 IF(WIN32)
1471     IF(NOT HAVE_DSOUND)
1472         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1473         MESSAGE(STATUS "         This is probably NOT what you want!")
1474         MESSAGE(STATUS "")
1475     ENDIF()
1476 ENDIF()
1478 if(ALSOFT_EMBED_HRTF_DATA)
1479     message(STATUS "Embedding HRTF datasets")
1480     message(STATUS "")
1481 endif()
1483 # Install alsoft.conf configuration file
1484 IF(ALSOFT_CONFIG)
1485     INSTALL(FILES alsoftrc.sample
1486             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1487     )
1488     MESSAGE(STATUS "Installing sample configuration")
1489     MESSAGE(STATUS "")
1490 ENDIF()
1492 # Install HRTF definitions
1493 IF(ALSOFT_HRTF_DEFS)
1494     INSTALL(FILES hrtf/default-44100.mhr
1495                   hrtf/default-48000.mhr
1496             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1497     )
1498     MESSAGE(STATUS "Installing HRTF definitions")
1499     MESSAGE(STATUS "")
1500 ENDIF()
1502 # Install AmbDec presets
1503 IF(ALSOFT_AMBDEC_PRESETS)
1504     INSTALL(FILES presets/3D7.1.ambdec
1505                   presets/hexagon.ambdec
1506                   presets/itu5.1.ambdec
1507                   presets/itu5.1-nocenter.ambdec
1508                   presets/rectangle.ambdec
1509                   presets/square.ambdec
1510                   presets/presets.txt
1511             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1512     )
1513     MESSAGE(STATUS "Installing AmbDec presets")
1514     MESSAGE(STATUS "")
1515 ENDIF()
1517 IF(ALSOFT_UTILS)
1518     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1519     TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS})
1520     TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL)
1522     SET(MAKEHRTF_SRCS  utils/makehrtf.c)
1523     IF(NOT HAVE_GETOPT)
1524         SET(MAKEHRTF_SRCS  ${MAKEHRTF_SRCS} utils/getopt.c utils/getopt.h)
1525     ENDIF()
1526     ADD_EXECUTABLE(makehrtf ${MAKEHRTF_SRCS})
1527     TARGET_COMPILE_DEFINITIONS(makehrtf PRIVATE ${CPP_DEFS})
1528     TARGET_COMPILE_OPTIONS(makehrtf PRIVATE ${C_FLAGS})
1529     IF(HAVE_LIBM)
1530         TARGET_LINK_LIBRARIES(makehrtf PRIVATE ${LINKER_FLAGS} m)
1531     ENDIF()
1533     IF(ALSOFT_INSTALL)
1534         INSTALL(TARGETS openal-info makehrtf
1535                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1536                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1537                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1538         )
1539     ENDIF()
1541     MESSAGE(STATUS "Building utility programs")
1542     IF(TARGET alsoft-config)
1543         MESSAGE(STATUS "Building configuration program")
1544     ENDIF()
1545     MESSAGE(STATUS "")
1546 ENDIF()
1548 IF(ALSOFT_TESTS)
1549     SET(TEST_COMMON_OBJS  examples/common/alhelpers.c)
1551     ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS})
1552     TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS})
1553     TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS})
1554     TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB})
1556     IF(ALSOFT_INSTALL)
1557         INSTALL(TARGETS altonegen
1558                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1559                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1560                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1561         )
1562     ENDIF()
1564     MESSAGE(STATUS "Building test programs")
1565     MESSAGE(STATUS "")
1566 ENDIF()
1568 IF(ALSOFT_EXAMPLES)
1569     # Add a static library with common functions used by multiple targets
1570     ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c)
1571     TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS})
1572     TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS})
1574     ADD_EXECUTABLE(alrecord examples/alrecord.c)
1575     TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS})
1576     TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS})
1577     TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common common OpenAL)
1579     IF(ALSOFT_INSTALL)
1580         INSTALL(TARGETS alrecord
1581                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1582                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1583                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1584         )
1585     ENDIF()
1587     MESSAGE(STATUS "Building example programs")
1589     IF(SDL2_FOUND)
1590         IF(SDL_SOUND_FOUND)
1591             ADD_EXECUTABLE(alplay examples/alplay.c)
1592             TARGET_COMPILE_DEFINITIONS(alplay PRIVATE ${CPP_DEFS})
1593             TARGET_INCLUDE_DIRECTORIES(alplay
1594                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1595             TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS})
1596             TARGET_LINK_LIBRARIES(alplay
1597                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1598                         OpenAL)
1600             ADD_EXECUTABLE(alstream examples/alstream.c)
1601             TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS})
1602             TARGET_INCLUDE_DIRECTORIES(alstream
1603                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1604             TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS})
1605             TARGET_LINK_LIBRARIES(alstream
1606                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1607                         OpenAL)
1609             ADD_EXECUTABLE(alreverb examples/alreverb.c)
1610             TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS})
1611             TARGET_INCLUDE_DIRECTORIES(alreverb
1612                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1613             TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS})
1614             TARGET_LINK_LIBRARIES(alreverb
1615                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1616                         OpenAL)
1618             ADD_EXECUTABLE(almultireverb examples/almultireverb.c)
1619             TARGET_COMPILE_DEFINITIONS(almultireverb PRIVATE ${CPP_DEFS})
1620             TARGET_INCLUDE_DIRECTORIES(almultireverb
1621                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1622             TARGET_COMPILE_OPTIONS(almultireverb PRIVATE ${C_FLAGS})
1623             TARGET_LINK_LIBRARIES(almultireverb
1624                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1625                         OpenAL ${MATH_LIB})
1627             ADD_EXECUTABLE(allatency examples/allatency.c)
1628             TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS})
1629             TARGET_INCLUDE_DIRECTORIES(allatency
1630                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1631             TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS})
1632             TARGET_LINK_LIBRARIES(allatency
1633                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1634                         OpenAL)
1636             ADD_EXECUTABLE(alloopback examples/alloopback.c)
1637             TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS})
1638             TARGET_INCLUDE_DIRECTORIES(alloopback
1639                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1640             TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS})
1641             TARGET_LINK_LIBRARIES(alloopback
1642                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1643                         OpenAL ${MATH_LIB})
1645             ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1646             TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS})
1647             TARGET_INCLUDE_DIRECTORIES(alhrtf
1648                 PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1649             TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS})
1650             TARGET_LINK_LIBRARIES(alhrtf
1651                 PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common
1652                         OpenAL ${MATH_LIB})
1654             IF(ALSOFT_INSTALL)
1655                 INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf
1656                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1657                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1658                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1659                 )
1660             ENDIF()
1662             MESSAGE(STATUS "Building SDL_sound example programs")
1663         ENDIF()
1665         SET(FFVER_OK FALSE)
1666         IF(FFMPEG_FOUND)
1667             SET(FFVER_OK TRUE)
1668             IF(AVFORMAT_VERSION VERSION_LESS "57.56.101")
1669                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 57.56.101)")
1670                 SET(FFVER_OK FALSE)
1671             ENDIF()
1672             IF(AVCODEC_VERSION VERSION_LESS "57.64.101")
1673                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 57.64.101)")
1674                 SET(FFVER_OK FALSE)
1675             ENDIF()
1676             IF(AVUTIL_VERSION VERSION_LESS "55.34.101")
1677                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 55.34.101)")
1678                 SET(FFVER_OK FALSE)
1679             ENDIF()
1680             IF(SWSCALE_VERSION VERSION_LESS "4.2.100")
1681                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 4.2.100)")
1682                 SET(FFVER_OK FALSE)
1683             ENDIF()
1684             IF(SWRESAMPLE_VERSION VERSION_LESS "2.3.100")
1685                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 2.3.100)")
1686                 SET(FFVER_OK FALSE)
1687             ENDIF()
1688         ENDIF()
1689         IF(FFVER_OK)
1690             ADD_EXECUTABLE(alffplay examples/alffplay.cpp)
1691             TARGET_COMPILE_DEFINITIONS(alffplay PRIVATE ${CPP_DEFS})
1692             TARGET_INCLUDE_DIRECTORIES(alffplay
1693                 PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS})
1694             TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS})
1695             TARGET_LINK_LIBRARIES(alffplay
1696                 PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common common
1697                         OpenAL)
1699             IF(ALSOFT_INSTALL)
1700                 INSTALL(TARGETS alffplay
1701                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1702                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1703                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1704                 )
1705             ENDIF()
1706             MESSAGE(STATUS "Building SDL+FFmpeg example programs")
1707         ENDIF()
1708         MESSAGE(STATUS "")
1709     ENDIF()
1710 ENDIF()