Use ComputeAngleGains for the echo and dedicated effects
[openal-soft/openal-hmr.git] / CMakeLists.txt
blobe91eab845de1173c83bdf1478afb497d8eff6899
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=0x0501")
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 "14")
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=0x0501)
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 0x0501
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_MMDEVAPI   0)
440 SET(HAVE_WINMM      0)
441 SET(HAVE_PORTAUDIO  0)
442 SET(HAVE_PULSEAUDIO 0)
443 SET(HAVE_COREAUDIO  0)
444 SET(HAVE_OPENSL     0)
445 SET(HAVE_WAVE       0)
447 # Check ALSA backend
448 IF(ALSA)
449     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
450     IF(HAVE_ALSA_ASOUNDLIB_H)
451         CHECK_SHARED_FUNCTION_EXISTS(snd_pcm_open "alsa/asoundlib.h" asound "" HAVE_LIBASOUND)
452         IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
453             SET(HAVE_ALSA 1)
454             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
455             IF(HAVE_DLFCN_H OR WIN32)
456                 SET(BACKENDS  "${BACKENDS} ALSA,")
457             ELSE()
458                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
459                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
460             ENDIF()
461         ENDIF()
462     ENDIF()
463 ENDIF()
464 IF(REQUIRE_ALSA AND NOT HAVE_ALSA)
465     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
466 ENDIF()
468 # Check OSS backend
469 IF(OSS)
470     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
471     IF(HAVE_SYS_SOUNDCARD_H)
472         SET(HAVE_OSS 1)
473         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
474         SET(BACKENDS  "${BACKENDS} OSS,")
475     ENDIF()
476 ENDIF()
477 IF(REQUIRE_OSS AND NOT HAVE_OSS)
478     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
479 ENDIF()
481 # Check Solaris backend
482 IF(SOLARIS)
483     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
484     IF(HAVE_SYS_AUDIOIO_H)
485         SET(HAVE_SOLARIS 1)
486         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
487         SET(BACKENDS  "${BACKENDS} Solaris,")
488     ENDIF()
489 ENDIF()
490 IF(REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
491     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
492 ENDIF()
494 # Check SndIO backend
495 IF(SNDIO)
496     CHECK_INCLUDE_FILE(sndio.h HAVE_SNDIO_H)
497     IF(HAVE_SNDIO_H)
498         CHECK_SHARED_FUNCTION_EXISTS(sio_open "sndio.h" sndio "" HAVE_LIBSNDIO)
499         IF(HAVE_LIBSNDIO OR HAVE_DLFCN_H OR WIN32)
500             SET(HAVE_SNDIO 1)
501             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
502             IF(HAVE_DLFCN_H OR WIN32)
503                 SET(BACKENDS  "${BACKENDS} SndIO,")
504             ELSE()
505                 SET(BACKENDS  "${BACKENDS} SndIO \(linked\),")
506                 SET(EXTRA_LIBS sndio ${EXTRA_LIBS})
507             ENDIF()
508         ENDIF()
509     ENDIF()
510 ENDIF()
511 IF(REQUIRE_SNDIO AND NOT HAVE_SNDIO)
512     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
513 ENDIF()
515 # Check for MMDevApi backend
516 IF(HAVE_WINDOWS_H)
517     IF(MMDEVAPI)
518         CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
519         IF(HAVE_MMDEVICEAPI_H)
520             SET(HAVE_MMDEVAPI 1)
521             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
523             SET(BACKENDS  "${BACKENDS} MMDevApi,")
524         ENDIF()
525     ENDIF()
526 ENDIF()
527 IF(REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
528     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
529 ENDIF()
531 # Check DSound/MMSystem backend
532 IF(DSOUND)
533     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
534     IF(HAVE_DSOUND_H)
535         CHECK_SHARED_FUNCTION_EXISTS(DirectSoundCreate "dsound.h" dsound "" HAVE_LIBDSOUND)
536         IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
537             SET(HAVE_DSOUND 1)
538             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
540             IF(HAVE_DLFCN_H OR WIN32)
541                 SET(BACKENDS  "${BACKENDS} DirectSound,")
542             ELSE()
543                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
544                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
545             ENDIF()
546         ENDIF()
547     ENDIF()
548 ENDIF()
549 IF(REQUIRE_DSOUND AND NOT HAVE_DSOUND)
550     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
551 ENDIF()
553 IF(HAVE_WINDOWS_H)
554     IF(WINMM)
555         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0501)
556         IF(HAVE_MMSYSTEM_H AND HAVE_LIBWINMM)
557             SET(HAVE_WINMM 1)
558             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
559             SET(BACKENDS  "${BACKENDS} WinMM,")
560         ENDIF()
561     ENDIF()
562 ENDIF()
563 IF(REQUIRE_WINMM AND NOT HAVE_WINMM)
564     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
565 ENDIF()
567 # Check PortAudio backend
568 IF(PORTAUDIO)
569     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
570     IF(HAVE_PORTAUDIO_H)
571         CHECK_SHARED_FUNCTION_EXISTS(Pa_Initialize "portaudio.h" portaudio "" HAVE_LIBPORTAUDIO)
572         IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
573             SET(HAVE_PORTAUDIO 1)
574             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
575             IF(HAVE_DLFCN_H OR WIN32)
576                 SET(BACKENDS  "${BACKENDS} PortAudio,")
577             ELSE()
578                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
579                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
580             ENDIF()
581         ENDIF()
582     ENDIF()
583 ENDIF()
584 IF(REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
585     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
586 ENDIF()
588 # Check PulseAudio backend
589 IF(PULSEAUDIO)
590     CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
591     IF(HAVE_PULSE_PULSEAUDIO_H)
592         CHECK_SHARED_FUNCTION_EXISTS(pa_context_new "pulse/pulseaudio.h" pulse "" HAVE_LIBPULSE)
593         IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
594             SET(HAVE_PULSEAUDIO 1)
595             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
596             IF(HAVE_DLFCN_H OR WIN32)
597                 SET(BACKENDS  "${BACKENDS} PulseAudio,")
598             ELSE()
599                 SET(BACKENDS  "${BACKENDS} PulseAudio \(linked\),")
600                 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
601             ENDIF()
602         ENDIF()
603     ENDIF()
604 ENDIF()
605 IF(REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
606     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
607 ENDIF()
609 # Check CoreAudio backend
610 IF(COREAUDIO)
611     CHECK_INCLUDE_FILE(/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h HAVE_COREAUDIO_FRAMEWORK)
612     IF(HAVE_COREAUDIO_FRAMEWORK)
613         SET(HAVE_COREAUDIO 1)
614         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
615         SET(BACKENDS  "${BACKENDS} CoreAudio,")
616         SET(EXTRA_LIBS /System/Library/Frameworks/CoreAudio.framework ${EXTRA_LIBS})
617         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
618         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
620         # Some versions of OSX may need the AudioToolbox framework. Add it if
621         # it's found.
622         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
623                      NAMES AudioToolbox
624                      PATHS ~/Library/Frameworks
625                            /Library/Frameworks
626                            /System/Library/Frameworks
627                     )
628         IF(AUDIOTOOLBOX_LIBRARY)
629             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
630         ENDIF()
631     ENDIF()
632 ENDIF()
633 IF(REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
634     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
635 ENDIF()
637 # Check for OpenSL (Android) backend
638 IF(OPENSL)
639     CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
640     IF(HAVE_SLES_OPENSLES_ANDROID_H)
641         CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
642         IF(HAVE_LIBOPENSLES)
643             SET(HAVE_OPENSL 1)
644             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
645             SET(BACKENDS  "${BACKENDS} OpenSL,")
646             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
647         ENDIF()
648     ENDIF()
649 ENDIF()
650 IF(REQUIRE_OPENSL AND NOT HAVE_OPENSL)
651     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
652 ENDIF()
654 # Optionally enable the Wave Writer backend
655 IF(WAVE)
656     SET(HAVE_WAVE 1)
657     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
658     SET(BACKENDS  "${BACKENDS} WaveFile,")
659 ENDIF()
661 # This is always available
662 SET(BACKENDS  "${BACKENDS} Null")
664 IF(EXAMPLES)
665     # Might be able to use earlier versions, but these definitely work
666     PKG_CHECK_MODULES(FFMPEG libavcodec>=52.123.0 libavformat>=52.111.0 libavutil>=51.9.1)
667 ENDIF()
669 IF(LIBTYPE STREQUAL "STATIC")
670     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
671     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
672 ENDIF()
674 # Needed for openal.pc.in
675 SET(prefix ${CMAKE_INSTALL_PREFIX})
676 SET(exec_prefix "\${prefix}")
677 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
678 SET(bindir "\${exec_prefix}/bin")
679 SET(includedir "\${prefix}/include")
680 SET(PACKAGE_VERSION "${LIB_VERSION}")
682 # End configuration
683 CONFIGURE_FILE(
684     "${OpenAL_SOURCE_DIR}/config.h.in"
685     "${OpenAL_BINARY_DIR}/config.h")
686 CONFIGURE_FILE(
687     "${OpenAL_SOURCE_DIR}/openal.pc.in"
688     "${OpenAL_BINARY_DIR}/openal.pc"
689     @ONLY)
691 # Build a library
692 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
693 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
694                                             COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
695                                             VERSION ${LIB_VERSION}.0
696                                             SOVERSION ${LIB_MAJOR_VERSION})
697 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
698     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
699 ENDIF()
701 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
703 # Add an install target here
704 INSTALL(TARGETS ${LIBNAME}
705         RUNTIME DESTINATION bin
706         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
707         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
709 INSTALL(FILES include/AL/al.h
710               include/AL/alc.h
711               include/AL/alext.h
712               include/AL/efx.h
713               include/AL/efx-creative.h
714               include/AL/efx-presets.h
715         DESTINATION include/AL
717 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
718         DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
721 MESSAGE(STATUS "")
722 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
723 MESSAGE(STATUS "    ${BACKENDS}")
724 MESSAGE(STATUS "")
726 IF(WIN32)
727     IF(NOT HAVE_DSOUND)
728         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
729         MESSAGE(STATUS "         This is probably NOT what you want!")
730         MESSAGE(STATUS "")
731     ENDIF()
732 ENDIF()
734 # Install alsoft.conf configuration file
735 IF(ALSOFT_CONFIG)
736     INSTALL(FILES alsoftrc.sample
737             DESTINATION /etc/openal
738             RENAME alsoft.conf
739     )
740     MESSAGE(STATUS "Installing sample alsoft.conf")
741     MESSAGE(STATUS "")
742 ENDIF()
744 IF(UTILS)
745     ADD_EXECUTABLE(openal-info utils/openal-info.c)
746     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
748     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
749     IF(HAVE_LIBM)
750         TARGET_LINK_LIBRARIES(makehrtf m)
751     ENDIF()
753     INSTALL(TARGETS openal-info makehrtf
754             RUNTIME DESTINATION bin
755             LIBRARY DESTINATION "lib${LIB_SUFFIX}"
756             ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
757     )
758     MESSAGE(STATUS "Building utility programs")
759     MESSAGE(STATUS "")
760 ENDIF()
762 IF(EXAMPLES)
763     IF(FFMPEG_FOUND)
764         ADD_EXECUTABLE(alstream examples/alhelpers.c examples/alffmpeg.c examples/alstream.c)
765         TARGET_LINK_LIBRARIES(alstream ${FFMPEG_LIBRARIES} ${LIBNAME})
766         SET_TARGET_PROPERTIES(alstream PROPERTIES COMPILE_FLAGS "${FFMPEG_CFLAGS}")
767         INSTALL(TARGETS alstream
768                 RUNTIME DESTINATION bin
769                 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
770                 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
771         )
773         MESSAGE(STATUS "Building ffmpeg example programs")
774         MESSAGE(STATUS "")
775     ENDIF()
776 ENDIF()