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