Use alGetEnumValue to check for supported filters and effects
[openal-soft/android.git] / CMakeLists.txt
blob3783a17690d9c712e9b6652a2a1d5f226c5c4b64
1 # CMake build file list for OpenAL
3 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
5 IF(COMMAND CMAKE_POLICY)
6   CMAKE_POLICY(SET CMP0003 NEW)
7 ENDIF(COMMAND CMAKE_POLICY)
9 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
11 INCLUDE(CheckFunctionExists)
12 INCLUDE(CheckLibraryExists)
13 INCLUDE(CheckSharedFunctionExists)
14 INCLUDE(CheckIncludeFile)
15 INCLUDE(CheckIncludeFiles)
16 INCLUDE(CheckSymbolExists)
17 INCLUDE(CheckCCompilerFlag)
18 INCLUDE(CheckCSourceCompiles)
19 INCLUDE(CheckTypeSize)
22 PROJECT(OpenAL C)
25 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
28 OPTION(ALSA    "Check for ALSA backend"                ON)
29 OPTION(OSS     "Check for OSS backend"                 ON)
30 OPTION(SOLARIS "Check for Solaris backend"             ON)
31 OPTION(SNDIO   "Check for SndIO backend"               ON)
32 OPTION(MMDEVAPI "Check for MMDevApi"                   ON)
33 OPTION(DSOUND  "Check for DirectSound backend"         ON)
34 OPTION(WINMM   "Check for Windows Multimedia backend"  ON)
35 OPTION(PORTAUDIO  "Check for PortAudio backend"        ON)
36 OPTION(PULSEAUDIO "Check for PulseAudio backend"       ON)
37 OPTION(COREAUDIO  "Check for CoreAudio backend"        ON)
38 OPTION(OPENSL     "Check for OpenSL backend"           ON)
39 OPTION(WAVE    "Enable Wave Writer backend"            ON)
41 OPTION(REQUIRE_ALSA       "Require ALSA backend"               OFF)
42 OPTION(REQUIRE_OSS        "Require OSS backend"                OFF)
43 OPTION(REQUIRE_SOLARIS    "Require Solaris backend"            OFF)
44 OPTION(REQUIRE_SNDIO      "Require SndIO backend"              OFF)
45 OPTION(REQUIRE_MMDEVAPI   "Require MMDevApi"                   OFF)
46 OPTION(REQUIRE_DSOUND     "Require DirectSound backend"        OFF)
47 OPTION(REQUIRE_WINMM      "Require Windows Multimedia backend" OFF)
48 OPTION(REQUIRE_PORTAUDIO  "Require PortAudio backend"          OFF)
49 OPTION(REQUIRE_PULSEAUDIO "Require PulseAudio backend"         OFF)
50 OPTION(REQUIRE_COREAUDIO  "Require CoreAudio backend"          OFF)
51 OPTION(REQUIRE_OPENSL     "Require OpenSL backend"             OFF)
53 OPTION(DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
55 OPTION(WERROR  "Treat compile warnings as errors"      OFF)
57 OPTION(UTILS  "Build and install utility programs"  ON)
59 OPTION(ALSOFT_CONFIG "Install alsoft.conf configuration file" OFF)
62 IF(WIN32)
63     SET(LIBNAME OpenAL32)
64     ADD_DEFINITIONS("-D_WIN32")
65 ELSE()
66     SET(LIBNAME openal)
67 ENDIF()
69 IF(NOT LIBTYPE)
70     SET(LIBTYPE SHARED)
71 ENDIF()
73 SET(LIB_MAJOR_VERSION "1")
74 SET(LIB_MINOR_VERSION "13")
75 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}")
77 SET(EXPORT_DECL "")
80 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
81 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
82 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
83 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
86 CHECK_C_SOURCE_COMPILES("int *restrict foo;
87                          int main() {return 0;}" HAVE_RESTRICT)
88 CHECK_C_SOURCE_COMPILES("int *__restrict foo;
89                          int main() {return 0;}" HAVE___RESTRICT)
92 # Add definitions, compiler switches, etc.
93 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
95 IF(NOT CMAKE_BUILD_TYPE)
96     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
97         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
98         FORCE)
99 ENDIF()
100 IF(NOT CMAKE_DEBUG_POSTFIX)
101     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
102         "Library postfix for debug builds. Normally left blank."
103         FORCE)
104 ENDIF()
106 IF(MSVC)
107     # ???
108     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
109     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
110     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
111     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
112     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
113     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
115     IF(NOT DXSDK_DIR)
116         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
117     ELSE()
118         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
119     ENDIF()
120     IF(DXSDK_DIR)
121         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
122         SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
123         INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
124         LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
125     ENDIF()
127     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
128     IF(FORCE_STATIC_VCRT)
129         FOREACH(flag_var
130                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
131                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
132             IF(${flag_var} MATCHES "/MD")
133                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
134             ENDIF()
135         ENDFOREACH(flag_var)
136     ENDIF()
137 ELSE()
138     ADD_DEFINITIONS(-Winline -Wall)
139     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
140     IF(HAVE_W_EXTRA)
141         ADD_DEFINITIONS(-Wextra)
142     ENDIF()
144     IF(WERROR)
145         ADD_DEFINITIONS(-Werror)
146     ENDIF()
148     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -D_DEBUG" CACHE STRING
149         "Flags used by the compiler during Release with Debug Info builds."
150         FORCE)
151     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
152         "Flags used by the compiler during release minsize builds."
153         FORCE)
154     SET(CMAKE_C_FLAGS_RELEASE "-O2 -fomit-frame-pointer -DNDEBUG" CACHE STRING
155         "Flags used by the compiler during release builds"
156         FORCE)
157     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
158         "Flags used by the compiler during debug builds."
159         FORCE)
161     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
162                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
163 ENDIF()
165 # Set visibility/export options if available
166 IF(WIN32)
167     SET(EXPORT_DECL "__declspec(dllexport)")
169     OPTION(WINE "Enable use of Wine headers when compiling" OFF)
170     IF(WINE)
171         FIND_PATH(WINE_INCLUDE_DIR library.h
172                   PATHS
173                   /usr/include/wine
174                   /usr/local/include/wine
175                   CMAKE_FIND_ROOT_PATH_BOTH)
176         IF(WINE_INCLUDE_DIR)
177             MESSAGE(STATUS "Found Wine header files - ${WINE_INCLUDE_DIR}" )
178             INCLUDE_DIRECTORIES("${WINE_INCLUDE_DIR}/windows")
179             SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${WINE_INCLUDE_DIR}/windows")
180         ELSE()
181             MESSAGE(STATUS "Could not find Wine header files" )
182         ENDIF()
183     ENDIF()
184 ELSE()
185     CHECK_C_COMPILER_FLAG(-fvisibility=internal HAVE_VISIBILITY_SWITCH)
186     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
187                              int main() {return 0;}" HAVE_GCC_VISIBILITY)
188     IF(HAVE_VISIBILITY_SWITCH AND HAVE_GCC_VISIBILITY)
189         ADD_DEFINITIONS(-fvisibility=internal)
190         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
191     ENDIF()
192 ENDIF()
194 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
195                          int main() {return 0;}" HAVE_GCC_FORMAT)
197 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
198 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
199 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
200 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
201 IF(NOT HAVE_GUIDDEF_H)
202     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
203 ENDIF()
204 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
206 CHECK_LIBRARY_EXISTS(m  powf   "" HAVE_POWF)
207 CHECK_LIBRARY_EXISTS(m  sqrtf  "" HAVE_SQRTF)
208 CHECK_LIBRARY_EXISTS(m  acosf  "" HAVE_ACOSF)
209 CHECK_LIBRARY_EXISTS(m  atanf  "" HAVE_ATANF)
210 CHECK_LIBRARY_EXISTS(m  fabsf  "" HAVE_FABSF)
211 IF(HAVE_FENV_H)
212     CHECK_LIBRARY_EXISTS(m  fesetround  "" HAVE_FESETROUND)
213 ENDIF()
214 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
215     SET(EXTRA_LIBS m ${EXTRA_LIBS})
216 ENDIF()
217 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
218 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
220 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
221 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
222 IF(NOT HAVE_STRCASECMP)
223     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
224     IF(NOT HAVE__STRICMP)
225         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
226     ENDIF()
228     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
229 ENDIF()
231 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
232 IF(NOT HAVE_STRNCASECMP)
233     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
234     IF(NOT HAVE__STRNICMP)
235         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
236     ENDIF()
238     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
239 ENDIF()
241 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
242 IF(NOT HAVE_SNPRINTF)
243     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
244     IF(NOT HAVE__SNPRINTF)
245         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
246     ENDIF()
248     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
249 ENDIF()
251 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
252 IF(NOT HAVE_VSNPRINTF)
253     CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
254     IF(NOT HAVE__VSNPRINTF)
255         MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
256     ENDIF()
258     ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
259 ENDIF()
261 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
262 IF(NOT HAVE_ISFINITE)
263     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
264     IF(NOT HAVE_FINITE)
265         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
266         IF(NOT HAVE__FINITE)
267             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
268         ENDIF()
269         ADD_DEFINITIONS(-Disfinite=_finite)
270     ELSE()
271         ADD_DEFINITIONS(-Disfinite=finite)
272     ENDIF()
273 ENDIF()
275 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
276 IF(NOT HAVE_ISNAN)
277     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
278     IF(NOT HAVE__ISNAN)
279         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
280     ENDIF()
282     ADD_DEFINITIONS(-Disnan=_isnan)
283 ENDIF()
286 # Check for the dlopen API (for dynamicly loading backend libs)
287 IF(DLOPEN)
288     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
289     IF(HAVE_DLFCN_H)
290         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
291         IF(HAVE_LIBDL)
292             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
293         ENDIF()
294     ENDIF()
295 ENDIF()
297 # Check if we have Windows headers
298 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
299 IF(NOT HAVE_WINDOWS_H)
300     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
301     IF(NOT HAVE_GETTIMEOFDAY)
302         MESSAGE(FATAL_ERROR "No timing function found!")
303     ENDIF()
305     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
306     IF(NOT HAVE_NANOSLEEP)
307         MESSAGE(FATAL_ERROR "No sleep function found!")
308     ENDIF()
310     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
311     IF(HAVE_PTHREAD)
312         ADD_DEFINITIONS(-pthread)
313         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
314     ENDIF()
316     # We need pthreads outside of Windows
317     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
318     IF(NOT HAVE_PTHREAD_H)
319         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
320     ENDIF()
321     # Some systems need pthread_np.h to get recursive mutexes
322     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
324     # _GNU_SOURCE is needed on some systems for extra attributes, and
325     # _REENTRANT is needed for libc thread-safety
326     ADD_DEFINITIONS(-D_GNU_SOURCE=1)
327     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
328     IF(HAVE_LIBPTHREAD)
329         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
330     ENDIF()
332     CHECK_LIBRARY_EXISTS(pthread pthread_setschedparam "" HAVE_PTHREAD_SETSCHEDPARAM)
334     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
335     IF(HAVE_LIBRT)
336         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
337     ENDIF()
338 ENDIF()
340 # Check for a 64-bit type
341 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
342 IF(NOT HAVE_STDINT_H)
343     IF(HAVE_WINDOWS_H)
344         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
345                                  \#include <windows.h>
346                                  __int64 foo;
347                                  int main() {return 0;}" HAVE___INT64)
348     ENDIF()
349     IF(NOT HAVE___INT64)
350         IF(NOT SIZEOF_LONG MATCHES "8")
351             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
352                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
353             ENDIF()
354         ENDIF()
355     ENDIF()
356 ENDIF()
358 # Windows needs winmm for timeGetTime, even if the backend is disabled
359 CHECK_SHARED_FUNCTION_EXISTS(timeGetTime "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
360 IF(HAVE_LIBWINMM)
361     SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
362     SET(PKG_CONFIG_LIBS ${PKG_CONFIG_LIBS} -lwinmm)
363 ENDIF()
366 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
367                  OpenAL32/alBuffer.c
368                  OpenAL32/alEffect.c
369                  OpenAL32/alError.c
370                  OpenAL32/alExtension.c
371                  OpenAL32/alFilter.c
372                  OpenAL32/alListener.c
373                  OpenAL32/alSource.c
374                  OpenAL32/alState.c
375                  OpenAL32/alThunk.c
377 SET(ALC_OBJS  Alc/ALc.c
378               Alc/ALu.c
379               Alc/alcConfig.c
380               Alc/alcDedicated.c
381               Alc/alcEcho.c
382               Alc/alcModulator.c
383               Alc/alcReverb.c
384               Alc/alcRing.c
385               Alc/alcThread.c
386               Alc/bs2b.c
387               Alc/helpers.c
388               Alc/hrtf.c
389               Alc/mixer.c
390               Alc/panning.c
391               # Default backends, always available
392               Alc/backends/loopback.c
393               Alc/backends/null.c
396 SET(BACKENDS "")
397 SET(HAVE_ALSA       0)
398 SET(HAVE_OSS        0)
399 SET(HAVE_SOLARIS    0)
400 SET(HAVE_SNDIO      0)
401 SET(HAVE_DSOUND     0)
402 SET(HAVE_WINMM      0)
403 SET(HAVE_PORTAUDIO  0)
404 SET(HAVE_PULSEAUDIO 0)
405 SET(HAVE_COREAUDIO  0)
406 SET(HAVE_OPENSL     0)
407 SET(HAVE_WAVE       0)
409 # Check ALSA backend
410 IF(ALSA)
411     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
412     IF(HAVE_ALSA_ASOUNDLIB_H)
413         CHECK_SHARED_FUNCTION_EXISTS(snd_pcm_open "alsa/asoundlib.h" asound "" HAVE_LIBASOUND)
414         IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
415             SET(HAVE_ALSA 1)
416             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
417             IF(HAVE_DLFCN_H OR WIN32)
418                 SET(BACKENDS  "${BACKENDS} ALSA,")
419             ELSE()
420                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
421                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
422             ENDIF()
423         ENDIF()
424     ENDIF()
425 ENDIF()
426 IF(REQUIRE_ALSA AND NOT HAVE_ALSA)
427     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
428 ENDIF()
430 # Check OSS backend
431 IF(OSS)
432     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
433     IF(HAVE_SYS_SOUNDCARD_H)
434         SET(HAVE_OSS 1)
435         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
436         SET(BACKENDS  "${BACKENDS} OSS,")
437     ENDIF()
438 ENDIF()
439 IF(REQUIRE_OSS AND NOT HAVE_OSS)
440     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
441 ENDIF()
443 # Check Solaris backend
444 IF(SOLARIS)
445     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
446     IF(HAVE_SYS_AUDIOIO_H)
447         SET(HAVE_SOLARIS 1)
448         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
449         SET(BACKENDS  "${BACKENDS} Solaris,")
450     ENDIF()
451 ENDIF()
452 IF(REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
453     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
454 ENDIF()
456 # Check SndIO backend
457 IF(SNDIO)
458     CHECK_INCLUDE_FILE(sndio.h HAVE_SNDIO_H)
459     IF(HAVE_SNDIO_H)
460         CHECK_SHARED_FUNCTION_EXISTS(sio_open "sndio.h" sndio "" HAVE_LIBSNDIO)
461         IF(HAVE_LIBSNDIO OR HAVE_DLFCN_H OR WIN32)
462             SET(HAVE_SNDIO 1)
463             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
464             IF(HAVE_DLFCN_H OR WIN32)
465                 SET(BACKENDS  "${BACKENDS} SndIO,")
466             ELSE()
467                 SET(BACKENDS  "${BACKENDS} SndIO \(linked\),")
468                 SET(EXTRA_LIBS sndio ${EXTRA_LIBS})
469             ENDIF()
470         ENDIF()
471     ENDIF()
472 ENDIF()
473 IF(REQUIRE_SNDIO AND NOT HAVE_SNDIO)
474     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
475 ENDIF()
477 # Check for MMDevApi backend
478 IF(HAVE_WINDOWS_H)
479     IF(MMDEVAPI)
480         CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
481         IF(HAVE_MMDEVICEAPI_H)
482             SET(HAVE_MMDEVAPI 1)
483             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
485             SET(BACKENDS  "${BACKENDS} MMDevApi,")
486         ENDIF()
487     ENDIF()
488 ENDIF()
489 IF(REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
490     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
491 ENDIF()
493 # Check DSound/MMSystem backend
494 IF(DSOUND)
495     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
496     IF(HAVE_DSOUND_H)
497         CHECK_SHARED_FUNCTION_EXISTS(DirectSoundCreate "dsound.h" dsound "" HAVE_LIBDSOUND)
498         IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
499             SET(HAVE_DSOUND 1)
500             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
502             IF(HAVE_DLFCN_H OR WIN32)
503                 SET(BACKENDS  "${BACKENDS} DirectSound,")
504             ELSE()
505                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
506                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
507             ENDIF()
508         ENDIF()
509     ENDIF()
510 ENDIF()
511 IF(REQUIRE_DSOUND AND NOT HAVE_DSOUND)
512     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
513 ENDIF()
515 IF(HAVE_WINDOWS_H)
516     IF(WINMM)
517         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
518         IF(HAVE_MMSYSTEM_H AND HAVE_LIBWINMM)
519             SET(HAVE_WINMM 1)
520             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
521             SET(BACKENDS  "${BACKENDS} WinMM,")
522         ENDIF()
523     ENDIF()
524 ENDIF()
525 IF(REQUIRE_WINMM AND NOT HAVE_WINMM)
526     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
527 ENDIF()
529 # Check PortAudio backend
530 IF(PORTAUDIO)
531     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
532     IF(HAVE_PORTAUDIO_H)
533         CHECK_SHARED_FUNCTION_EXISTS(Pa_Initialize "portaudio.h" portaudio "" HAVE_LIBPORTAUDIO)
534         IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
535             SET(HAVE_PORTAUDIO 1)
536             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
537             IF(HAVE_DLFCN_H OR WIN32)
538                 SET(BACKENDS  "${BACKENDS} PortAudio,")
539             ELSE()
540                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
541                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
542             ENDIF()
543         ENDIF()
544     ENDIF()
545 ENDIF()
546 IF(REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
547     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
548 ENDIF()
550 # Check PulseAudio backend
551 IF(PULSEAUDIO)
552     CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
553     IF(HAVE_PULSE_PULSEAUDIO_H)
554         CHECK_SHARED_FUNCTION_EXISTS(pa_context_new "pulse/pulseaudio.h" pulse "" HAVE_LIBPULSE)
555         IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
556             SET(HAVE_PULSEAUDIO 1)
557             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
558             IF(HAVE_DLFCN_H OR WIN32)
559                 SET(BACKENDS  "${BACKENDS} PulseAudio,")
560             ELSE()
561                 SET(BACKENDS  "${BACKENDS} PulseAudio \(linked\),")
562                 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
563             ENDIF()
564         ENDIF()
565     ENDIF()
566 ENDIF()
567 IF(REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
568     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
569 ENDIF()
571 # Check CoreAudio backend
572 IF(COREAUDIO)
573     CHECK_INCLUDE_FILE(/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h HAVE_COREAUDIO_FRAMEWORK)
574     IF(HAVE_COREAUDIO_FRAMEWORK)
575         SET(HAVE_COREAUDIO 1)
576         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
577         SET(BACKENDS  "${BACKENDS} CoreAudio,")
578         SET(EXTRA_LIBS /System/Library/Frameworks/CoreAudio.framework ${EXTRA_LIBS})
579         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
580         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
581     ENDIF()
582 ENDIF()
583 IF(REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
584     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
585 ENDIF()
587 # Check for OpenSL (Android) backend
588 IF(OPENSL)
589     CHECK_INCLUDE_FILE(SLES/OpenSLES_Android.h HAVE_SLES_OPENSLES_ANDROID_H)
590     IF(HAVE_SLES_OPENSLES_ANDROID_H)
591         CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
592         IF(HAVE_LIBOPENSLES)
593             SET(HAVE_OPENSL 1)
594             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
595             SET(BACKENDS  "${BACKENDS} OpenSL,")
596             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
597         ENDIF()
598     ENDIF()
599 ENDIF()
600 IF(REQUIRE_OPENSL AND NOT HAVE_OPENSL)
601     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
602 ENDIF()
604 # Optionally enable the Wave Writer backend
605 IF(WAVE)
606     SET(HAVE_WAVE 1)
607     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
608     SET(BACKENDS  "${BACKENDS} WaveFile,")
609 ENDIF()
611 # This is always available
612 SET(BACKENDS  "${BACKENDS} Null")
614 IF(LIBTYPE STREQUAL "STATIC")
615     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
616     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
617 ENDIF()
619 # Needed for openal.pc.in
620 SET(prefix ${CMAKE_INSTALL_PREFIX})
621 SET(exec_prefix "\${prefix}")
622 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
623 SET(bindir "\${exec_prefix}/bin")
624 SET(includedir "\${prefix}/include")
625 SET(PACKAGE_VERSION "${LIB_VERSION}")
627 # End configuration
628 CONFIGURE_FILE(
629     "${OpenAL_SOURCE_DIR}/config.h.in"
630     "${OpenAL_BINARY_DIR}/config.h")
631 CONFIGURE_FILE(
632     "${OpenAL_SOURCE_DIR}/openal.pc.in"
633     "${OpenAL_BINARY_DIR}/openal.pc"
634     @ONLY)
636 # Build a library
637 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
638 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
639                                             COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
640                                             VERSION ${LIB_VERSION}.0
641                                             SOVERSION ${LIB_MAJOR_VERSION})
642 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
643     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
644 ENDIF()
646 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
648 # Add an install target here
649 INSTALL(TARGETS ${LIBNAME}
650         RUNTIME DESTINATION bin
651         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
652         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
654 INSTALL(FILES include/AL/al.h
655               include/AL/alc.h
656               include/AL/alext.h
657               include/AL/efx.h
658               include/AL/efx-creative.h
659         DESTINATION include/AL
661 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
662         DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
665 MESSAGE(STATUS "")
666 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
667 MESSAGE(STATUS "    ${BACKENDS}")
668 MESSAGE(STATUS "")
670 IF(WIN32)
671     IF(NOT HAVE_DSOUND)
672         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
673         MESSAGE(STATUS "         This is probably NOT what you want!")
674         MESSAGE(STATUS "")
675     ENDIF()
676 ENDIF()
678 # Install alsoft.conf configuration file
679 IF(ALSOFT_CONFIG)
680     INSTALL(FILES alsoftrc.sample
681             DESTINATION /etc/openal
682             RENAME alsoft.conf
683     )
684     MESSAGE(STATUS "Installing sample alsoft.conf")
685     MESSAGE(STATUS "")
686 ENDIF()
688 IF(UTILS)
689     ADD_EXECUTABLE(openal-info utils/openal-info.c)
690     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
691     INSTALL(TARGETS openal-info
692             RUNTIME DESTINATION bin
693             LIBRARY DESTINATION "lib${LIB_SUFFIX}"
694             ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
695     )
696     MESSAGE(STATUS "Building utility programs")
697     MESSAGE(STATUS "")
698 ENDIF()