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