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