Workaround some systems having an ECHO macro
[openal-soft.git] / CMakeLists.txt
blobcf6d7ca6fb21faabe2caa4ca3c1cc51aab3d024d
1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
5 PROJECT(OpenAL)
7 IF(COMMAND CMAKE_POLICY)
8     CMAKE_POLICY(SET CMP0003 NEW)
9     CMAKE_POLICY(SET CMP0005 NEW)
10     IF(POLICY CMP0042)
11         CMAKE_POLICY(SET CMP0042 NEW)
12     ENDIF(POLICY CMP0042)
13 ENDIF(COMMAND CMAKE_POLICY)
15 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
17 INCLUDE(CheckFunctionExists)
18 INCLUDE(CheckLibraryExists)
19 INCLUDE(CheckSharedFunctionExists)
20 INCLUDE(CheckIncludeFile)
21 INCLUDE(CheckIncludeFiles)
22 INCLUDE(CheckSymbolExists)
23 INCLUDE(CheckCCompilerFlag)
24 INCLUDE(CheckCSourceCompiles)
25 INCLUDE(CheckTypeSize)
26 include(CheckStructHasMember)
27 include(CheckFileOffsetBits)
28 include(GNUInstallDirs)
31 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
34 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
36 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
38 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
39 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
41 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
42 OPTION(ALSOFT_TESTS     "Build and install test programs"     ON)
44 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
45 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
46 OPTION(ALSOFT_AMBDEC_PRESETS "Install AmbDec preset files" ON)
47 OPTION(ALSOFT_INSTALL "Install headers and libraries" ON)
49 if(DEFINED SHARE_INSTALL_DIR)
50     message(WARNING "SHARE_INSTALL_DIR is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
51     set(CMAKE_INSTALL_DATADIR "${SHARE_INSTALL_DIR}")
52 endif()
54 if(DEFINED LIB_SUFFIX)
55     message(WARNING "LIB_SUFFIX is deprecated.  Use the variables provided by the GNUInstallDirs module instead")
56 endif()
59 IF(NOT WIN32)
60     SET(LIBNAME openal)
61 ELSE()
62     SET(LIBNAME OpenAL32)
63     ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
65     # This option is mainly for static linking OpenAL Soft into another project
66     # that already defines the IDs. It is up to that project to ensure all
67     # required IDs are defined.
68     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
70     IF(MINGW)
71         OPTION(ALSOFT_BUILD_IMPORT_LIB "Build an import .lib using dlltool (requires sed)" ON)
72         IF(NOT DLLTOOL)
73             IF(HOST)
74                 SET(DLLTOOL "${HOST}-dlltool")
75             ELSE()
76                 SET(DLLTOOL "dlltool")
77             ENDIF()
78         ENDIF()
79     ENDIF()
80 ENDIF()
83 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
84 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
85     ADD_DEFINITIONS("-I/usr/include")
86     SET(EXTRA_LIBS ${EXTRA_LIBS} -L/usr/lib)
87 ENDIF()
89 IF(NOT LIBTYPE)
90     SET(LIBTYPE SHARED)
91 ENDIF()
93 SET(LIB_MAJOR_VERSION "1")
94 SET(LIB_MINOR_VERSION "17")
95 SET(LIB_REVISION "2")
96 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
98 SET(EXPORT_DECL "")
99 SET(ALIGN_DECL "")
102 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
103 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
106 CHECK_C_COMPILER_FLAG(-std=c11 HAVE_STD_C11)
107 IF(HAVE_STD_C11)
108     SET(CMAKE_C_FLAGS "-std=c11 ${CMAKE_C_FLAGS}")
109 ELSE()
110     CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
111     IF(HAVE_STD_C99)
112         SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
113     ENDIF()
114 ENDIF()
116 if(NOT WIN32)
117     # Check if _POSIX_C_SOURCE and _XOPEN_SOURCE needs to be set for POSIX functions
118     CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_DEFAULT)
119     IF(NOT HAVE_POSIX_MEMALIGN_DEFAULT)
120         SET(OLD_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
121         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500")
122         CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN_POSIX)
123         IF(NOT HAVE_POSIX_MEMALIGN_POSIX)
124             SET(CMAKE_REQUIRED_FLAGS ${OLD_REQUIRED_FLAGS})
125         ELSE()
126             ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=500)
127         ENDIF()
128     ENDIF()
129     UNSET(OLD_REQUIRED_FLAGS)
130 ENDIF()
132 # Set defines for large file support
133 CHECK_FILE_OFFSET_BITS()
134 IF(_FILE_OFFSET_BITS)
135     ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
136     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS}")
137 ENDIF()
138 ADD_DEFINITIONS(-D_LARGEFILE_SOURCE -D_LARGE_FILES)
139 SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_LARGEFILE_SOURCE -D_LARGE_FILES")
141 # MSVC may need workarounds for C99 restrict and inline
142 IF(MSVC)
143     # TODO: Once we truly require C99, these restrict and inline checks should go
144     # away.
145     CHECK_C_SOURCE_COMPILES("int *restrict foo;
146                              int main() {return 0;}" HAVE_RESTRICT)
147     IF(NOT HAVE_RESTRICT)
148         ADD_DEFINITIONS("-Drestrict=")
149         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
150     ENDIF()
152     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
153                              int main() {return 0;}" HAVE_INLINE)
154     IF(NOT HAVE_INLINE)
155         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
156                                  int main() {return 0;}" HAVE___INLINE)
157         IF(NOT HAVE___INLINE)
158             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
159         ENDIF()
161         ADD_DEFINITIONS(-Dinline=__inline)
162         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
163     ENDIF()
164 ENDIF()
166 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
167 IF(CMAKE_COMPILER_IS_GNUCC)
168     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
169     # Force no inlining for the next test.
170     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
172     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
173                              int main() {return foo();}" INLINE_IS_C99)
174     IF(NOT INLINE_IS_C99)
175         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
176                              Please update your compiler for better C99 compliance.")
177     ENDIF()
179     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
180 ENDIF()
182 # Check if we have a proper timespec declaration
183 CHECK_STRUCT_HAS_MEMBER("struct timespec" tv_sec time.h HAVE_STRUCT_TIMESPEC)
184 IF(HAVE_STRUCT_TIMESPEC)
185     # Define it here so we don't have to include config.h for it
186     ADD_DEFINITIONS("-DHAVE_STRUCT_TIMESPEC")
187 ENDIF()
189 # Some systems may need libatomic for C11 atomic functions to work
190 SET(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
191 SET(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES} atomic)
192 CHECK_C_SOURCE_COMPILES("#include <stdatomic.h>
193 int _Atomic foo = ATOMIC_VAR_INIT(0);
194 int main()
196     return atomic_fetch_add(&foo, 2);
198 HAVE_LIBATOMIC)
199 IF(NOT HAVE_LIBATOMIC)
200     SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}")
201 ELSE()
202     SET(EXTRA_LIBS atomic ${EXTRA_LIBS})
203 ENDIF()
204 UNSET(OLD_REQUIRED_LIBRARIES)
206 # Check if we have C99 variable length arrays
207 CHECK_C_SOURCE_COMPILES(
208 "int main(int argc, char *argv[])
210      volatile int tmp[argc];
211      tmp[0] = argv[0][0];
212      return tmp[0];
213  }"
214 HAVE_C99_VLA)
216 # Check if we have C99 bool
217 CHECK_C_SOURCE_COMPILES(
218 "int main(int argc, char *argv[])
220      volatile _Bool ret;
221      ret = (argc > 1) ? 1 : 0;
222      return ret ? -1 : 0;
223  }"
224 HAVE_C99_BOOL)
226 # Check if we have C11 static_assert
227 CHECK_C_SOURCE_COMPILES(
228 "int main()
230      _Static_assert(sizeof(int) == sizeof(int), \"What\");
231      return 0;
232  }"
233 HAVE_C11_STATIC_ASSERT)
235 # Check if we have C11 alignas
236 CHECK_C_SOURCE_COMPILES(
237 "_Alignas(16) int foo;
238  int main()
240      return 0;
241  }"
242 HAVE_C11_ALIGNAS)
244 # Check if we have C11 _Atomic
245 CHECK_C_SOURCE_COMPILES(
246 "#include <stdatomic.h>
247  const int _Atomic foo = ATOMIC_VAR_INIT(~0);
248  int _Atomic bar = ATOMIC_VAR_INIT(0);
249  int main()
251      atomic_fetch_add(&bar, 2);
252      return atomic_load(&foo);
253  }"
254 HAVE_C11_ATOMIC)
256 # Add definitions, compiler switches, etc.
257 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
258 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
259     INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
260     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
261         ADD_DEFINITIONS("-DAL_NO_UID_DEFS")
262     ENDIF()
263 ENDIF()
265 IF(NOT CMAKE_BUILD_TYPE)
266     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
267         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
268         FORCE)
269 ENDIF()
270 IF(NOT CMAKE_DEBUG_POSTFIX)
271     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
272         "Library postfix for debug builds. Normally left blank."
273         FORCE)
274 ENDIF()
276 SET(EXTRA_CFLAGS "")
277 IF(MSVC)
278     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
279     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
280     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} /wd4098")
282     IF(NOT DXSDK_DIR)
283         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
284     ELSE()
285         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
286     ENDIF()
287     IF(DXSDK_DIR)
288         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
289     ENDIF()
291     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
292     IF(FORCE_STATIC_VCRT)
293         FOREACH(flag_var
294                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
295                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
296             IF(${flag_var} MATCHES "/MD")
297                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
298             ENDIF()
299         ENDFOREACH(flag_var)
300     ENDIF()
301 ELSE()
302     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Winline -Wall")
303     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
304     IF(HAVE_W_EXTRA)
305         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wextra")
306     ENDIF()
308     IF(ALSOFT_WERROR)
309         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
310     ENDIF()
312     # Force enable -fPIC for CMake versions before 2.8.9 (later versions have
313     # the POSITION_INDEPENDENT_CODE target property). The static common library
314     # will be linked into the dynamic openal library, which requires all its
315     # code to be position-independent.
316     IF(CMAKE_VERSION VERSION_LESS "2.8.9" AND NOT WIN32)
317         CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH)
318         IF(HAVE_FPIC_SWITCH)
319             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIC")
320         ENDIF()
321     ENDIF()
323     # We want RelWithDebInfo to actually include debug stuff (define _DEBUG
324     # instead of NDEBUG)
325     FOREACH(flag_var  CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO)
326         IF(${flag_var} MATCHES "-DNDEBUG")
327             STRING(REGEX REPLACE "-DNDEBUG" "-D_DEBUG" ${flag_var} "${${flag_var}}")
328         ENDIF()
329     ENDFOREACH()
331     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
332                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
334     option(ALSOFT_STATIC_LIBGCC "Force -static-libgcc for static GCC runtimes" OFF)
335     if(ALSOFT_STATIC_LIBGCC)
336         set(OLD_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
337         set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -static-libgcc)
338         check_c_source_compiles(
339 "#include <stdlib.h>
340 int main()
342     return 0;
344             HAVE_STATIC_LIBGCC_SWITCH
345         )
346         if(HAVE_STATIC_LIBGCC_SWITCH)
347             set(EXTRA_LIBS ${EXTRA_LIBS} -static-libgcc)
348         endif()
349         set(CMAKE_REQUIRED_LIBRARIES ${OLD_REQUIRED_LIBRARIES})
350         unset(OLD_REQUIRED_LIBRARIES)
351     endif()
352 ENDIF()
354 # Set visibility/export options if available
355 SET(HIDDEN_DECL "")
356 IF(WIN32)
357     SET(EXPORT_DECL "__declspec(dllexport)")
358     IF(NOT MINGW)
359         SET(ALIGN_DECL "__declspec(align(x))")
360     ELSE()
361         SET(ALIGN_DECL "__declspec(aligned(x))")
362     ENDIF()
363 ELSE()
364     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
365     # Yes GCC, really don't accept visibility modes you don't support
366     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
368     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
369                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
370     IF(HAVE_GCC_PROTECTED_VISIBILITY)
371         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
372     ELSE()
373         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
374                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
375         IF(HAVE_GCC_DEFAULT_VISIBILITY)
376             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
377         ENDIF()
378     ENDIF()
380     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
381         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
382         IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
383             SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
384             SET(HIDDEN_DECL "__attribute__((visibility(\"hidden\")))")
385         ENDIF()
386     ENDIF()
388     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
389                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
390     IF(HAVE_ATTRIBUTE_ALIGNED)
391         SET(ALIGN_DECL "__attribute__((aligned(x)))")
392     ENDIF()
394     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
395 ENDIF()
397 SET(SSE_SWITCH "")
398 SET(SSE2_SWITCH "")
399 SET(SSE3_SWITCH "")
400 SET(SSE4_1_SWITCH "")
401 SET(FPU_NEON_SWITCH "")
402 IF(NOT MSVC)
403     CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
404     IF(HAVE_MSSE_SWITCH)
405         SET(SSE_SWITCH "-msse")
406     ENDIF()
407     CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
408     IF(HAVE_MSSE2_SWITCH)
409         SET(SSE2_SWITCH "-msse2")
410     ENDIF()
411     CHECK_C_COMPILER_FLAG(-msse3 HAVE_MSSE3_SWITCH)
412     IF(HAVE_MSSE3_SWITCH)
413         SET(SSE3_SWITCH "-msse3")
414     ENDIF()
415     CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
416     IF(HAVE_MSSE4_1_SWITCH)
417         SET(SSE4_1_SWITCH "-msse4.1")
418     ENDIF()
419     CHECK_C_COMPILER_FLAG(-mfpu=neon HAVE_MFPU_NEON_SWITCH)
420     IF(HAVE_MFPU_NEON_SWITCH)
421         SET(FPU_NEON_SWITCH "-mfpu=neon")
422     ENDIF()
423 ENDIF()
425 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
426                          int main() {return 0;}" HAVE_GCC_FORMAT)
428 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
429 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
430 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
431 CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
432 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
433 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
434 CHECK_INCLUDE_FILE(intrin.h HAVE_INTRIN_H)
435 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
436 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
437 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
438 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
439 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
440 IF(NOT HAVE_GUIDDEF_H)
441     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
442 ENDIF()
444 # Some systems need libm for some of the following math functions to work
445 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
446 IF(HAVE_LIBM)
447     SET(EXTRA_LIBS m ${EXTRA_LIBS})
448     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
449 ENDIF()
451 # Check for the dlopen API (for dynamicly loading backend libs)
452 IF(ALSOFT_DLOPEN)
453     CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
454     IF(HAVE_LIBDL)
455         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
456         SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
457     ENDIF()
459     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
460 ENDIF()
462 # Check for a cpuid intrinsic
463 IF(HAVE_CPUID_H)
464     CHECK_C_SOURCE_COMPILES("#include <cpuid.h>
465         int main()
466         {
467             unsigned int eax, ebx, ecx, edx;
468             return __get_cpuid(0, &eax, &ebx, &ecx, &edx);
469         }" HAVE_GCC_GET_CPUID)
470 ENDIF()
471 IF(HAVE_INTRIN_H)
472     CHECK_C_SOURCE_COMPILES("#include <intrin.h>
473         int main()
474         {
475             int regs[4];
476             __cpuid(regs, 0);
477             return regs[0];
478         }" HAVE_CPUID_INTRINSIC)
479 ENDIF()
481 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
482 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
483 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
484 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
485 CHECK_SYMBOL_EXISTS(modff  math.h HAVE_MODFF)
486 IF(NOT HAVE_C99_VLA)
487     CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
488     IF(NOT HAVE_ALLOCA)
489         MESSAGE(FATAL_ERROR "No alloca function found, please report!")
490     ENDIF()
491 ENDIF()
493 IF(HAVE_FLOAT_H)
494     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
495     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
496 ENDIF()
498 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
499 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
500 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
501 IF(NOT HAVE_STRCASECMP)
502     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
503     IF(NOT HAVE__STRICMP)
504         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
505     ENDIF()
507     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
508 ENDIF()
510 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
511 IF(NOT HAVE_STRNCASECMP)
512     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
513     IF(NOT HAVE__STRNICMP)
514         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
515     ENDIF()
517     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
518 ENDIF()
520 CHECK_SYMBOL_EXISTS(strnlen string.h HAVE_STRNLEN)
521 CHECK_SYMBOL_EXISTS(snprintf stdio.h HAVE_SNPRINTF)
522 IF(NOT HAVE_SNPRINTF)
523     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
524     IF(NOT HAVE__SNPRINTF)
525         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
526     ENDIF()
528     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
529 ENDIF()
531 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
532 IF(NOT HAVE_ISFINITE)
533     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
534     IF(NOT HAVE_FINITE)
535         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
536         IF(NOT HAVE__FINITE)
537             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
538         ENDIF()
539         ADD_DEFINITIONS(-Disfinite=_finite)
540     ELSE()
541         ADD_DEFINITIONS(-Disfinite=finite)
542     ENDIF()
543 ENDIF()
545 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
546 IF(NOT HAVE_ISNAN)
547     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
548     IF(NOT HAVE__ISNAN)
549         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
550     ENDIF()
552     ADD_DEFINITIONS(-Disnan=_isnan)
553 ENDIF()
556 # Check if we have Windows headers
557 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
558 IF(NOT HAVE_WINDOWS_H)
559     CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
560     IF(NOT HAVE_GETTIMEOFDAY)
561         MESSAGE(FATAL_ERROR "No timing function found!")
562     ENDIF()
564     CHECK_SYMBOL_EXISTS(nanosleep time.h HAVE_NANOSLEEP)
565     IF(NOT HAVE_NANOSLEEP)
566         MESSAGE(FATAL_ERROR "No sleep function found!")
567     ENDIF()
569     # We need pthreads outside of Windows
570     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
571     IF(NOT HAVE_PTHREAD_H)
572         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
573     ENDIF()
574     # Some systems need pthread_np.h to get recursive mutexes
575     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
577     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
578     IF(HAVE_PTHREAD)
579         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pthread")
580         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
581         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
582     ENDIF()
584     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
585     IF(HAVE_LIBPTHREAD)
586         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
587     ENDIF()
589     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
591     IF(HAVE_PTHREAD_NP_H)
592         CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SETNAME_NP)
593         IF(NOT HAVE_PTHREAD_SETNAME_NP)
594             CHECK_SYMBOL_EXISTS(pthread_set_name_np "pthread.h;pthread_np.h" HAVE_PTHREAD_SET_NAME_NP)
595         ELSE()
596             CHECK_C_SOURCE_COMPILES("
597 #include <pthread.h>
598 #include <pthread_np.h>
599 int main()
601     pthread_setname_np(\"testname\");
602     return 0;
604                 PTHREAD_SETNAME_NP_ONE_PARAM
605             )
606         ENDIF()
607         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
608     ELSE()
609         CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
610         IF(NOT HAVE_PTHREAD_SETNAME_NP)
611             CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
612         ELSE()
613             CHECK_C_SOURCE_COMPILES("
614 #include <pthread.h>
615 int main()
617     pthread_setname_np(\"testname\");
618     return 0;
620                 PTHREAD_SETNAME_NP_ONE_PARAM
621             )
622         ENDIF()
623         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np pthread.h HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
624     ENDIF()
626     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
628     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
629     IF(HAVE_LIBRT)
630         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
631     ENDIF()
632 ENDIF()
634 # Check for a 64-bit type
635 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
636 IF(NOT HAVE_STDINT_H)
637     IF(HAVE_WINDOWS_H)
638         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
639                                  #include <windows.h>
640                                  __int64 foo;
641                                  int main() {return 0;}" HAVE___INT64)
642     ENDIF()
643     IF(NOT HAVE___INT64)
644         IF(NOT SIZEOF_LONG MATCHES "8")
645             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
646                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
647             ENDIF()
648         ENDIF()
649     ENDIF()
650 ENDIF()
653 SET(COMMON_OBJS  common/almalloc.c
654                  common/atomic.c
655                  common/rwlock.c
656                  common/threads.c
657                  common/uintmap.c
659 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
660                  OpenAL32/alBuffer.c
661                  OpenAL32/alEffect.c
662                  OpenAL32/alError.c
663                  OpenAL32/alExtension.c
664                  OpenAL32/alFilter.c
665                  OpenAL32/alListener.c
666                  OpenAL32/alSource.c
667                  OpenAL32/alState.c
668                  OpenAL32/alThunk.c
669                  OpenAL32/sample_cvt.c
671 SET(ALC_OBJS  Alc/ALc.c
672               Alc/ALu.c
673               Alc/alcConfig.c
674               Alc/alcRing.c
675               Alc/bs2b.c
676               Alc/effects/chorus.c
677               Alc/effects/compressor.c
678               Alc/effects/dedicated.c
679               Alc/effects/distortion.c
680               Alc/effects/echo.c
681               Alc/effects/equalizer.c
682               Alc/effects/flanger.c
683               Alc/effects/modulator.c
684               Alc/effects/null.c
685               Alc/effects/reverb.c
686               Alc/helpers.c
687               Alc/bsinc.c
688               Alc/hrtf.c
689               Alc/uhjfilter.c
690               Alc/ambdec.c
691               Alc/bformatdec.c
692               Alc/panning.c
693               Alc/mixer.c
694               Alc/mixer_c.c
698 SET(CPU_EXTS "Default")
699 SET(HAVE_SSE        0)
700 SET(HAVE_SSE2       0)
701 SET(HAVE_SSE3       0)
702 SET(HAVE_SSE4_1     0)
703 SET(HAVE_NEON       0)
705 SET(HAVE_ALSA       0)
706 SET(HAVE_OSS        0)
707 SET(HAVE_SOLARIS    0)
708 SET(HAVE_SNDIO      0)
709 SET(HAVE_QSA        0)
710 SET(HAVE_DSOUND     0)
711 SET(HAVE_MMDEVAPI   0)
712 SET(HAVE_WINMM      0)
713 SET(HAVE_PORTAUDIO  0)
714 SET(HAVE_PULSEAUDIO 0)
715 SET(HAVE_COREAUDIO  0)
716 SET(HAVE_OPENSL     0)
717 SET(HAVE_WAVE       0)
719 # Check for SSE support
720 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
721 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
722 IF(HAVE_XMMINTRIN_H)
723     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
724     IF(ALSOFT_CPUEXT_SSE)
725         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
726             SET(HAVE_SSE 1)
727             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
728             IF(SSE_SWITCH)
729                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
730                                             COMPILE_FLAGS "${SSE_SWITCH}")
731             ENDIF()
732             SET(CPU_EXTS "${CPU_EXTS}, SSE")
733         ENDIF()
734     ENDIF()
735 ENDIF()
736 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
737     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
738 ENDIF()
740 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
741 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
742 IF(HAVE_EMMINTRIN_H)
743     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
744     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
745         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
746             SET(HAVE_SSE2 1)
747             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse2.c)
748             IF(SSE2_SWITCH)
749                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
750                                             COMPILE_FLAGS "${SSE2_SWITCH}")
751             ENDIF()
752             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
753         ENDIF()
754     ENDIF()
755 ENDIF()
756 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
757     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
758 ENDIF()
760 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE3 support" OFF)
761 CHECK_INCLUDE_FILE(pmmintrin.h HAVE_PMMINTRIN_H "${SSE3_SWITCH}")
762 IF(HAVE_EMMINTRIN_H)
763     OPTION(ALSOFT_CPUEXT_SSE3 "Enable SSE3 support" ON)
764     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE3)
765         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
766             SET(HAVE_SSE3 1)
767             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse3.c)
768             IF(SSE2_SWITCH)
769                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse3.c PROPERTIES
770                                             COMPILE_FLAGS "${SSE3_SWITCH}")
771             ENDIF()
772             SET(CPU_EXTS "${CPU_EXTS}, SSE3")
773         ENDIF()
774     ENDIF()
775 ENDIF()
776 IF(ALSOFT_REQUIRE_SSE3 AND NOT HAVE_SSE3)
777     MESSAGE(FATAL_ERROR "Failed to enable required SSE3 CPU extensions")
778 ENDIF()
780 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
781 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
782 IF(HAVE_SMMINTRIN_H)
783     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
784     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
785         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
786             SET(HAVE_SSE4_1 1)
787             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse41.c)
788             IF(SSE4_1_SWITCH)
789                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
790                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
791             ENDIF()
792             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
793         ENDIF()
794     ENDIF()
795 ENDIF()
796 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
797     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
798 ENDIF()
800 # Check for ARM Neon support
801 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
802 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
803 IF(HAVE_ARM_NEON_H)
804     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
805     IF(ALSOFT_CPUEXT_NEON)
806         SET(HAVE_NEON 1)
807         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
808         IF(FPU_NEON_SWITCH)
809             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_neon.c PROPERTIES
810                                         COMPILE_FLAGS "${FPU_NEON_SWITCH}")
811         ENDIF()
812         SET(CPU_EXTS "${CPU_EXTS}, Neon")
813     ENDIF()
814 ENDIF()
815 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
816     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
817 ENDIF()
820 IF(WIN32 OR HAVE_DLFCN_H)
821     SET(IS_LINKED "")
822     MACRO(ADD_BACKEND_LIBS _LIBS)
823     ENDMACRO()
824 ELSE()
825     SET(IS_LINKED " (linked)")
826     MACRO(ADD_BACKEND_LIBS _LIBS)
827         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
828     ENDMACRO()
829 ENDIF()
831 SET(BACKENDS "")
832 SET(ALC_OBJS  ${ALC_OBJS}
833               Alc/backends/base.c
834               # Default backends, always available
835               Alc/backends/loopback.c
836               Alc/backends/null.c
839 # Check ALSA backend
840 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
841 FIND_PACKAGE(ALSA)
842 IF(ALSA_FOUND)
843     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
844     IF(ALSOFT_BACKEND_ALSA)
845         SET(HAVE_ALSA 1)
846         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
847         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
848         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
849         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
850             INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
851         ENDIF()
852     ENDIF()
853 ENDIF()
854 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
855     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
856 ENDIF()
858 # Check OSS backend
859 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
860 FIND_PACKAGE(OSS)
861 IF(OSS_FOUND)
862     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
863     IF(ALSOFT_BACKEND_OSS)
864         SET(HAVE_OSS 1)
865         SET(BACKENDS  "${BACKENDS} OSS,")
866         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
867         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
868             INCLUDE_DIRECTORIES(${OSS_INCLUDE_DIRS})
869         ENDIF()
870     ENDIF()
871 ENDIF()
872 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
873     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
874 ENDIF()
876 # Check Solaris backend
877 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
878 FIND_PACKAGE(AudioIO)
879 IF(AUDIOIO_FOUND)
880     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
881     IF(ALSOFT_BACKEND_SOLARIS)
882         SET(HAVE_SOLARIS 1)
883         SET(BACKENDS  "${BACKENDS} Solaris,")
884         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
885         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
886             INCLUDE_DIRECTORIES(${AUDIOIO_INCLUDE_DIRS})
887         ENDIF()
888     ENDIF()
889 ENDIF()
890 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
891     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
892 ENDIF()
894 # Check SndIO backend
895 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
896 FIND_PACKAGE(SoundIO)
897 IF(SOUNDIO_FOUND)
898     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
899     IF(ALSOFT_BACKEND_SNDIO)
900         SET(HAVE_SNDIO 1)
901         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
902         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
903         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
904         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
905             INCLUDE_DIRECTORIES(${SOUNDIO_INCLUDE_DIRS})
906         ENDIF()
907     ENDIF()
908 ENDIF()
909 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
910     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
911 ENDIF()
913 # Check QSA backend
914 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
915 FIND_PACKAGE(QSA)
916 IF(QSA_FOUND)
917     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
918     IF(ALSOFT_BACKEND_QSA)
919         SET(HAVE_QSA 1)
920         SET(BACKENDS  "${BACKENDS} QSA (linked),")
921         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
922         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
923         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
924             INCLUDE_DIRECTORIES(${QSA_INCLUDE_DIRS})
925         ENDIF()
926     ENDIF()
927 ENDIF()
928 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
929     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
930 ENDIF()
932 # Check Windows-only backends
933 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
934 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
935 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
936 IF(HAVE_WINDOWS_H)
937     # Check MMSystem backend
938     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
939     IF(HAVE_MMSYSTEM_H)
940         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
941         IF(HAVE_LIBWINMM)
942             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
943             IF(ALSOFT_BACKEND_WINMM)
944                 SET(HAVE_WINMM 1)
945                 SET(BACKENDS  "${BACKENDS} WinMM,")
946                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
947                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
948             ENDIF()
949         ENDIF()
950     ENDIF()
952     # Check DSound backend
953     FIND_PACKAGE(DSound)
954     IF(DSOUND_FOUND)
955         OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
956         IF(ALSOFT_BACKEND_DSOUND)
957             SET(HAVE_DSOUND 1)
958             SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
959             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
960             ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
961             IF(CMAKE_VERSION VERSION_LESS "2.8.8")
962                 INCLUDE_DIRECTORIES(${DSOUND_INCLUDE_DIRS})
963             ENDIF()
964         ENDIF()
965     ENDIF()
967     # Check for MMDevApi backend
968     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
969     IF(HAVE_MMDEVICEAPI_H)
970         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
971         IF(ALSOFT_BACKEND_MMDEVAPI)
972             SET(HAVE_MMDEVAPI 1)
973             SET(BACKENDS  "${BACKENDS} MMDevApi,")
974             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
975         ENDIF()
976     ENDIF()
977 ENDIF()
978 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
979     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
980 ENDIF()
981 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
982     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
983 ENDIF()
984 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
985     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
986 ENDIF()
988 # Check PortAudio backend
989 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
990 FIND_PACKAGE(PortAudio)
991 IF(PORTAUDIO_FOUND)
992     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
993     IF(ALSOFT_BACKEND_PORTAUDIO)
994         SET(HAVE_PORTAUDIO 1)
995         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
996         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
997         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
998         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
999             INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
1000         ENDIF()
1001     ENDIF()
1002 ENDIF()
1003 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
1004     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
1005 ENDIF()
1007 # Check PulseAudio backend
1008 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
1009 FIND_PACKAGE(PulseAudio)
1010 IF(PULSEAUDIO_FOUND)
1011     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
1012     IF(ALSOFT_BACKEND_PULSEAUDIO)
1013         SET(HAVE_PULSEAUDIO 1)
1014         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
1015         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
1016         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
1017         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1018             INCLUDE_DIRECTORIES(${PULSEAUDIO_INCLUDE_DIRS})
1019         ENDIF()
1020     ENDIF()
1021 ENDIF()
1022 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
1023     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
1024 ENDIF()
1026 # Check JACK backend
1027 OPTION(ALSOFT_REQUIRE_JACK "Require JACK backend" OFF)
1028 FIND_PACKAGE(JACK)
1029 IF(JACK_FOUND)
1030     OPTION(ALSOFT_BACKEND_JACK "Enable JACK backend" ON)
1031     IF(ALSOFT_BACKEND_JACK)
1032         SET(HAVE_JACK 1)
1033         SET(BACKENDS  "${BACKENDS} JACK${IS_LINKED},")
1034         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/jack.c)
1035         ADD_BACKEND_LIBS(${JACK_LIBRARIES})
1036         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
1037             INCLUDE_DIRECTORIES(${JACK_INCLUDE_DIRS})
1038         ENDIF()
1039     ENDIF()
1040 ENDIF()
1041 IF(ALSOFT_REQUIRE_JACK AND NOT HAVE_JACK)
1042     MESSAGE(FATAL_ERROR "Failed to enabled required JACK backend")
1043 ENDIF()
1045 # Check CoreAudio backend
1046 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
1047 FIND_LIBRARY(COREAUDIO_FRAMEWORK
1048              NAMES CoreAudio
1049              PATHS /System/Library/Frameworks
1051 IF(COREAUDIO_FRAMEWORK)
1052     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
1053     IF(ALSOFT_BACKEND_COREAUDIO)
1054         SET(HAVE_COREAUDIO 1)
1055         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
1056         SET(BACKENDS  "${BACKENDS} CoreAudio,")
1057         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
1058         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
1059         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
1061         # Some versions of OSX may need the AudioToolbox framework. Add it if
1062         # it's found.
1063         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
1064                      NAMES AudioToolbox
1065                      PATHS ~/Library/Frameworks
1066                            /Library/Frameworks
1067                            /System/Library/Frameworks
1068                     )
1069         IF(AUDIOTOOLBOX_LIBRARY)
1070             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
1071         ENDIF()
1072     ENDIF()
1073 ENDIF()
1074 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
1075     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
1076 ENDIF()
1078 # Check for OpenSL (Android) backend
1079 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
1080 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
1081 IF(HAVE_SLES_OPENSLES_ANDROID_H)
1082     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
1083     IF(HAVE_LIBOPENSLES)
1084         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
1085         IF(ALSOFT_BACKEND_OPENSL)
1086             SET(HAVE_OPENSL 1)
1087             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
1088             SET(BACKENDS  "${BACKENDS} OpenSL,")
1089             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
1090         ENDIF()
1091     ENDIF()
1092 ENDIF()
1093 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
1094     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
1095 ENDIF()
1097 # Optionally enable the Wave Writer backend
1098 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
1099 IF(ALSOFT_BACKEND_WAVE)
1100     SET(HAVE_WAVE 1)
1101     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
1102     SET(BACKENDS  "${BACKENDS} WaveFile,")
1103 ENDIF()
1105 # This is always available
1106 SET(BACKENDS  "${BACKENDS} Null")
1108 option(ALSOFT_EMBED_HRTF_DATA "Embed the HRTF data files (increases library footprint)" OFF)
1109 if(ALSOFT_EMBED_HRTF_DATA)
1110     if(WIN32)
1111         set(ALC_OBJS  ${ALC_OBJS} Alc/hrtf_res.rc)
1112     else()
1113         set(FILENAMES default-44100.mhr default-48000.mhr)
1114         foreach(FILENAME ${FILENAMES})
1115             set(outfile ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${FILENAME}${CMAKE_C_OUTPUT_EXTENSION})
1116             add_custom_command(OUTPUT ${outfile}
1117                 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hrtf/${FILENAME}"
1118                 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/hrtf"
1119                 COMMAND "${CMAKE_LINKER}" -r -b binary -o "${outfile}" ${FILENAME}
1120                 COMMAND "${CMAKE_OBJCOPY}" --rename-section .data=.rodata,alloc,load,readonly,data,contents "${outfile}" "${outfile}"
1121                 COMMENT "Generating ${FILENAME}${CMAKE_C_OUTPUT_EXTENSION}"
1122                 VERBATIM
1123             )
1124             set(ALC_OBJS  ${ALC_OBJS} ${outfile})
1125         endforeach()
1126         unset(outfile)
1127         unset(FILENAMES)
1128     endif()
1129 endif()
1132 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
1133     add_subdirectory(utils/alsoft-config)
1134 ENDIF()
1135 IF(ALSOFT_EXAMPLES)
1136     FIND_PACKAGE(SDL2)
1137     IF(SDL2_FOUND)
1138         FIND_PACKAGE(SDL_sound)
1139         IF(SDL_SOUND_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1140             INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
1141         ENDIF()
1142         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
1143         IF(FFMPEG_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
1144             INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
1145         ENDIF()
1146     ENDIF()
1147 ENDIF()
1149 IF(LIBTYPE STREQUAL "STATIC")
1150     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
1151     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
1152 ENDIF()
1154 # Needed for openal.pc.in
1155 SET(prefix ${CMAKE_INSTALL_PREFIX})
1156 SET(exec_prefix "\${prefix}")
1157 SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
1158 SET(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
1159 SET(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
1160 SET(PACKAGE_VERSION "${LIB_VERSION}")
1162 # End configuration
1163 CONFIGURE_FILE(
1164     "${OpenAL_SOURCE_DIR}/config.h.in"
1165     "${OpenAL_BINARY_DIR}/config.h")
1166 CONFIGURE_FILE(
1167     "${OpenAL_SOURCE_DIR}/openal.pc.in"
1168     "${OpenAL_BINARY_DIR}/openal.pc"
1169     @ONLY)
1171 # Build a common library with reusable helpers
1172 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
1173 SET_PROPERTY(TARGET common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1174 IF(NOT LIBTYPE STREQUAL "STATIC")
1175     SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE)
1176 ENDIF()
1178 # Build main library
1179 IF(LIBTYPE STREQUAL "STATIC")
1180     ADD_LIBRARY(${LIBNAME} STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
1181 ELSE()
1182     ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
1183 ENDIF()
1184 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1185 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
1186 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
1187     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
1188 ENDIF()
1189 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
1190 IF(HAVE_ALSA)
1191     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1192 ENDIF()
1193 IF(HAVE_OSS)
1194     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1195 ENDIF()
1196 IF(HAVE_SOLARIS)
1197     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1198 ENDIF()
1199 IF(HAVE_SNDIO)
1200     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1201 ENDIF()
1202 IF(HAVE_QSA)
1203     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1204 ENDIF()
1205 IF(HAVE_DSOUND)
1206     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1207 ENDIF()
1208 IF(HAVE_PORTAUDIO)
1209     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1210 ENDIF()
1211 IF(HAVE_PULSEAUDIO)
1212     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1213 ENDIF()
1214 IF(HAVE_JACK)
1215     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${JACK_INCLUDE_DIRS})
1216 ENDIF()
1217 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
1218                                             SOVERSION ${LIB_MAJOR_VERSION})
1219 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1220     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
1222     IF(MINGW AND ALSOFT_BUILD_IMPORT_LIB)
1223         FIND_PROGRAM(SED_EXECUTABLE NAMES sed DOC "sed executable")
1224         FIND_PROGRAM(DLLTOOL_EXECUTABLE NAMES "${DLLTOOL}" DOC "dlltool executable")
1225         IF(NOT SED_EXECUTABLE OR NOT DLLTOOL_EXECUTABLE)
1226             MESSAGE(STATUS "")
1227             IF(NOT SED_EXECUTABLE)
1228                 MESSAGE(STATUS "WARNING: Cannot find sed, disabling .def/.lib generation")
1229             ENDIF()
1230             IF(NOT DLLTOOL_EXECUTABLE)
1231                 MESSAGE(STATUS "WARNING: Cannot find dlltool, disabling .def/.lib generation")
1232             ENDIF()
1233         ELSE()
1234             SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES LINK_FLAGS "-Wl,--output-def,${LIBNAME}.def")
1235             ADD_CUSTOM_COMMAND(TARGET ${LIBNAME} POST_BUILD
1236                 COMMAND "${SED_EXECUTABLE}" -i -e "s/ @[^ ]*//" ${LIBNAME}.def
1237                 COMMAND "${DLLTOOL_EXECUTABLE}" -d ${LIBNAME}.def -l ${LIBNAME}.lib -D ${LIBNAME}.dll
1238                 COMMENT "Stripping ordinals from ${LIBNAME}.def and generating ${LIBNAME}.lib..."
1239                 VERBATIM
1240             )
1241         ENDIF()
1242     ENDIF()
1243 ENDIF()
1245 TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
1247 IF(ALSOFT_INSTALL)
1248     # Add an install target here
1249     INSTALL(TARGETS ${LIBNAME}
1250             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1251             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1252             ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1253     )
1254     INSTALL(FILES include/AL/al.h
1255                   include/AL/alc.h
1256                   include/AL/alext.h
1257                   include/AL/efx.h
1258                   include/AL/efx-creative.h
1259                   include/AL/efx-presets.h
1260             DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/AL
1261     )
1262     INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1263             DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
1264 ENDIF()
1267 MESSAGE(STATUS "")
1268 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1269 MESSAGE(STATUS "    ${BACKENDS}")
1270 MESSAGE(STATUS "")
1271 MESSAGE(STATUS "Building with support for CPU extensions:")
1272 MESSAGE(STATUS "    ${CPU_EXTS}")
1273 MESSAGE(STATUS "")
1275 IF(WIN32)
1276     IF(NOT HAVE_DSOUND)
1277         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1278         MESSAGE(STATUS "         This is probably NOT what you want!")
1279         MESSAGE(STATUS "")
1280     ENDIF()
1281 ENDIF()
1283 if(ALSOFT_EMBED_HRTF_DATA)
1284     message(STATUS "Embedding HRTF datasets")
1285     message(STATUS "")
1286 endif()
1288 # Install alsoft.conf configuration file
1289 IF(ALSOFT_CONFIG)
1290     INSTALL(FILES alsoftrc.sample
1291             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal
1292     )
1293     MESSAGE(STATUS "Installing sample configuration")
1294     MESSAGE(STATUS "")
1295 ENDIF()
1297 # Install HRTF definitions
1298 IF(ALSOFT_HRTF_DEFS)
1299     INSTALL(FILES hrtf/default-44100.mhr
1300                   hrtf/default-48000.mhr
1301             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/hrtf
1302     )
1303     MESSAGE(STATUS "Installing HRTF definitions")
1304     MESSAGE(STATUS "")
1305 ENDIF()
1307 # Install AmbDec presets
1308 IF(ALSOFT_AMBDEC_PRESETS)
1309     INSTALL(FILES presets/3D7.1.ambdec
1310                   presets/hexagon.ambdec
1311                   presets/itu5.1.ambdec
1312                   presets/rectangle.ambdec
1313                   presets/square.ambdec
1314                   presets/presets.txt
1315             DESTINATION ${CMAKE_INSTALL_DATADIR}/openal/presets
1316     )
1317     MESSAGE(STATUS "Installing AmbDec presets")
1318     MESSAGE(STATUS "")
1319 ENDIF()
1321 IF(ALSOFT_UTILS)
1322     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1323     SET_PROPERTY(TARGET openal-info APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1324     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
1326     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1327     SET_PROPERTY(TARGET makehrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1328     IF(HAVE_LIBM)
1329         TARGET_LINK_LIBRARIES(makehrtf m)
1330     ENDIF()
1332     ADD_EXECUTABLE(bsincgen utils/bsincgen.c)
1333     SET_PROPERTY(TARGET bsincgen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1334     IF(HAVE_LIBM)
1335         TARGET_LINK_LIBRARIES(bsincgen m)
1336     ENDIF()
1338     IF(ALSOFT_INSTALL)
1339         INSTALL(TARGETS openal-info makehrtf bsincgen
1340                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1341                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1342                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1343         )
1344     ENDIF()
1346     MESSAGE(STATUS "Building utility programs")
1347     IF(TARGET alsoft-config)
1348         MESSAGE(STATUS "Building configuration program")
1349     ENDIF()
1350     MESSAGE(STATUS "")
1351 ENDIF()
1353 IF(ALSOFT_TESTS)
1354     ADD_LIBRARY(test-common STATIC examples/common/alhelpers.c)
1355     SET_PROPERTY(TARGET test-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1357     ADD_EXECUTABLE(altonegen examples/altonegen.c)
1358     TARGET_LINK_LIBRARIES(altonegen test-common ${LIBNAME})
1359     SET_PROPERTY(TARGET altonegen APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1361     IF(ALSOFT_INSTALL)
1362         INSTALL(TARGETS altonegen
1363                 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1364                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1365                 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1366         )
1367     ENDIF()
1369     MESSAGE(STATUS "Building test programs")
1370     MESSAGE(STATUS "")
1371 ENDIF()
1373 IF(ALSOFT_EXAMPLES)
1374     IF(SDL2_FOUND AND SDL_SOUND_FOUND)
1375         ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c
1376                                      examples/common/sdl_sound.c)
1377         SET_PROPERTY(TARGET ex-common APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1378         SET_PROPERTY(TARGET ex-common APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1379                                                                           ${SDL_SOUND_INCLUDE_DIR})
1381         ADD_EXECUTABLE(alstream examples/alstream.c)
1382         TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1383                                        common ${LIBNAME})
1384         SET_PROPERTY(TARGET alstream APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1385         SET_PROPERTY(TARGET alstream APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1386                                                                          ${SDL_SOUND_INCLUDE_DIR})
1388         ADD_EXECUTABLE(alreverb examples/alreverb.c)
1389         TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1390                                        common ${LIBNAME})
1391         SET_PROPERTY(TARGET alreverb APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1392         SET_PROPERTY(TARGET alreverb APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1393                                                                          ${SDL_SOUND_INCLUDE_DIR})
1395         ADD_EXECUTABLE(allatency examples/allatency.c)
1396         TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1397                                         common ${LIBNAME})
1398         SET_PROPERTY(TARGET allatency APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1399         SET_PROPERTY(TARGET allatency APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1400                                                                           ${SDL_SOUND_INCLUDE_DIR})
1402         ADD_EXECUTABLE(alloopback examples/alloopback.c)
1403         TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1404                                          common ${LIBNAME})
1405         SET_PROPERTY(TARGET alloopback APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1406         SET_PROPERTY(TARGET alloopback APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1407                                                                            ${SDL_SOUND_INCLUDE_DIR})
1409         ADD_EXECUTABLE(alhrtf examples/alhrtf.c)
1410         TARGET_LINK_LIBRARIES(alhrtf ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY}
1411                                      common ${LIBNAME})
1412         SET_PROPERTY(TARGET alhrtf APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1413         SET_PROPERTY(TARGET alhrtf APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1414                                                                        ${SDL_SOUND_INCLUDE_DIR})
1416         IF(ALSOFT_INSTALL)
1417             INSTALL(TARGETS alstream alreverb allatency alloopback alhrtf
1418                     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1419                     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1420                     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1421             )
1422         ENDIF()
1424         SET(FFVER_OK FALSE)
1425         IF(FFMPEG_FOUND)
1426             SET(FFVER_OK TRUE)
1427             IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
1428                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
1429                 SET(FFVER_OK FALSE)
1430             ENDIF()
1431             IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
1432                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
1433                 SET(FFVER_OK FALSE)
1434             ENDIF()
1435             IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
1436                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
1437                 SET(FFVER_OK FALSE)
1438             ENDIF()
1439             IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
1440                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
1441                 SET(FFVER_OK FALSE)
1442             ENDIF()
1443             IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
1444                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
1445                 SET(FFVER_OK FALSE)
1446             ENDIF()
1447         ENDIF()
1448         IF(FFVER_OK AND NOT MSVC)
1449             ADD_EXECUTABLE(alffplay examples/alffplay.c)
1450             TARGET_LINK_LIBRARIES(alffplay common ex-common ${SDL2_LIBRARY} ${LIBNAME} ${FFMPEG_LIBRARIES})
1451             SET_PROPERTY(TARGET alffplay APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS})
1452             SET_PROPERTY(TARGET alffplay APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1453                                                                              ${FFMPEG_INCLUDE_DIRS})
1455             IF(ALSOFT_INSTALL)
1456                 INSTALL(TARGETS alffplay
1457                         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
1458                         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1459                         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
1460                 )
1461             ENDIF()
1462             MESSAGE(STATUS "Building SDL and FFmpeg example programs")
1463         ELSE()
1464             MESSAGE(STATUS "Building SDL example programs")
1465         ENDIF()
1466         MESSAGE(STATUS "")
1467     ENDIF()
1468 ENDIF()