Use fast float-to-int conversions for some mixer-related code
[openal-soft/android.git] / CMakeLists.txt
blob14492387ceb5e7f5087645339a1888e7668fc316
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 -D_WIN32_WINNT=0x0500")
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)
84 CHECK_C_SOURCE_COMPILES("int *restrict foo;
85                          int main() {return 0;}" HAVE_RESTRICT)
86 CHECK_C_SOURCE_COMPILES("int *__restrict foo;
87                          int main() {return 0;}" HAVE___RESTRICT)
90 # Add definitions, compiler switches, etc.
91 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
93 IF(NOT CMAKE_BUILD_TYPE)
94     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
95         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
96         FORCE)
97 ENDIF()
98 IF(NOT CMAKE_DEBUG_POSTFIX)
99     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
100         "Library postfix for debug builds. Normally left blank."
101         FORCE)
102 ENDIF()
104 IF(MSVC)
105     # ???
106     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
107     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
108     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
109     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
110     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
111     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
113     IF(NOT DXSDK_DIR)
114         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
115     ELSE()
116         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
117     ENDIF()
118     IF(DXSDK_DIR)
119         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
120         SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
121         INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
122         LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
123     ENDIF()
125     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
126     IF(FORCE_STATIC_VCRT)
127         FOREACH(flag_var
128                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
129                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
130             IF(${flag_var} MATCHES "/MD")
131                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
132             ENDIF()
133         ENDFOREACH(flag_var)
134     ENDIF()
135 ELSE()
136     ADD_DEFINITIONS(-Winline -Wall)
137     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
138     IF(HAVE_W_EXTRA)
139         ADD_DEFINITIONS(-Wextra)
140     ENDIF()
142     IF(WERROR)
143         ADD_DEFINITIONS(-Werror)
144     ENDIF()
146     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -D_DEBUG" CACHE STRING
147         "Flags used by the compiler during Release with Debug Info builds."
148         FORCE)
149     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
150         "Flags used by the compiler during release minsize builds."
151         FORCE)
152     SET(CMAKE_C_FLAGS_RELEASE "-O2 -fomit-frame-pointer -DNDEBUG" CACHE STRING
153         "Flags used by the compiler during release builds"
154         FORCE)
155     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
156         "Flags used by the compiler during debug builds."
157         FORCE)
159     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
160                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
161 ENDIF()
163 # Set visibility/export options if available
164 IF(WIN32)
165     SET(EXPORT_DECL "__declspec(dllexport)")
167     OPTION(WINE "Enable use of Wine headers when compiling" OFF)
168     IF(WINE)
169         FIND_PATH(WINE_INCLUDE_DIR library.h
170                   PATHS
171                   /usr/include/wine
172                   /usr/local/include/wine
173                   CMAKE_FIND_ROOT_PATH_BOTH)
174         IF(WINE_INCLUDE_DIR)
175             MESSAGE(STATUS "Found Wine header files - ${WINE_INCLUDE_DIR}" )
176             INCLUDE_DIRECTORIES("${WINE_INCLUDE_DIR}/windows")
177             SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${WINE_INCLUDE_DIR}/windows")
178         ELSE()
179             MESSAGE(STATUS "Could not find Wine header files" )
180         ENDIF()
181     ENDIF()
182 ELSE()
183     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
184     # Yes GCC, really don't accept visibility modes you don't support
185     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror")
187     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
188                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
189     IF(HAVE_GCC_PROTECTED_VISIBILITY)
190         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
191     ELSE()
192         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
193                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
194         IF(HAVE_GCC_DEFAULT_VISIBILITY)
195             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
196         ENDIF()
197     ENDIF()
199     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
200         CHECK_C_COMPILER_FLAG(-fvisibility=internal HAVE_VISIBILITY_INTERNAL_SWITCH)
201         IF(HAVE_VISIBILITY_INTERNAL_SWITCH)
202             ADD_DEFINITIONS(-fvisibility=internal)
203         ELSE()
204             CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
205             IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
206                 ADD_DEFINITIONS(-fvisibility=hidden)
207             ENDIF()
208         ENDIF()
209     ENDIF()
211     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
212 ENDIF()
214 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
215                          int main() {return 0;}" HAVE_GCC_FORMAT)
217 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
218 CHECK_INCLUDE_FILE(fpu_control.h HAVE_FPU_CONTROL_H)
219 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
220 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
221 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
222 IF(NOT HAVE_GUIDDEF_H)
223     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
224 ENDIF()
225 CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
227 # Some systems need libm for some of the following math functions to work
228 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
229 IF(HAVE_LIBM)
230     SET(EXTRA_LIBS m ${EXTRA_LIBS})
231     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
232 ENDIF()
235 CHECK_SYMBOL_EXISTS(powf   math.h HAVE_POWF)
236 CHECK_SYMBOL_EXISTS(sqrtf  math.h HAVE_SQRTF)
237 CHECK_SYMBOL_EXISTS(cosf   math.h HAVE_COSF)
238 CHECK_SYMBOL_EXISTS(sinf   math.h HAVE_SINF)
239 CHECK_SYMBOL_EXISTS(acosf  math.h HAVE_ACOSF)
240 CHECK_SYMBOL_EXISTS(asinf  math.h HAVE_ASINF)
241 CHECK_SYMBOL_EXISTS(atanf  math.h HAVE_ATANF)
242 CHECK_SYMBOL_EXISTS(atan2f math.h HAVE_ATAN2F)
243 CHECK_SYMBOL_EXISTS(fabsf  math.h HAVE_FABSF)
244 CHECK_SYMBOL_EXISTS(log10f math.h HAVE_LOG10F)
245 CHECK_SYMBOL_EXISTS(floorf math.h HAVE_FLOORF)
247 IF(HAVE_FENV_H)
248     CHECK_SYMBOL_EXISTS(fesetround fenv.h HAVE_FESETROUND)
249 ENDIF()
251 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
252 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
254 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
255 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
256 IF(NOT HAVE_STRCASECMP)
257     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
258     IF(NOT HAVE__STRICMP)
259         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
260     ENDIF()
262     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
263 ENDIF()
265 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
266 IF(NOT HAVE_STRNCASECMP)
267     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
268     IF(NOT HAVE__STRNICMP)
269         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
270     ENDIF()
272     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
273 ENDIF()
275 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
276 IF(NOT HAVE_SNPRINTF)
277     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
278     IF(NOT HAVE__SNPRINTF)
279         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
280     ENDIF()
282     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
283 ENDIF()
285 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
286 IF(NOT HAVE_VSNPRINTF)
287     CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
288     IF(NOT HAVE__VSNPRINTF)
289         MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
290     ENDIF()
292     ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
293 ENDIF()
295 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
296 IF(NOT HAVE_ISFINITE)
297     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
298     IF(NOT HAVE_FINITE)
299         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
300         IF(NOT HAVE__FINITE)
301             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
302         ENDIF()
303         ADD_DEFINITIONS(-Disfinite=_finite)
304     ELSE()
305         ADD_DEFINITIONS(-Disfinite=finite)
306     ENDIF()
307 ENDIF()
309 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
310 IF(NOT HAVE_ISNAN)
311     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
312     IF(NOT HAVE__ISNAN)
313         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
314     ENDIF()
316     ADD_DEFINITIONS(-Disnan=_isnan)
317 ENDIF()
320 # Check for the dlopen API (for dynamicly loading backend libs)
321 IF(DLOPEN)
322     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
323     IF(HAVE_DLFCN_H)
324         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
325         IF(HAVE_LIBDL)
326             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
327         ENDIF()
328     ENDIF()
329 ENDIF()
331 # Check if we have Windows headers
332 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
333 IF(NOT HAVE_WINDOWS_H)
334     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
335     IF(NOT HAVE_GETTIMEOFDAY)
336         MESSAGE(FATAL_ERROR "No timing function found!")
337     ENDIF()
339     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
340     IF(NOT HAVE_NANOSLEEP)
341         MESSAGE(FATAL_ERROR "No sleep function found!")
342     ENDIF()
344     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
345     IF(HAVE_PTHREAD)
346         ADD_DEFINITIONS(-pthread)
347         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
348     ENDIF()
350     # We need pthreads outside of Windows
351     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
352     IF(NOT HAVE_PTHREAD_H)
353         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
354     ENDIF()
355     # Some systems need pthread_np.h to get recursive mutexes
356     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
358     # _GNU_SOURCE is needed on some systems for extra attributes, and
359     # _REENTRANT is needed for libc thread-safety
360     ADD_DEFINITIONS(-D_GNU_SOURCE=1)
361     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
362     IF(HAVE_LIBPTHREAD)
363         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
364     ENDIF()
366     CHECK_LIBRARY_EXISTS(pthread pthread_setschedparam "" HAVE_PTHREAD_SETSCHEDPARAM)
368     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
369     IF(HAVE_LIBRT)
370         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
371     ENDIF()
372 ENDIF()
374 # Check for a 64-bit type
375 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
376 IF(NOT HAVE_STDINT_H)
377     IF(HAVE_WINDOWS_H)
378         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
379                                  \#include <windows.h>
380                                  __int64 foo;
381                                  int main() {return 0;}" HAVE___INT64)
382     ENDIF()
383     IF(NOT HAVE___INT64)
384         IF(NOT SIZEOF_LONG MATCHES "8")
385             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
386                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
387             ENDIF()
388         ENDIF()
389     ENDIF()
390 ENDIF()
392 # Windows needs winmm for timeGetTime, even if the backend is disabled
393 CHECK_SHARED_FUNCTION_EXISTS(timeGetTime "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
394 IF(HAVE_LIBWINMM)
395     SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
396     SET(PKG_CONFIG_LIBS ${PKG_CONFIG_LIBS} -lwinmm)
397 ENDIF()
400 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
401                  OpenAL32/alBuffer.c
402                  OpenAL32/alEffect.c
403                  OpenAL32/alError.c
404                  OpenAL32/alExtension.c
405                  OpenAL32/alFilter.c
406                  OpenAL32/alListener.c
407                  OpenAL32/alSource.c
408                  OpenAL32/alState.c
409                  OpenAL32/alThunk.c
411 SET(ALC_OBJS  Alc/ALc.c
412               Alc/ALu.c
413               Alc/alcConfig.c
414               Alc/alcDedicated.c
415               Alc/alcEcho.c
416               Alc/alcModulator.c
417               Alc/alcReverb.c
418               Alc/alcRing.c
419               Alc/alcThread.c
420               Alc/bs2b.c
421               Alc/helpers.c
422               Alc/hrtf.c
423               Alc/mixer.c
424               Alc/panning.c
425               # Default backends, always available
426               Alc/backends/loopback.c
427               Alc/backends/null.c
430 SET(BACKENDS "")
431 SET(HAVE_ALSA       0)
432 SET(HAVE_OSS        0)
433 SET(HAVE_SOLARIS    0)
434 SET(HAVE_SNDIO      0)
435 SET(HAVE_DSOUND     0)
436 SET(HAVE_WINMM      0)
437 SET(HAVE_PORTAUDIO  0)
438 SET(HAVE_PULSEAUDIO 0)
439 SET(HAVE_COREAUDIO  0)
440 SET(HAVE_OPENSL     0)
441 SET(HAVE_WAVE       0)
443 # Check ALSA backend
444 IF(ALSA)
445     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
446     IF(HAVE_ALSA_ASOUNDLIB_H)
447         CHECK_SHARED_FUNCTION_EXISTS(snd_pcm_open "alsa/asoundlib.h" asound "" HAVE_LIBASOUND)
448         IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
449             SET(HAVE_ALSA 1)
450             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
451             IF(HAVE_DLFCN_H OR WIN32)
452                 SET(BACKENDS  "${BACKENDS} ALSA,")
453             ELSE()
454                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
455                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
456             ENDIF()
457         ENDIF()
458     ENDIF()
459 ENDIF()
460 IF(REQUIRE_ALSA AND NOT HAVE_ALSA)
461     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
462 ENDIF()
464 # Check OSS backend
465 IF(OSS)
466     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
467     IF(HAVE_SYS_SOUNDCARD_H)
468         SET(HAVE_OSS 1)
469         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
470         SET(BACKENDS  "${BACKENDS} OSS,")
471     ENDIF()
472 ENDIF()
473 IF(REQUIRE_OSS AND NOT HAVE_OSS)
474     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
475 ENDIF()
477 # Check Solaris backend
478 IF(SOLARIS)
479     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
480     IF(HAVE_SYS_AUDIOIO_H)
481         SET(HAVE_SOLARIS 1)
482         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
483         SET(BACKENDS  "${BACKENDS} Solaris,")
484     ENDIF()
485 ENDIF()
486 IF(REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
487     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
488 ENDIF()
490 # Check SndIO backend
491 IF(SNDIO)
492     CHECK_INCLUDE_FILE(sndio.h HAVE_SNDIO_H)
493     IF(HAVE_SNDIO_H)
494         CHECK_SHARED_FUNCTION_EXISTS(sio_open "sndio.h" sndio "" HAVE_LIBSNDIO)
495         IF(HAVE_LIBSNDIO OR HAVE_DLFCN_H OR WIN32)
496             SET(HAVE_SNDIO 1)
497             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
498             IF(HAVE_DLFCN_H OR WIN32)
499                 SET(BACKENDS  "${BACKENDS} SndIO,")
500             ELSE()
501                 SET(BACKENDS  "${BACKENDS} SndIO \(linked\),")
502                 SET(EXTRA_LIBS sndio ${EXTRA_LIBS})
503             ENDIF()
504         ENDIF()
505     ENDIF()
506 ENDIF()
507 IF(REQUIRE_SNDIO AND NOT HAVE_SNDIO)
508     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
509 ENDIF()
511 # Check for MMDevApi backend
512 IF(HAVE_WINDOWS_H)
513     IF(MMDEVAPI)
514         CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
515         IF(HAVE_MMDEVICEAPI_H)
516             SET(HAVE_MMDEVAPI 1)
517             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
519             SET(BACKENDS  "${BACKENDS} MMDevApi,")
520         ENDIF()
521     ENDIF()
522 ENDIF()
523 IF(REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
524     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
525 ENDIF()
527 # Check DSound/MMSystem backend
528 IF(DSOUND)
529     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
530     IF(HAVE_DSOUND_H)
531         CHECK_SHARED_FUNCTION_EXISTS(DirectSoundCreate "dsound.h" dsound "" HAVE_LIBDSOUND)
532         IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
533             SET(HAVE_DSOUND 1)
534             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
536             IF(HAVE_DLFCN_H OR WIN32)
537                 SET(BACKENDS  "${BACKENDS} DirectSound,")
538             ELSE()
539                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
540                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
541             ENDIF()
542         ENDIF()
543     ENDIF()
544 ENDIF()
545 IF(REQUIRE_DSOUND AND NOT HAVE_DSOUND)
546     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
547 ENDIF()
549 IF(HAVE_WINDOWS_H)
550     IF(WINMM)
551         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
552         IF(HAVE_MMSYSTEM_H AND HAVE_LIBWINMM)
553             SET(HAVE_WINMM 1)
554             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
555             SET(BACKENDS  "${BACKENDS} WinMM,")
556         ENDIF()
557     ENDIF()
558 ENDIF()
559 IF(REQUIRE_WINMM AND NOT HAVE_WINMM)
560     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
561 ENDIF()
563 # Check PortAudio backend
564 IF(PORTAUDIO)
565     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
566     IF(HAVE_PORTAUDIO_H)
567         CHECK_SHARED_FUNCTION_EXISTS(Pa_Initialize "portaudio.h" portaudio "" HAVE_LIBPORTAUDIO)
568         IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
569             SET(HAVE_PORTAUDIO 1)
570             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
571             IF(HAVE_DLFCN_H OR WIN32)
572                 SET(BACKENDS  "${BACKENDS} PortAudio,")
573             ELSE()
574                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
575                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
576             ENDIF()
577         ENDIF()
578     ENDIF()
579 ENDIF()
580 IF(REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
581     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
582 ENDIF()
584 # Check PulseAudio backend
585 IF(PULSEAUDIO)
586     CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
587     IF(HAVE_PULSE_PULSEAUDIO_H)
588         CHECK_SHARED_FUNCTION_EXISTS(pa_context_new "pulse/pulseaudio.h" pulse "" HAVE_LIBPULSE)
589         IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
590             SET(HAVE_PULSEAUDIO 1)
591             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
592             IF(HAVE_DLFCN_H OR WIN32)
593                 SET(BACKENDS  "${BACKENDS} PulseAudio,")
594             ELSE()
595                 SET(BACKENDS  "${BACKENDS} PulseAudio \(linked\),")
596                 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
597             ENDIF()
598         ENDIF()
599     ENDIF()
600 ENDIF()
601 IF(REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
602     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
603 ENDIF()
605 # Check CoreAudio backend
606 IF(COREAUDIO)
607     CHECK_INCLUDE_FILE(/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h HAVE_COREAUDIO_FRAMEWORK)
608     IF(HAVE_COREAUDIO_FRAMEWORK)
609         SET(HAVE_COREAUDIO 1)
610         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
611         SET(BACKENDS  "${BACKENDS} CoreAudio,")
612         SET(EXTRA_LIBS /System/Library/Frameworks/CoreAudio.framework ${EXTRA_LIBS})
613         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
614         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
615     ENDIF()
616 ENDIF()
617 IF(REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
618     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
619 ENDIF()
621 # Check for OpenSL (Android) backend
622 IF(OPENSL)
623     CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
624     IF(HAVE_SLES_OPENSLES_ANDROID_H)
625         CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
626         IF(HAVE_LIBOPENSLES)
627             SET(HAVE_OPENSL 1)
628             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
629             SET(BACKENDS  "${BACKENDS} OpenSL,")
630             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
631         ENDIF()
632     ENDIF()
633 ENDIF()
634 IF(REQUIRE_OPENSL AND NOT HAVE_OPENSL)
635     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
636 ENDIF()
638 # Optionally enable the Wave Writer backend
639 IF(WAVE)
640     SET(HAVE_WAVE 1)
641     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
642     SET(BACKENDS  "${BACKENDS} WaveFile,")
643 ENDIF()
645 # This is always available
646 SET(BACKENDS  "${BACKENDS} Null")
648 IF(LIBTYPE STREQUAL "STATIC")
649     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
650     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
651 ENDIF()
653 # Needed for openal.pc.in
654 SET(prefix ${CMAKE_INSTALL_PREFIX})
655 SET(exec_prefix "\${prefix}")
656 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
657 SET(bindir "\${exec_prefix}/bin")
658 SET(includedir "\${prefix}/include")
659 SET(PACKAGE_VERSION "${LIB_VERSION}")
661 # End configuration
662 CONFIGURE_FILE(
663     "${OpenAL_SOURCE_DIR}/config.h.in"
664     "${OpenAL_BINARY_DIR}/config.h")
665 CONFIGURE_FILE(
666     "${OpenAL_SOURCE_DIR}/openal.pc.in"
667     "${OpenAL_BINARY_DIR}/openal.pc"
668     @ONLY)
670 # Build a library
671 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
672 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
673                                             COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
674                                             VERSION ${LIB_VERSION}.0
675                                             SOVERSION ${LIB_MAJOR_VERSION})
676 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
677     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
678 ENDIF()
680 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
682 # Add an install target here
683 INSTALL(TARGETS ${LIBNAME}
684         RUNTIME DESTINATION bin
685         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
686         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
688 INSTALL(FILES include/AL/al.h
689               include/AL/alc.h
690               include/AL/alext.h
691               include/AL/efx.h
692               include/AL/efx-creative.h
693         DESTINATION include/AL
695 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
696         DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
699 MESSAGE(STATUS "")
700 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
701 MESSAGE(STATUS "    ${BACKENDS}")
702 MESSAGE(STATUS "")
704 IF(WIN32)
705     IF(NOT HAVE_DSOUND)
706         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
707         MESSAGE(STATUS "         This is probably NOT what you want!")
708         MESSAGE(STATUS "")
709     ENDIF()
710 ENDIF()
712 # Install alsoft.conf configuration file
713 IF(ALSOFT_CONFIG)
714     INSTALL(FILES alsoftrc.sample
715             DESTINATION /etc/openal
716             RENAME alsoft.conf
717     )
718     MESSAGE(STATUS "Installing sample alsoft.conf")
719     MESSAGE(STATUS "")
720 ENDIF()
722 IF(UTILS)
723     ADD_EXECUTABLE(openal-info utils/openal-info.c)
724     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
725     INSTALL(TARGETS openal-info
726             RUNTIME DESTINATION bin
727             LIBRARY DESTINATION "lib${LIB_SUFFIX}"
728             ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
729     )
730     MESSAGE(STATUS "Building utility programs")
731     MESSAGE(STATUS "")
732 ENDIF()