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