Keep existing presets when loading in a new soundfont
[openal-soft.git] / CMakeLists.txt
blob7b5ec71e47d4986444b27dc4ad0c5175cd8327ea
1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
5 PROJECT(OpenAL)
7 IF(COMMAND CMAKE_POLICY)
8   CMAKE_POLICY(SET CMP0003 NEW)
9   CMAKE_POLICY(SET CMP0005 NEW)
10 ENDIF(COMMAND CMAKE_POLICY)
12 SET(CMAKE_MODULE_PATH "${OpenAL_SOURCE_DIR}/cmake")
14 INCLUDE(CheckFunctionExists)
15 INCLUDE(CheckLibraryExists)
16 INCLUDE(CheckSharedFunctionExists)
17 INCLUDE(CheckIncludeFile)
18 INCLUDE(CheckIncludeFiles)
19 INCLUDE(CheckSymbolExists)
20 INCLUDE(CheckCCompilerFlag)
21 INCLUDE(CheckCSourceCompiles)
22 INCLUDE(CheckTypeSize)
25 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
28 IF(WIN32)
29     # This option is mainly for static linking OpenAL Soft into another project
30     # that already defines the IDs. It is up to that project to ensure all
31     # required IDs are defined.
32     OPTION(ALSOFT_NO_UID_DEFS "Do not define GUIDs, IIDs, CLSIDs, or PropertyKeys" OFF)
33 ELSE()
34     # These are needed on non-Windows systems for extra features
35     ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700)
36     SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE=1 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700")
37 ENDIF()
40 OPTION(ALSOFT_DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
42 OPTION(ALSOFT_WERROR  "Treat compile warnings as errors"      OFF)
44 OPTION(ALSOFT_UTILS          "Build and install utility programs"         ON)
45 OPTION(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" OFF)
47 OPTION(ALSOFT_EXAMPLES  "Build and install example programs"  ON)
49 OPTION(ALSOFT_CONFIG "Install alsoft.conf sample configuration file" ON)
50 OPTION(ALSOFT_HRTF_DEFS "Install HRTF definition files" ON)
53 IF(WIN32)
54     SET(LIBNAME OpenAL32)
55     ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0502")
56 ELSE()
57     SET(LIBNAME openal)
58 ENDIF()
60 # QNX's gcc do not uses /usr/include and /usr/lib pathes by default
61 IF ("${CMAKE_C_PLATFORM_ID}" STREQUAL "QNX")
62     ADD_DEFINITIONS("-I/usr/include")
63     SET(EXTRA_LIBS ${EXTRA_LIBS} -L/usr/lib)
64 ENDIF()
66 IF(NOT LIBTYPE)
67     SET(LIBTYPE SHARED)
68 ENDIF()
70 SET(LIB_MAJOR_VERSION "1")
71 SET(LIB_MINOR_VERSION "15")
72 SET(LIB_REVISION "1")
73 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
75 SET(EXPORT_DECL "")
76 SET(ALIGN_DECL "")
79 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
80 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
83 CHECK_C_COMPILER_FLAG(-std=c99 HAVE_STD_C99)
84 IF(HAVE_STD_C99)
85     SET(CMAKE_C_FLAGS "-std=c99 ${CMAKE_C_FLAGS}")
86 ENDIF()
88 # MSVC may need workarounds for C99 restrict and inline
89 IF(MSVC)
90     # TODO: Once we truly require C99, these restrict and inline checks should go
91     # away.
92     CHECK_C_SOURCE_COMPILES("int *restrict foo;
93                              int main() {return 0;}" HAVE_RESTRICT)
94     IF(NOT HAVE_RESTRICT)
95         ADD_DEFINITIONS("-Drestrict=")
96         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Drestrict=")
97     ENDIF()
99     CHECK_C_SOURCE_COMPILES("inline void foo(void) { }
100                              int main() {return 0;}" HAVE_INLINE)
101     IF(NOT HAVE_INLINE)
102         CHECK_C_SOURCE_COMPILES("__inline void foo(void) { }
103                                  int main() {return 0;}" HAVE___INLINE)
104         IF(NOT HAVE___INLINE)
105             MESSAGE(FATAL_ERROR "No inline keyword found, please report!")
106         ENDIF()
108         ADD_DEFINITIONS(-Dinline=__inline)
109         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Dinline=__inline")
110     ENDIF()
111 ENDIF()
113 # Make sure we have C99-style inline semantics with GCC (4.3 or newer).
114 IF(CMAKE_COMPILER_IS_GNUCC)
115     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
116     # Force no inlining for the next test.
117     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -fno-inline")
119     CHECK_C_SOURCE_COMPILES("extern inline int foo() { return 0; }
120                              int main() {return foo();}" INLINE_IS_C99)
121     IF(NOT INLINE_IS_C99)
122         MESSAGE(FATAL_ERROR "Your compiler does not seem to have C99 inline semantics!
123                              Please update your compiler for better C99 compliance.")
124     ENDIF()
126     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
127 ENDIF()
129 # Check if we have C99 variable length arrays
130 CHECK_C_SOURCE_COMPILES(
131 "int main(int argc, char *argv[])
133      volatile int tmp[argc];
134      tmp[0] = argv[0][0];
135      return tmp[0];
136  }"
137 HAVE_C99_VLA)
139 # Check if we have C99 bool
140 CHECK_C_SOURCE_COMPILES(
141 "int main(int argc, char *argv[])
143      volatile _Bool ret;
144      ret = (argc > 1) ? 1 : 0;
145      return ret ? -1 : 0;
146  }"
147 HAVE_C99_BOOL)
149 # Check if we have C11 static_assert
150 CHECK_C_SOURCE_COMPILES(
151 "int main()
153      _Static_assert(sizeof(int) == sizeof(int), \"What\");
154      return 0;
155  }"
156 HAVE_C11_STATIC_ASSERT)
158 # Check if we have C11 alignas
159 CHECK_C_SOURCE_COMPILES(
160 "_Alignas(16) int foo;
161  int main()
163      return 0;
164  }"
165 HAVE_C11_ALIGNAS)
167 # Add definitions, compiler switches, etc.
168 INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_BINARY_DIR}")
169 IF(CMAKE_VERSION VERSION_LESS "2.8.8")
170     INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
171     IF(WIN32 AND ALSOFT_NO_UID_DEFS)
172         ADD_DEFINITIONS("-DAL_NO_UID_DEFS")
173     ENDIF()
174 ENDIF()
176 IF(NOT CMAKE_BUILD_TYPE)
177     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
178         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
179         FORCE)
180 ENDIF()
181 IF(NOT CMAKE_DEBUG_POSTFIX)
182     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
183         "Library postfix for debug builds. Normally left blank."
184         FORCE)
185 ENDIF()
187 IF(MSVC)
188     # ???
189     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
190     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
191     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
192     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
193     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
194     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
195     ADD_DEFINITIONS("/wd4098")
197     IF(NOT DXSDK_DIR)
198         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
199     ELSE()
200         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
201     ENDIF()
202     IF(DXSDK_DIR)
203         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
204         SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
205         INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
206         LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
207     ENDIF()
209     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
210     IF(FORCE_STATIC_VCRT)
211         FOREACH(flag_var
212                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
213                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
214             IF(${flag_var} MATCHES "/MD")
215                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
216             ENDIF()
217         ENDFOREACH(flag_var)
218     ENDIF()
219 ELSE()
220     ADD_DEFINITIONS(-Winline -Wall)
221     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
222     IF(HAVE_W_EXTRA)
223         ADD_DEFINITIONS(-Wextra)
224     ENDIF()
226     IF(ALSOFT_WERROR)
227         ADD_DEFINITIONS(-Werror)
228     ENDIF()
230     # Force enable PIC if available. The static common library will be linked
231     # into the dynamic openal library, which requires all its code to be
232     # position-independent, and CMake doesn't automatically enable PIC for
233     # static library targets (Windows code is always position-independent).
234     CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH)
235     IF(HAVE_FPIC_SWITCH AND NOT WIN32)
236         ADD_DEFINITIONS(-fPIC)
237     ENDIF()
239     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -D_DEBUG" CACHE STRING
240         "Flags used by the compiler during Release with Debug Info builds."
241         FORCE)
242     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
243         "Flags used by the compiler during release minsize builds."
244         FORCE)
245     SET(CMAKE_C_FLAGS_RELEASE "-O2 -fomit-frame-pointer -DNDEBUG" CACHE STRING
246         "Flags used by the compiler during release builds"
247         FORCE)
248     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
249         "Flags used by the compiler during debug builds."
250         FORCE)
252     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
253                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
254 ENDIF()
256 # Set visibility/export options if available
257 IF(WIN32)
258     SET(EXPORT_DECL "__declspec(dllexport)")
259     IF(NOT MINGW)
260         SET(ALIGN_DECL "__declspec(align(x))")
261     ELSE()
262         SET(ALIGN_DECL "__declspec(aligned(x))")
263     ENDIF()
264 ELSE()
265     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
266     # Yes GCC, really don't accept visibility modes you don't support
267     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
269     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
270                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
271     IF(HAVE_GCC_PROTECTED_VISIBILITY)
272         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
273     ELSE()
274         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
275                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
276         IF(HAVE_GCC_DEFAULT_VISIBILITY)
277             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
278         ENDIF()
279     ENDIF()
281     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
282         CHECK_C_COMPILER_FLAG(-fvisibility=internal HAVE_VISIBILITY_INTERNAL_SWITCH)
283         IF(HAVE_VISIBILITY_INTERNAL_SWITCH)
284             ADD_DEFINITIONS(-fvisibility=internal)
285         ELSE()
286             CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
287             IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
288                 ADD_DEFINITIONS(-fvisibility=hidden)
289             ENDIF()
290         ENDIF()
291     ENDIF()
293     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
294                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
295     IF(HAVE_ATTRIBUTE_ALIGNED)
296         SET(ALIGN_DECL "__attribute__((aligned(x)))")
297     ENDIF()
299     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
300 ENDIF()
302 SET(SSE_SWITCH "")
303 SET(SSE2_SWITCH "")
304 SET(SSE4_1_SWITCH "")
305 IF(NOT MSVC)
306     CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
307     IF(HAVE_MSSE_SWITCH)
308         SET(SSE_SWITCH "-msse")
309     ENDIF()
310     CHECK_C_COMPILER_FLAG(-msse2 HAVE_MSSE2_SWITCH)
311     IF(HAVE_MSSE2_SWITCH)
312         SET(SSE2_SWITCH "-msse2")
313     ENDIF()
314     CHECK_C_COMPILER_FLAG(-msse4.1 HAVE_MSSE4_1_SWITCH)
315     IF(HAVE_MSSE4_1_SWITCH)
316         SET(SSE4_1_SWITCH "-msse4.1")
317     ENDIF()
318 ENDIF()
320 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
321                          int main() {return 0;}" HAVE_GCC_FORMAT)
323 CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H)
324 CHECK_INCLUDE_FILE(stdalign.h HAVE_STDALIGN_H)
325 CHECK_INCLUDE_FILE(malloc.h HAVE_MALLOC_H)
326 CHECK_INCLUDE_FILE(ftw.h HAVE_FTW_H)
327 CHECK_INCLUDE_FILE(io.h HAVE_IO_H)
328 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
329 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
330 CHECK_INCLUDE_FILE(sys/sysconf.h HAVE_SYS_SYSCONF_H)
331 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
332 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
333 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
334 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
335 IF(NOT HAVE_GUIDDEF_H)
336     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
337 ENDIF()
339 # Some systems need libm for some of the following math functions to work
340 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
341 IF(HAVE_LIBM)
342     SET(EXTRA_LIBS m ${EXTRA_LIBS})
343     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
344 ENDIF()
347 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
348 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
349 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
350 CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
351 IF(NOT HAVE_C99_VLA)
352     CHECK_SYMBOL_EXISTS(alloca malloc.h HAVE_ALLOCA)
353     IF(NOT HAVE_ALLOCA)
354         MESSAGE(FATAL_ERROR "No alloca function found, please report!")
355     ENDIF()
356 ENDIF()
358 IF(HAVE_FLOAT_H)
359     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
360     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
361 ENDIF()
362 IF(HAVE_FTW_H)
363     CHECK_SYMBOL_EXISTS(ftw ftw.h HAVE_FTW)
364 ENDIF()
365 IF(HAVE_IO_H)
366     CHECK_SYMBOL_EXISTS(_wfindfirst io.h HAVE__WFINDFIRST)
367 ENDIF()
369 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
370 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
371 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
372 IF(NOT HAVE_STRCASECMP)
373     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
374     IF(NOT HAVE__STRICMP)
375         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
376     ENDIF()
378     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
379 ENDIF()
381 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
382 IF(NOT HAVE_STRNCASECMP)
383     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
384     IF(NOT HAVE__STRNICMP)
385         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
386     ENDIF()
388     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
389 ENDIF()
391 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
392 IF(NOT HAVE_SNPRINTF)
393     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
394     IF(NOT HAVE__SNPRINTF)
395         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
396     ENDIF()
398     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
399 ENDIF()
401 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
402 IF(NOT HAVE_ISFINITE)
403     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
404     IF(NOT HAVE_FINITE)
405         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
406         IF(NOT HAVE__FINITE)
407             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
408         ENDIF()
409         ADD_DEFINITIONS(-Disfinite=_finite)
410     ELSE()
411         ADD_DEFINITIONS(-Disfinite=finite)
412     ENDIF()
413 ENDIF()
415 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
416 IF(NOT HAVE_ISNAN)
417     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
418     IF(NOT HAVE__ISNAN)
419         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
420     ENDIF()
422     ADD_DEFINITIONS(-Disnan=_isnan)
423 ENDIF()
426 # Check for the dlopen API (for dynamicly loading backend libs)
427 IF(ALSOFT_DLOPEN)
428     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
429     IF(HAVE_DLFCN_H)
430         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
431         IF(HAVE_LIBDL)
432             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
433         ENDIF()
434     ENDIF()
435 ENDIF()
437 # Check if we have Windows headers
438 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0502)
439 IF(NOT HAVE_WINDOWS_H)
440     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
441     IF(NOT HAVE_GETTIMEOFDAY)
442         MESSAGE(FATAL_ERROR "No timing function found!")
443     ENDIF()
445     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
446     IF(NOT HAVE_NANOSLEEP)
447         MESSAGE(FATAL_ERROR "No sleep function found!")
448     ENDIF()
450     # We need pthreads outside of Windows
451     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
452     IF(NOT HAVE_PTHREAD_H)
453         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
454     ENDIF()
455     # Some systems need pthread_np.h to get recursive mutexes
456     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
458     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
459     IF(HAVE_PTHREAD)
460         ADD_DEFINITIONS(-pthread)
461         SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -pthread")
462         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
463     ENDIF()
465     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
466     IF(HAVE_LIBPTHREAD)
467         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
468     ENDIF()
470     CHECK_SYMBOL_EXISTS(pthread_setschedparam pthread.h HAVE_PTHREAD_SETSCHEDPARAM)
472     CHECK_SYMBOL_EXISTS(pthread_setname_np pthread.h HAVE_PTHREAD_SETNAME_NP)
473     IF(NOT HAVE_PTHREAD_SETNAME_NP)
474         CHECK_SYMBOL_EXISTS(pthread_set_name_np pthread.h HAVE_PTHREAD_SET_NAME_NP)
475     ENDIF()
476     IF(HAVE_PTHREAD_NP_H)
477         CHECK_SYMBOL_EXISTS(pthread_mutexattr_setkind_np "pthread.h;pthread_np.h" HAVE_PTHREAD_MUTEXATTR_SETKIND_NP)
478     ENDIF()
480     CHECK_SYMBOL_EXISTS(pthread_mutex_timedlock pthread.h HAVE_PTHREAD_MUTEX_TIMEDLOCK)
482     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
483     IF(HAVE_LIBRT)
484         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
485     ENDIF()
486 ENDIF()
488 # Check for a 64-bit type
489 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
490 IF(NOT HAVE_STDINT_H)
491     IF(HAVE_WINDOWS_H)
492         CHECK_C_SOURCE_COMPILES("#define _WIN32_WINNT 0x0502
493                                  #include <windows.h>
494                                  __int64 foo;
495                                  int main() {return 0;}" HAVE___INT64)
496     ENDIF()
497     IF(NOT HAVE___INT64)
498         IF(NOT SIZEOF_LONG MATCHES "8")
499             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
500                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
501             ENDIF()
502         ENDIF()
503     ENDIF()
504 ENDIF()
507 SET(COMMON_OBJS  common/atomic.c
508                  common/rwlock.c
509                  common/threads.c
510                  common/uintmap.c
512 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
513                  OpenAL32/alBuffer.c
514                  OpenAL32/alEffect.c
515                  OpenAL32/alError.c
516                  OpenAL32/alExtension.c
517                  OpenAL32/alFilter.c
518                  OpenAL32/alFontsound.c
519                  OpenAL32/alListener.c
520                  OpenAL32/alMidi.c
521                  OpenAL32/alPreset.c
522                  OpenAL32/alSoundfont.c
523                  OpenAL32/alSource.c
524                  OpenAL32/alState.c
525                  OpenAL32/alThunk.c
526                  OpenAL32/sample_cvt.c
528 SET(ALC_OBJS  Alc/ALc.c
529               Alc/ALu.c
530               Alc/alcConfig.c
531               Alc/alcRing.c
532               Alc/bs2b.c
533               Alc/effects/autowah.c
534               Alc/effects/chorus.c
535               Alc/effects/compressor.c
536               Alc/effects/dedicated.c
537               Alc/effects/distortion.c
538               Alc/effects/echo.c
539               Alc/effects/equalizer.c
540               Alc/effects/flanger.c
541               Alc/effects/modulator.c
542               Alc/effects/null.c
543               Alc/effects/reverb.c
544               Alc/helpers.c
545               Alc/hrtf.c
546               Alc/panning.c
547               Alc/mixer.c
548               Alc/mixer_c.c
552 SET(CPU_EXTS "Default")
553 SET(HAVE_SSE 0)
554 SET(HAVE_SSE2 0)
555 SET(HAVE_SSE4_1 0)
556 SET(HAVE_NEON 0)
558 # Check for SSE support
559 OPTION(ALSOFT_REQUIRE_SSE "Require SSE support" OFF)
560 CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
561 IF(HAVE_XMMINTRIN_H)
562     OPTION(ALSOFT_CPUEXT_SSE "Enable SSE support" ON)
563     IF(ALSOFT_CPUEXT_SSE)
564         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
565             SET(HAVE_SSE 1)
566             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
567             IF(SSE_SWITCH)
568                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
569                                             COMPILE_FLAGS "${SSE_SWITCH}")
570             ENDIF()
571             SET(CPU_EXTS "${CPU_EXTS}, SSE")
572         ENDIF()
573     ENDIF()
574 ENDIF()
575 IF(ALSOFT_REQUIRE_SSE AND NOT HAVE_SSE)
576     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
577 ENDIF()
579 OPTION(ALSOFT_REQUIRE_SSE2 "Require SSE2 support" OFF)
580 CHECK_INCLUDE_FILE(emmintrin.h HAVE_EMMINTRIN_H "${SSE2_SWITCH}")
581 IF(HAVE_EMMINTRIN_H)
582     OPTION(ALSOFT_CPUEXT_SSE2 "Enable SSE2 support" ON)
583     IF(HAVE_SSE AND ALSOFT_CPUEXT_SSE2)
584         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
585             SET(HAVE_SSE2 1)
586             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse2.c)
587             IF(SSE2_SWITCH)
588                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse2.c PROPERTIES
589                                             COMPILE_FLAGS "${SSE2_SWITCH}")
590             ENDIF()
591             SET(CPU_EXTS "${CPU_EXTS}, SSE2")
592         ENDIF()
593     ENDIF()
594 ENDIF()
595 IF(ALSOFT_REQUIRE_SSE2 AND NOT HAVE_SSE2)
596     MESSAGE(FATAL_ERROR "Failed to enable required SSE2 CPU extensions")
597 ENDIF()
599 OPTION(ALSOFT_REQUIRE_SSE4_1 "Require SSE4.1 support" OFF)
600 CHECK_INCLUDE_FILE(smmintrin.h HAVE_SMMINTRIN_H "${SSE4_1_SWITCH}")
601 IF(HAVE_SMMINTRIN_H)
602     OPTION(ALSOFT_CPUEXT_SSE4_1 "Enable SSE4.1 support" ON)
603     IF(HAVE_SSE2 AND ALSOFT_CPUEXT_SSE4_1)
604         IF(ALIGN_DECL OR HAVE_C11_ALIGNAS)
605             SET(HAVE_SSE4_1 1)
606             SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse41.c)
607             IF(SSE4_1_SWITCH)
608                 SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse41.c PROPERTIES
609                                             COMPILE_FLAGS "${SSE4_1_SWITCH}")
610             ENDIF()
611             SET(CPU_EXTS "${CPU_EXTS}, SSE4.1")
612         ENDIF()
613     ENDIF()
614 ENDIF()
615 IF(ALSOFT_REQUIRE_SSE4_1 AND NOT HAVE_SSE4_1)
616     MESSAGE(FATAL_ERROR "Failed to enable required SSE4.1 CPU extensions")
617 ENDIF()
619 # Check for ARM Neon support
620 OPTION(ALSOFT_REQUIRE_NEON "Require ARM Neon support" OFF)
621 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
622 IF(HAVE_ARM_NEON_H)
623     OPTION(ALSOFT_CPUEXT_NEON "Enable ARM Neon support" ON)
624     IF(ALSOFT_CPUEXT_NEON)
625         SET(HAVE_NEON 1)
626         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
627         SET(CPU_EXTS "${CPU_EXTS}, Neon")
628     ENDIF()
629 ENDIF()
630 IF(ALSOFT_REQUIRE_NEON AND NOT HAVE_NEON)
631     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
632 ENDIF()
635 SET(ALC_OBJS  ${ALC_OBJS}
636               Alc/midi/base.c
637               Alc/midi/sf2load.c
638               Alc/midi/dummy.c
639               Alc/midi/fluidsynth.c
640               Alc/midi/soft.c
643 SET(HAVE_FLUIDSYNTH  0)
645 # Check for FluidSynth support
646 OPTION(ALSOFT_REQUIRE_FLUIDSYNTH "Require FluidSynth MIDI" OFF)
647 FIND_PACKAGE(FluidSynth)
648 IF(FLUIDSYNTH_FOUND)
649     OPTION(ALSOFT_MIDI_FLUIDSYNTH "Enable FluidSynth MIDI" ON)
650     IF(ALSOFT_MIDI_FLUIDSYNTH)
651         SET(HAVE_FLUIDSYNTH 1)
652         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
653             INCLUDE_DIRECTORIES(${FLUIDSYNTH_INCLUDE_DIR})
654         ENDIF()
655         SET(EXTRA_LIBS ${FLUIDSYNTH_LIBRARIES} ${EXTRA_LIBS})
656     ENDIF()
657 ENDIF()
658 IF(ALSOFT_REQUIRE_FLUIDSYNTH AND NOT HAVE_FLUIDSYNTH)
659     MESSAGE(FATAL_ERROR "Failed to enabled required FluidSynth support")
660 ENDIF()
663 SET(ALC_OBJS  ${ALC_OBJS}
664               Alc/backends/base.c
665               # Default backends, always available
666               Alc/backends/loopback.c
667               Alc/backends/null.c
670 SET(BACKENDS "")
671 SET(HAVE_ALSA       0)
672 SET(HAVE_OSS        0)
673 SET(HAVE_SOLARIS    0)
674 SET(HAVE_SNDIO      0)
675 SET(HAVE_QSA        0)
676 SET(HAVE_DSOUND     0)
677 SET(HAVE_MMDEVAPI   0)
678 SET(HAVE_WINMM      0)
679 SET(HAVE_PORTAUDIO  0)
680 SET(HAVE_PULSEAUDIO 0)
681 SET(HAVE_COREAUDIO  0)
682 SET(HAVE_OPENSL     0)
683 SET(HAVE_WAVE       0)
684 IF(WIN32 OR HAVE_DLFCN_H)
685     SET(IS_LINKED "")
686     MACRO(ADD_BACKEND_LIBS _LIBS)
687     ENDMACRO()
688 ELSE()
689     SET(IS_LINKED " (linked)")
690     MACRO(ADD_BACKEND_LIBS _LIBS)
691         SET(EXTRA_LIBS ${_LIBS} ${EXTRA_LIBS})
692     ENDMACRO()
693 ENDIF()
695 # Check ALSA backend
696 OPTION(ALSOFT_REQUIRE_ALSA "Require ALSA backend" OFF)
697 FIND_PACKAGE(ALSA)
698 IF(ALSA_FOUND)
699     OPTION(ALSOFT_BACKEND_ALSA "Enable ALSA backend" ON)
700     IF(ALSOFT_BACKEND_ALSA)
701         SET(HAVE_ALSA 1)
702         SET(BACKENDS  "${BACKENDS} ALSA${IS_LINKED},")
703         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
704         ADD_BACKEND_LIBS(${ALSA_LIBRARIES})
705         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
706             INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIRS})
707         ENDIF()
708     ENDIF()
709 ENDIF()
710 IF(ALSOFT_REQUIRE_ALSA AND NOT HAVE_ALSA)
711     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
712 ENDIF()
714 # Check OSS backend
715 OPTION(ALSOFT_REQUIRE_OSS "Require OSS backend" OFF)
716 FIND_PACKAGE(OSS)
717 IF(OSS_FOUND)
718     OPTION(ALSOFT_BACKEND_OSS "Enable OSS backend" ON)
719     IF(ALSOFT_BACKEND_OSS)
720         SET(HAVE_OSS 1)
721         SET(BACKENDS  "${BACKENDS} OSS,")
722         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
723         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
724             INCLUDE_DIRECTORIES(${OSS_INCLUDE_DIRS})
725         ENDIF()
726     ENDIF()
727 ENDIF()
728 IF(ALSOFT_REQUIRE_OSS AND NOT HAVE_OSS)
729     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
730 ENDIF()
732 # Check Solaris backend
733 OPTION(ALSOFT_REQUIRE_SOLARIS "Require Solaris backend" OFF)
734 FIND_PACKAGE(AudioIO)
735 IF(AUDIOIO_FOUND)
736     OPTION(ALSOFT_BACKEND_SOLARIS "Enable Solaris backend" ON)
737     IF(ALSOFT_BACKEND_SOLARIS)
738         SET(HAVE_SOLARIS 1)
739         SET(BACKENDS  "${BACKENDS} Solaris,")
740         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
741         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
742             INCLUDE_DIRECTORIES(${AUDIOIO_INCLUDE_DIRS})
743         ENDIF()
744     ENDIF()
745 ENDIF()
746 IF(ALSOFT_REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
747     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
748 ENDIF()
750 # Check SndIO backend
751 OPTION(ALSOFT_REQUIRE_SNDIO "Require SndIO backend" OFF)
752 FIND_PACKAGE(SoundIO)
753 IF(SOUNDIO_FOUND)
754     OPTION(ALSOFT_BACKEND_SNDIO "Enable SndIO backend" ON)
755     IF(ALSOFT_BACKEND_SNDIO)
756         SET(HAVE_SNDIO 1)
757         SET(BACKENDS  "${BACKENDS} SndIO (linked),")
758         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
759         SET(EXTRA_LIBS ${SOUNDIO_LIBRARIES} ${EXTRA_LIBS})
760         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
761             INCLUDE_DIRECTORIES(${SOUNDIO_INCLUDE_DIRS})
762         ENDIF()
763     ENDIF()
764 ENDIF()
765 IF(ALSOFT_REQUIRE_SNDIO AND NOT HAVE_SNDIO)
766     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
767 ENDIF()
769 # Check QSA backend
770 OPTION(ALSOFT_REQUIRE_QSA "Require QSA backend" OFF)
771 FIND_PACKAGE(QSA)
772 IF(QSA_FOUND)
773     OPTION(ALSOFT_BACKEND_QSA "Enable QSA backend" ON)
774     IF(ALSOFT_BACKEND_QSA)
775         SET(HAVE_QSA 1)
776         SET(BACKENDS  "${BACKENDS} QSA (linked),")
777         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/qsa.c)
778         SET(EXTRA_LIBS ${QSA_LIBRARIES} ${EXTRA_LIBS})
779         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
780             INCLUDE_DIRECTORIES(${QSA_INCLUDE_DIRS})
781         ENDIF()
782     ENDIF()
783 ENDIF()
784 IF(ALSOFT_REQUIRE_QSA AND NOT HAVE_QSA)
785     MESSAGE(FATAL_ERROR "Failed to enabled required QSA backend")
786 ENDIF()
788 # Check DSound backend
789 OPTION(ALSOFT_REQUIRE_DSOUND "Require DirectSound backend" OFF)
790 FIND_PACKAGE(DSound)
791 IF(DSOUND_FOUND)
792     OPTION(ALSOFT_BACKEND_DSOUND "Enable DirectSound backend" ON)
793     IF(ALSOFT_BACKEND_DSOUND)
794         SET(HAVE_DSOUND 1)
795         SET(BACKENDS  "${BACKENDS} DirectSound${IS_LINKED},")
796         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
797         ADD_BACKEND_LIBS(${DSOUND_LIBRARIES})
798         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
799             INCLUDE_DIRECTORIES(${DSOUND_INCLUDE_DIRS})
800         ENDIF()
801     ENDIF()
802 ENDIF()
803 IF(ALSOFT_REQUIRE_DSOUND AND NOT HAVE_DSOUND)
804     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
805 ENDIF()
807 # Check for MMDevApi backend
808 OPTION(ALSOFT_REQUIRE_MMDEVAPI "Require MMDevApi backend" OFF)
809 IF(HAVE_WINDOWS_H)
810     CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
811     IF(HAVE_MMDEVICEAPI_H)
812         OPTION(ALSOFT_BACKEND_MMDEVAPI "Enable MMDevApi backend" ON)
813         IF(ALSOFT_BACKEND_MMDEVAPI)
814             SET(HAVE_MMDEVAPI 1)
815             SET(BACKENDS  "${BACKENDS} MMDevApi,")
816             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
817         ENDIF()
818     ENDIF()
819 ENDIF()
820 IF(ALSOFT_REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
821     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
822 ENDIF()
824 # Check MMSystem backend
825 OPTION(ALSOFT_REQUIRE_WINMM "Require Windows Multimedia backend" OFF)
826 IF(HAVE_WINDOWS_H)
827     CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0502)
828     IF(HAVE_MMSYSTEM_H)
829         CHECK_SHARED_FUNCTION_EXISTS(waveOutOpen "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
830         IF(HAVE_LIBWINMM)
831             OPTION(ALSOFT_BACKEND_WINMM "Enable Windows Multimedia backend" ON)
832             IF(ALSOFT_BACKEND_WINMM)
833                 SET(HAVE_WINMM 1)
834                 SET(BACKENDS  "${BACKENDS} WinMM,")
835                 SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
836                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
837             ENDIF()
838         ENDIF()
839     ENDIF()
840 ENDIF()
841 IF(ALSOFT_REQUIRE_WINMM AND NOT HAVE_WINMM)
842     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
843 ENDIF()
845 # Check PortAudio backend
846 OPTION(ALSOFT_REQUIRE_PORTAUDIO "Require PortAudio backend" OFF)
847 FIND_PACKAGE(PortAudio)
848 IF(PORTAUDIO_FOUND)
849     OPTION(ALSOFT_BACKEND_PORTAUDIO "Enable PortAudio backend" ON)
850     IF(ALSOFT_BACKEND_PORTAUDIO)
851         SET(HAVE_PORTAUDIO 1)
852         SET(BACKENDS  "${BACKENDS} PortAudio${IS_LINKED},")
853         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
854         ADD_BACKEND_LIBS(${PORTAUDIO_LIBRARIES})
855         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
856             INCLUDE_DIRECTORIES(${PORTAUDIO_INCLUDE_DIRS})
857         ENDIF()
858     ENDIF()
859 ENDIF()
860 IF(ALSOFT_REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
861     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
862 ENDIF()
864 # Check PulseAudio backend
865 OPTION(ALSOFT_REQUIRE_PULSEAUDIO "Require PulseAudio backend" OFF)
866 FIND_PACKAGE(PulseAudio)
867 IF(PULSEAUDIO_FOUND)
868     OPTION(ALSOFT_BACKEND_PULSEAUDIO "Enable PulseAudio backend" ON)
869     IF(ALSOFT_BACKEND_PULSEAUDIO)
870         SET(HAVE_PULSEAUDIO 1)
871         SET(BACKENDS  "${BACKENDS} PulseAudio${IS_LINKED},")
872         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
873         ADD_BACKEND_LIBS(${PULSEAUDIO_LIBRARIES})
874         IF(CMAKE_VERSION VERSION_LESS "2.8.8")
875             INCLUDE_DIRECTORIES(${PULSEAUDIO_INCLUDE_DIRS})
876         ENDIF()
877     ENDIF()
878 ENDIF()
879 IF(ALSOFT_REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
880     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
881 ENDIF()
883 # Check CoreAudio backend
884 OPTION(ALSOFT_REQUIRE_COREAUDIO "Require CoreAudio backend" OFF)
885 FIND_LIBRARY(COREAUDIO_FRAMEWORK
886              NAMES CoreAudio
887              PATHS /System/Library/Frameworks
889 IF(COREAUDIO_FRAMEWORK)
890     OPTION(ALSOFT_BACKEND_COREAUDIO "Enable CoreAudio backend" ON)
891     IF(ALSOFT_BACKEND_COREAUDIO)
892         SET(HAVE_COREAUDIO 1)
893         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
894         SET(BACKENDS  "${BACKENDS} CoreAudio,")
895         SET(EXTRA_LIBS ${COREAUDIO_FRAMEWORK} ${EXTRA_LIBS})
896         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
897         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
899         # Some versions of OSX may need the AudioToolbox framework. Add it if
900         # it's found.
901         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
902                      NAMES AudioToolbox
903                      PATHS ~/Library/Frameworks
904                            /Library/Frameworks
905                            /System/Library/Frameworks
906                     )
907         IF(AUDIOTOOLBOX_LIBRARY)
908             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
909         ENDIF()
910     ENDIF()
911 ENDIF()
912 IF(ALSOFT_REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
913     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
914 ENDIF()
916 # Check for OpenSL (Android) backend
917 OPTION(ALSOFT_REQUIRE_OPENSL "Require OpenSL backend" OFF)
918 CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
919 IF(HAVE_SLES_OPENSLES_ANDROID_H)
920     CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
921     IF(HAVE_LIBOPENSLES)
922         OPTION(ALSOFT_BACKEND_OPENSL "Enable OpenSL backend" ON)
923         IF(ALSOFT_BACKEND_OPENSL)
924             SET(HAVE_OPENSL 1)
925             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
926             SET(BACKENDS  "${BACKENDS} OpenSL,")
927             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
928         ENDIF()
929     ENDIF()
930 ENDIF()
931 IF(ALSOFT_REQUIRE_OPENSL AND NOT HAVE_OPENSL)
932     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
933 ENDIF()
935 # Optionally enable the Wave Writer backend
936 OPTION(ALSOFT_BACKEND_WAVE "Enable Wave Writer backend" ON)
937 IF(ALSOFT_BACKEND_WAVE)
938     SET(HAVE_WAVE 1)
939     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
940     SET(BACKENDS  "${BACKENDS} WaveFile,")
941 ENDIF()
943 # This is always available
944 SET(BACKENDS  "${BACKENDS} Null")
946 IF(ALSOFT_UTILS AND NOT ALSOFT_NO_CONFIG_UTIL)
947     add_subdirectory(utils/alsoft-config)
948 ENDIF()
949 IF(ALSOFT_EXAMPLES)
950     FIND_PACKAGE(SDL2)
951     IF(SDL2_FOUND)
952         FIND_PACKAGE(SDL_sound)
953         IF(SDL_SOUND_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
954             INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
955         ENDIF()
956         FIND_PACKAGE(FFmpeg COMPONENTS AVFORMAT AVCODEC AVUTIL SWSCALE SWRESAMPLE)
957         IF(FFMPEG_FOUND AND CMAKE_VERSION VERSION_LESS "2.8.8")
958             INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIRS})
959         ENDIF()
960     ENDIF()
961 ENDIF()
963 IF(LIBTYPE STREQUAL "STATIC")
964     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
965     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
966 ENDIF()
968 # Needed for openal.pc.in
969 SET(prefix ${CMAKE_INSTALL_PREFIX})
970 SET(exec_prefix "\${prefix}")
971 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
972 SET(bindir "\${exec_prefix}/bin")
973 SET(includedir "\${prefix}/include")
974 SET(PACKAGE_VERSION "${LIB_VERSION}")
976 # End configuration
977 CONFIGURE_FILE(
978     "${OpenAL_SOURCE_DIR}/config.h.in"
979     "${OpenAL_BINARY_DIR}/config.h")
980 CONFIGURE_FILE(
981     "${OpenAL_SOURCE_DIR}/openal.pc.in"
982     "${OpenAL_BINARY_DIR}/openal.pc"
983     @ONLY)
985 # Build a common library with reusable helpers
986 ADD_LIBRARY(common STATIC ${COMMON_OBJS})
988 # Build main library
989 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
990 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
991 IF(WIN32 AND ALSOFT_NO_UID_DEFS)
992     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
993 ENDIF()
994 SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc")
995 IF(FLUIDSYNTH_FOUND)
996     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${FLUIDSYNTH_INCLUDE_DIR})
997 ENDIF()
998 IF(HAVE_ALSA)
999     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${ALSA_INCLUDE_DIRS})
1000 ENDIF()
1001 IF(HAVE_OSS)
1002     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${OSS_INCLUDE_DIRS})
1003 ENDIF()
1004 IF(HAVE_SOLARIS)
1005     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${AUDIOIO_INCLUDE_DIRS})
1006 ENDIF()
1007 IF(HAVE_SNDIO)
1008     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${SOUNDIO_INCLUDE_DIRS})
1009 ENDIF()
1010 IF(HAVE_QSA)
1011     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${QSA_INCLUDE_DIRS})
1012 ENDIF()
1013 IF(HAVE_DSOUND)
1014     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${DSOUND_INCLUDE_DIRS})
1015 ENDIF()
1016 IF(HAVE_PORTAUDIO)
1017     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
1018 ENDIF()
1019 IF(HAVE_PULSEAUDIO)
1020     SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY INCLUDE_DIRECTORIES ${PULSEAUDIO_INCLUDE_DIRS})
1021 ENDIF()
1022 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
1023                                             SOVERSION ${LIB_MAJOR_VERSION})
1024 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
1025     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
1026 ENDIF()
1028 TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
1030 # Add an install target here
1031 INSTALL(TARGETS ${LIBNAME}
1032         RUNTIME DESTINATION bin
1033         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
1034         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
1036 INSTALL(FILES include/AL/al.h
1037               include/AL/alc.h
1038               include/AL/alext.h
1039               include/AL/efx.h
1040               include/AL/efx-creative.h
1041               include/AL/efx-presets.h
1042         DESTINATION include/AL
1044 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
1045         DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
1048 MESSAGE(STATUS "")
1049 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
1050 MESSAGE(STATUS "    ${BACKENDS}")
1051 MESSAGE(STATUS "")
1052 MESSAGE(STATUS "Building with support for CPU extensions:")
1053 MESSAGE(STATUS "    ${CPU_EXTS}")
1054 MESSAGE(STATUS "")
1055 IF(HAVE_FLUIDSYNTH)
1056     MESSAGE(STATUS "FluidSynth support for ALC_SOFT_midi_interface enabled")
1057     MESSAGE(STATUS "")
1058 ENDIF()
1060 IF(WIN32)
1061     IF(NOT HAVE_DSOUND)
1062         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
1063         MESSAGE(STATUS "         This is probably NOT what you want!")
1064         MESSAGE(STATUS "")
1065     ENDIF()
1066 ENDIF()
1068 # Install alsoft.conf configuration file
1069 IF(ALSOFT_CONFIG)
1070     INSTALL(FILES alsoftrc.sample
1071             DESTINATION share/openal
1072     )
1073     MESSAGE(STATUS "Installing sample configuration")
1074     MESSAGE(STATUS "")
1075 ENDIF()
1077 # Install HRTF definitions
1078 IF(ALSOFT_HRTF_DEFS)
1079     INSTALL(FILES hrtf/default-44100.mhr
1080             DESTINATION share/openal/hrtf
1081     )
1082     MESSAGE(STATUS "Installing HRTF definitions")
1083     MESSAGE(STATUS "")
1084 ENDIF()
1086 IF(ALSOFT_UTILS)
1087     ADD_EXECUTABLE(openal-info utils/openal-info.c)
1088     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
1090     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
1091     IF(HAVE_LIBM)
1092         TARGET_LINK_LIBRARIES(makehrtf m)
1093     ENDIF()
1095     INSTALL(TARGETS openal-info makehrtf
1096             RUNTIME DESTINATION bin
1097             LIBRARY DESTINATION "lib${LIB_SUFFIX}"
1098             ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
1099     )
1101     MESSAGE(STATUS "Building utility programs")
1102     IF(TARGET alsoft-config)
1103         MESSAGE(STATUS "Building configuration program")
1104     ENDIF()
1105     MESSAGE(STATUS "")
1106 ENDIF()
1108 IF(ALSOFT_EXAMPLES)
1109     IF(SDL2_FOUND AND SDL_SOUND_FOUND)
1110         ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c
1111                                      examples/common/sdl_sound.c)
1112         SET_PROPERTY(TARGET ex-common APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1113                                                                           ${SDL_SOUND_INCLUDE_DIR})
1115         ADD_EXECUTABLE(alstream examples/alstream.c)
1116         TARGET_LINK_LIBRARIES(alstream ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
1117         SET_PROPERTY(TARGET alstream APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1118                                                                          ${SDL_SOUND_INCLUDE_DIR})
1120         ADD_EXECUTABLE(alreverb examples/alreverb.c)
1121         TARGET_LINK_LIBRARIES(alreverb ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
1122         SET_PROPERTY(TARGET alreverb APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1123                                                                          ${SDL_SOUND_INCLUDE_DIR})
1125         ADD_EXECUTABLE(allatency examples/allatency.c)
1126         TARGET_LINK_LIBRARIES(allatency ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
1127         SET_PROPERTY(TARGET allatency APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1128                                                                           ${SDL_SOUND_INCLUDE_DIR})
1130         ADD_EXECUTABLE(alloopback examples/alloopback.c)
1131         TARGET_LINK_LIBRARIES(alloopback ex-common ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ${LIBNAME})
1132         SET_PROPERTY(TARGET alloopback APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1133                                                                            ${SDL_SOUND_INCLUDE_DIR})
1135         INSTALL(TARGETS alstream alreverb allatency alloopback
1136                 RUNTIME DESTINATION bin
1137                 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
1138                 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
1139         )
1141         SET(FFVER_OK FALSE)
1142         IF(FFMPEG_FOUND)
1143             SET(FFVER_OK TRUE)
1144             IF(AVFORMAT_VERSION VERSION_LESS "55.33.100")
1145                 MESSAGE(STATUS "libavformat is too old! (${AVFORMAT_VERSION}, wanted 55.33.100)")
1146                 SET(FFVER_OK FALSE)
1147             ENDIF()
1148             IF(AVCODEC_VERSION VERSION_LESS "55.52.102")
1149                 MESSAGE(STATUS "libavcodec is too old! (${AVCODEC_VERSION}, wanted 55.52.102)")
1150                 SET(FFVER_OK FALSE)
1151             ENDIF()
1152             IF(AVUTIL_VERSION VERSION_LESS "52.66.100")
1153                 MESSAGE(STATUS "libavutil is too old! (${AVUTIL_VERSION}, wanted 52.66.100)")
1154                 SET(FFVER_OK FALSE)
1155             ENDIF()
1156             IF(SWSCALE_VERSION VERSION_LESS "2.5.102")
1157                 MESSAGE(STATUS "libswscale is too old! (${SWSCALE_VERSION}, wanted 2.5.102)")
1158                 SET(FFVER_OK FALSE)
1159             ENDIF()
1160             IF(SWRESAMPLE_VERSION VERSION_LESS "0.18.100")
1161                 MESSAGE(STATUS "libswresample is too old! (${SWRESAMPLE_VERSION}, wanted 0.18.100)")
1162                 SET(FFVER_OK FALSE)
1163             ENDIF()
1164         ENDIF()
1165         IF(FFVER_OK AND NOT MSVC)
1166             ADD_EXECUTABLE(alffplay examples/alffplay.c)
1167             TARGET_LINK_LIBRARIES(alffplay common ex-common ${SDL2_LIBRARY} ${LIBNAME} ${FFMPEG_LIBRARIES})
1168             SET_PROPERTY(TARGET alffplay APPEND PROPERTY INCLUDE_DIRECTORIES ${SDL2_INCLUDE_DIR}
1169                                                                              ${FFMPEG_INCLUDE_DIRS})
1171             INSTALL(TARGETS alffplay
1172                     RUNTIME DESTINATION bin
1173                     LIBRARY DESTINATION "lib${LIB_SUFFIX}"
1174                     ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
1175             )
1176             MESSAGE(STATUS "Building SDL and FFmpeg example programs")
1177         ELSE()
1178             MESSAGE(STATUS "Building SDL example programs")
1179         ENDIF()
1180         MESSAGE(STATUS "")
1181     ENDIF()
1182 ENDIF()