Ensure the device's default effect slot is properly aligned
[openal-soft.git] / CMakeLists.txt
blobce5e7a10f0b30b1c3591988d1f966f4f2e94a5df
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(SSE  "Check for SSE CPU extensions"      ON)
30 OPTION(NEON "Check for ARM Neon CPU extensions" ON)
32 OPTION(REQUIRE_SSE  "Require SSE CPU extensions"      OFF)
33 OPTION(REQUIRE_NEON "Require ARM Neon CPU extensions" OFF)
36 OPTION(ALSA    "Check for ALSA backend"                ON)
37 OPTION(OSS     "Check for OSS backend"                 ON)
38 OPTION(SOLARIS "Check for Solaris backend"             ON)
39 OPTION(SNDIO   "Check for SndIO backend"               ON)
40 OPTION(MMDEVAPI "Check for MMDevApi"                   ON)
41 OPTION(DSOUND  "Check for DirectSound backend"         ON)
42 OPTION(WINMM   "Check for Windows Multimedia backend"  ON)
43 OPTION(PORTAUDIO  "Check for PortAudio backend"        ON)
44 OPTION(PULSEAUDIO "Check for PulseAudio backend"       ON)
45 OPTION(COREAUDIO  "Check for CoreAudio backend"        ON)
46 OPTION(OPENSL     "Check for OpenSL backend"           ON)
47 OPTION(WAVE    "Enable Wave Writer backend"            ON)
49 OPTION(REQUIRE_ALSA       "Require ALSA backend"               OFF)
50 OPTION(REQUIRE_OSS        "Require OSS backend"                OFF)
51 OPTION(REQUIRE_SOLARIS    "Require Solaris backend"            OFF)
52 OPTION(REQUIRE_SNDIO      "Require SndIO backend"              OFF)
53 OPTION(REQUIRE_MMDEVAPI   "Require MMDevApi"                   OFF)
54 OPTION(REQUIRE_DSOUND     "Require DirectSound backend"        OFF)
55 OPTION(REQUIRE_WINMM      "Require Windows Multimedia backend" OFF)
56 OPTION(REQUIRE_PORTAUDIO  "Require PortAudio backend"          OFF)
57 OPTION(REQUIRE_PULSEAUDIO "Require PulseAudio backend"         OFF)
58 OPTION(REQUIRE_COREAUDIO  "Require CoreAudio backend"          OFF)
59 OPTION(REQUIRE_OPENSL     "Require OpenSL backend"             OFF)
61 OPTION(DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
63 OPTION(WERROR  "Treat compile warnings as errors"      OFF)
65 OPTION(UTILS  "Build and install utility programs"  ON)
67 OPTION(EXAMPLES  "Build and install example programs"  ON)
69 OPTION(ALSOFT_CONFIG "Install alsoft.conf configuration file" OFF)
72 IF(WIN32)
73     SET(LIBNAME OpenAL32)
74     ADD_DEFINITIONS("-D_WIN32 -D_WIN32_WINNT=0x0501")
75 ELSE()
76     SET(LIBNAME openal)
77 ENDIF()
79 IF(NOT LIBTYPE)
80     SET(LIBTYPE SHARED)
81 ENDIF()
83 SET(LIB_MAJOR_VERSION "1")
84 SET(LIB_MINOR_VERSION "14")
85 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}")
87 SET(EXPORT_DECL "")
88 SET(ALIGN_DECL "")
91 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
92 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
95 CHECK_C_SOURCE_COMPILES("int *restrict foo;
96                          int main() {return 0;}" HAVE_RESTRICT)
97 CHECK_C_SOURCE_COMPILES("int *__restrict foo;
98                          int main() {return 0;}" HAVE___RESTRICT)
101 # Add definitions, compiler switches, etc.
102 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
104 IF(NOT CMAKE_BUILD_TYPE)
105     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
106         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
107         FORCE)
108 ENDIF()
109 IF(NOT CMAKE_DEBUG_POSTFIX)
110     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
111         "Library postfix for debug builds. Normally left blank."
112         FORCE)
113 ENDIF()
115 IF(MSVC)
116     # ???
117     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
118     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
119     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
120     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
121     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
122     ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
124     IF(NOT DXSDK_DIR)
125         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
126     ELSE()
127         STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
128     ENDIF()
129     IF(DXSDK_DIR)
130         MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
131         SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
132         INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
133         LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
134     ENDIF()
136     OPTION(FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF)
137     IF(FORCE_STATIC_VCRT)
138         FOREACH(flag_var
139                 CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
140                 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
141             IF(${flag_var} MATCHES "/MD")
142                 STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
143             ENDIF()
144         ENDFOREACH(flag_var)
145     ENDIF()
146 ELSE()
147     ADD_DEFINITIONS(-Winline -Wall)
148     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
149     IF(HAVE_W_EXTRA)
150         ADD_DEFINITIONS(-Wextra)
151     ENDIF()
153     IF(WERROR)
154         ADD_DEFINITIONS(-Werror)
155     ENDIF()
157     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -D_DEBUG" CACHE STRING
158         "Flags used by the compiler during Release with Debug Info builds."
159         FORCE)
160     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
161         "Flags used by the compiler during release minsize builds."
162         FORCE)
163     SET(CMAKE_C_FLAGS_RELEASE "-O2 -fomit-frame-pointer -DNDEBUG" CACHE STRING
164         "Flags used by the compiler during release builds"
165         FORCE)
166     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
167         "Flags used by the compiler during debug builds."
168         FORCE)
170     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
171                              int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
172 ENDIF()
174 # Set visibility/export options if available
175 IF(WIN32)
176     SET(EXPORT_DECL "__declspec(dllexport)")
177     SET(ALIGN_DECL "__declspec(align(x))")
179     OPTION(WINE "Enable use of Wine headers when compiling" OFF)
180     IF(WINE)
181         FIND_PATH(WINE_INCLUDE_DIR library.h
182                   PATHS
183                   /usr/include/wine
184                   /usr/local/include/wine
185                   CMAKE_FIND_ROOT_PATH_BOTH)
186         IF(WINE_INCLUDE_DIR)
187             MESSAGE(STATUS "Found Wine header files - ${WINE_INCLUDE_DIR}" )
188             INCLUDE_DIRECTORIES("${WINE_INCLUDE_DIR}/windows")
189             SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${WINE_INCLUDE_DIR}/windows")
190         ELSE()
191             MESSAGE(STATUS "Could not find Wine header files" )
192         ENDIF()
193     ENDIF()
194 ELSE()
195     SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
196     # Yes GCC, really don't accept visibility modes you don't support
197     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Wattributes -Werror")
199     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
200                              int main() {return 0;}" HAVE_GCC_PROTECTED_VISIBILITY)
201     IF(HAVE_GCC_PROTECTED_VISIBILITY)
202         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
203     ELSE()
204         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
205                                  int main() {return 0;}" HAVE_GCC_DEFAULT_VISIBILITY)
206         IF(HAVE_GCC_DEFAULT_VISIBILITY)
207             SET(EXPORT_DECL "__attribute__((visibility(\"default\")))")
208         ENDIF()
209     ENDIF()
211     IF(HAVE_GCC_PROTECTED_VISIBILITY OR HAVE_GCC_DEFAULT_VISIBILITY)
212         CHECK_C_COMPILER_FLAG(-fvisibility=internal HAVE_VISIBILITY_INTERNAL_SWITCH)
213         IF(HAVE_VISIBILITY_INTERNAL_SWITCH)
214             ADD_DEFINITIONS(-fvisibility=internal)
215         ELSE()
216             CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN_SWITCH)
217             IF(HAVE_VISIBILITY_HIDDEN_SWITCH)
218                 ADD_DEFINITIONS(-fvisibility=hidden)
219             ENDIF()
220         ENDIF()
221     ENDIF()
223     CHECK_C_SOURCE_COMPILES("int foo __attribute__((aligned(16)));
224                              int main() {return 0;}" HAVE_ATTRIBUTE_ALIGNED)
225     IF(HAVE_ATTRIBUTE_ALIGNED)
226         SET(ALIGN_DECL "__attribute__((aligned(x)))")
227     ENDIF()
229     SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}")
230 ENDIF()
232 SET(SSE_SWITCH "")
233 CHECK_C_COMPILER_FLAG(-msse HAVE_MSSE_SWITCH)
234 IF(HAVE_MSSE_SWITCH)
235     SET(SSE_SWITCH "-msse")
236 ENDIF()
238 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
239                          int main() {return 0;}" HAVE_GCC_FORMAT)
241 CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
242 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
243 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
244 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
245 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
246 IF(NOT HAVE_GUIDDEF_H)
247     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
248 ENDIF()
250 # Some systems need libm for some of the following math functions to work
251 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
252 IF(HAVE_LIBM)
253     SET(EXTRA_LIBS m ${EXTRA_LIBS})
254     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
255 ENDIF()
258 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
259 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
260 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
261 CHECK_SYMBOL_EXISTS(powf   math.h HAVE_POWF)
262 CHECK_SYMBOL_EXISTS(powf   math.h HAVE_POWF)
263 CHECK_SYMBOL_EXISTS(sqrtf  math.h HAVE_SQRTF)
264 CHECK_SYMBOL_EXISTS(cosf   math.h HAVE_COSF)
265 CHECK_SYMBOL_EXISTS(sinf   math.h HAVE_SINF)
266 CHECK_SYMBOL_EXISTS(acosf  math.h HAVE_ACOSF)
267 CHECK_SYMBOL_EXISTS(asinf  math.h HAVE_ASINF)
268 CHECK_SYMBOL_EXISTS(atanf  math.h HAVE_ATANF)
269 CHECK_SYMBOL_EXISTS(atan2f math.h HAVE_ATAN2F)
270 CHECK_SYMBOL_EXISTS(fabsf  math.h HAVE_FABSF)
271 CHECK_SYMBOL_EXISTS(log10f math.h HAVE_LOG10F)
272 CHECK_SYMBOL_EXISTS(floorf math.h HAVE_FLOORF)
274 IF(HAVE_FENV_H)
275     CHECK_SYMBOL_EXISTS(fesetround fenv.h HAVE_FESETROUND)
276 ENDIF()
277 IF(HAVE_FLOAT_H)
278     CHECK_SYMBOL_EXISTS(_controlfp float.h HAVE__CONTROLFP)
279     CHECK_SYMBOL_EXISTS(__control87_2 float.h HAVE___CONTROL87_2)
280 ENDIF()
282 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
283 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
284 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
285 IF(NOT HAVE_STRCASECMP)
286     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
287     IF(NOT HAVE__STRICMP)
288         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
289     ENDIF()
291     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
292 ENDIF()
294 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
295 IF(NOT HAVE_STRNCASECMP)
296     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
297     IF(NOT HAVE__STRNICMP)
298         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
299     ENDIF()
301     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
302 ENDIF()
304 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
305 IF(NOT HAVE_SNPRINTF)
306     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
307     IF(NOT HAVE__SNPRINTF)
308         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
309     ENDIF()
311     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
312 ENDIF()
314 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
315 IF(NOT HAVE_VSNPRINTF)
316     CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
317     IF(NOT HAVE__VSNPRINTF)
318         MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
319     ENDIF()
321     ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
322 ENDIF()
324 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
325 IF(NOT HAVE_ISFINITE)
326     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
327     IF(NOT HAVE_FINITE)
328         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
329         IF(NOT HAVE__FINITE)
330             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
331         ENDIF()
332         ADD_DEFINITIONS(-Disfinite=_finite)
333     ELSE()
334         ADD_DEFINITIONS(-Disfinite=finite)
335     ENDIF()
336 ENDIF()
338 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
339 IF(NOT HAVE_ISNAN)
340     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
341     IF(NOT HAVE__ISNAN)
342         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
343     ENDIF()
345     ADD_DEFINITIONS(-Disnan=_isnan)
346 ENDIF()
349 # Check for the dlopen API (for dynamicly loading backend libs)
350 IF(DLOPEN)
351     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
352     IF(HAVE_DLFCN_H)
353         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
354         IF(HAVE_LIBDL)
355             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
356         ENDIF()
357     ENDIF()
358 ENDIF()
360 # Check if we have Windows headers
361 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0501)
362 IF(NOT HAVE_WINDOWS_H)
363     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
364     IF(NOT HAVE_GETTIMEOFDAY)
365         MESSAGE(FATAL_ERROR "No timing function found!")
366     ENDIF()
368     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
369     IF(NOT HAVE_NANOSLEEP)
370         MESSAGE(FATAL_ERROR "No sleep function found!")
371     ENDIF()
373     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
374     IF(HAVE_PTHREAD)
375         ADD_DEFINITIONS(-pthread)
376         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
377     ENDIF()
379     # We need pthreads outside of Windows
380     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
381     IF(NOT HAVE_PTHREAD_H)
382         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
383     ENDIF()
384     # Some systems need pthread_np.h to get recursive mutexes
385     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
387     # _GNU_SOURCE is needed on some systems for extra attributes
388     ADD_DEFINITIONS(-D_GNU_SOURCE=1)
389     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
390     IF(HAVE_LIBPTHREAD)
391         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
392     ENDIF()
394     CHECK_LIBRARY_EXISTS(pthread pthread_setschedparam "" HAVE_PTHREAD_SETSCHEDPARAM)
396     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
397     IF(HAVE_LIBRT)
398         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
399     ENDIF()
400 ENDIF()
402 # Check for a 64-bit type
403 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
404 IF(NOT HAVE_STDINT_H)
405     IF(HAVE_WINDOWS_H)
406         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0501
407                                  \#include <windows.h>
408                                  __int64 foo;
409                                  int main() {return 0;}" HAVE___INT64)
410     ENDIF()
411     IF(NOT HAVE___INT64)
412         IF(NOT SIZEOF_LONG MATCHES "8")
413             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
414                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
415             ENDIF()
416         ENDIF()
417     ENDIF()
418 ENDIF()
420 # Windows needs winmm for timeGetTime, even if the backend is disabled
421 CHECK_SHARED_FUNCTION_EXISTS(timeGetTime "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
422 IF(HAVE_LIBWINMM)
423     SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
424     SET(PKG_CONFIG_LIBS ${PKG_CONFIG_LIBS} -lwinmm)
425 ENDIF()
428 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
429                  OpenAL32/alBuffer.c
430                  OpenAL32/alEffect.c
431                  OpenAL32/alError.c
432                  OpenAL32/alExtension.c
433                  OpenAL32/alFilter.c
434                  OpenAL32/alListener.c
435                  OpenAL32/alSource.c
436                  OpenAL32/alState.c
437                  OpenAL32/alThunk.c
439 SET(ALC_OBJS  Alc/ALc.c
440               Alc/ALu.c
441               Alc/alcConfig.c
442               Alc/alcDedicated.c
443               Alc/alcEcho.c
444               Alc/alcModulator.c
445               Alc/alcReverb.c
446               Alc/alcRing.c
447               Alc/alcThread.c
448               Alc/bs2b.c
449               Alc/helpers.c
450               Alc/panning.c
451               Alc/hrtf.c
452               Alc/mixer.c
453               Alc/mixer_c.c
457 SET(CPU_EXTS "Default")
458 SET(HAVE_SSE  0)
459 SET(HAVE_NEON 0)
461 # Check for SSE support
462 IF(SSE)
463     CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
464     IF(HAVE_XMMINTRIN_H)
465         SET(HAVE_SSE 1)
466         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
467         IF(SSE_SWITCH)
468             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
469                                         COMPILE_FLAGS "${SSE_SWITCH}")
470         ENDIF()
471         SET(CPU_EXTS "${CPU_EXTS}, SSE")
472     ENDIF()
473 ENDIF()
474 IF(REQUIRE_SSE AND NOT HAVE_SSE)
475     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
476 ENDIF()
478 # Check for ARM Neon support
479 IF(NEON)
480     CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
481     IF(HAVE_ARM_NEON_H)
482         SET(HAVE_NEON 1)
483         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
484         SET(CPU_EXTS "${CPU_EXTS}, Neon")
485     ENDIF()
486 ENDIF()
487 IF(REQUIRE_NEON AND NOT HAVE_NEON)
488     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
489 ENDIF()
492 SET(ALC_OBJS  ${ALC_OBJS}
493               # Default backends, always available
494               Alc/backends/loopback.c
495               Alc/backends/null.c
498 SET(BACKENDS "")
499 SET(HAVE_ALSA       0)
500 SET(HAVE_OSS        0)
501 SET(HAVE_SOLARIS    0)
502 SET(HAVE_SNDIO      0)
503 SET(HAVE_DSOUND     0)
504 SET(HAVE_MMDEVAPI   0)
505 SET(HAVE_WINMM      0)
506 SET(HAVE_PORTAUDIO  0)
507 SET(HAVE_PULSEAUDIO 0)
508 SET(HAVE_COREAUDIO  0)
509 SET(HAVE_OPENSL     0)
510 SET(HAVE_WAVE       0)
512 # Check ALSA backend
513 IF(ALSA)
514     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
515     IF(HAVE_ALSA_ASOUNDLIB_H)
516         CHECK_SHARED_FUNCTION_EXISTS(snd_pcm_open "alsa/asoundlib.h" asound "" HAVE_LIBASOUND)
517         IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
518             SET(HAVE_ALSA 1)
519             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
520             IF(HAVE_DLFCN_H OR WIN32)
521                 SET(BACKENDS  "${BACKENDS} ALSA,")
522             ELSE()
523                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
524                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
525             ENDIF()
526         ENDIF()
527     ENDIF()
528 ENDIF()
529 IF(REQUIRE_ALSA AND NOT HAVE_ALSA)
530     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
531 ENDIF()
533 # Check OSS backend
534 IF(OSS)
535     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
536     IF(HAVE_SYS_SOUNDCARD_H)
537         SET(HAVE_OSS 1)
538         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
539         SET(BACKENDS  "${BACKENDS} OSS,")
540     ENDIF()
541 ENDIF()
542 IF(REQUIRE_OSS AND NOT HAVE_OSS)
543     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
544 ENDIF()
546 # Check Solaris backend
547 IF(SOLARIS)
548     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
549     IF(HAVE_SYS_AUDIOIO_H)
550         SET(HAVE_SOLARIS 1)
551         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
552         SET(BACKENDS  "${BACKENDS} Solaris,")
553     ENDIF()
554 ENDIF()
555 IF(REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
556     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
557 ENDIF()
559 # Check SndIO backend
560 IF(SNDIO)
561     CHECK_INCLUDE_FILE(sndio.h HAVE_SNDIO_H)
562     IF(HAVE_SNDIO_H)
563         CHECK_SHARED_FUNCTION_EXISTS(sio_open "sndio.h" sndio "" HAVE_LIBSNDIO)
564         IF(HAVE_LIBSNDIO)
565             SET(HAVE_SNDIO 1)
566             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
567             SET(BACKENDS  "${BACKENDS} SndIO \(linked\),")
568             SET(EXTRA_LIBS sndio ${EXTRA_LIBS})
569         ENDIF()
570     ENDIF()
571 ENDIF()
572 IF(REQUIRE_SNDIO AND NOT HAVE_SNDIO)
573     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
574 ENDIF()
576 # Check for MMDevApi backend
577 IF(HAVE_WINDOWS_H)
578     IF(MMDEVAPI)
579         CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
580         IF(HAVE_MMDEVICEAPI_H)
581             SET(HAVE_MMDEVAPI 1)
582             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
584             SET(BACKENDS  "${BACKENDS} MMDevApi,")
585         ENDIF()
586     ENDIF()
587 ENDIF()
588 IF(REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
589     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
590 ENDIF()
592 # Check DSound/MMSystem backend
593 IF(DSOUND)
594     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
595     IF(HAVE_DSOUND_H)
596         CHECK_SHARED_FUNCTION_EXISTS(DirectSoundCreate "dsound.h" dsound "" HAVE_LIBDSOUND)
597         IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
598             SET(HAVE_DSOUND 1)
599             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
601             IF(HAVE_DLFCN_H OR WIN32)
602                 SET(BACKENDS  "${BACKENDS} DirectSound,")
603             ELSE()
604                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
605                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
606             ENDIF()
607         ENDIF()
608     ENDIF()
609 ENDIF()
610 IF(REQUIRE_DSOUND AND NOT HAVE_DSOUND)
611     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
612 ENDIF()
614 IF(HAVE_WINDOWS_H)
615     IF(WINMM)
616         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0501)
617         IF(HAVE_MMSYSTEM_H AND HAVE_LIBWINMM)
618             SET(HAVE_WINMM 1)
619             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
620             SET(BACKENDS  "${BACKENDS} WinMM,")
621         ENDIF()
622     ENDIF()
623 ENDIF()
624 IF(REQUIRE_WINMM AND NOT HAVE_WINMM)
625     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
626 ENDIF()
628 # Check PortAudio backend
629 IF(PORTAUDIO)
630     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
631     IF(HAVE_PORTAUDIO_H)
632         CHECK_SHARED_FUNCTION_EXISTS(Pa_Initialize "portaudio.h" portaudio "" HAVE_LIBPORTAUDIO)
633         IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
634             SET(HAVE_PORTAUDIO 1)
635             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
636             IF(HAVE_DLFCN_H OR WIN32)
637                 SET(BACKENDS  "${BACKENDS} PortAudio,")
638             ELSE()
639                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
640                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
641             ENDIF()
642         ENDIF()
643     ENDIF()
644 ENDIF()
645 IF(REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
646     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
647 ENDIF()
649 # Check PulseAudio backend
650 IF(PULSEAUDIO)
651     CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
652     IF(HAVE_PULSE_PULSEAUDIO_H)
653         CHECK_SHARED_FUNCTION_EXISTS(pa_context_new "pulse/pulseaudio.h" pulse "" HAVE_LIBPULSE)
654         IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
655             SET(HAVE_PULSEAUDIO 1)
656             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
657             IF(HAVE_DLFCN_H OR WIN32)
658                 SET(BACKENDS  "${BACKENDS} PulseAudio,")
659             ELSE()
660                 SET(BACKENDS  "${BACKENDS} PulseAudio \(linked\),")
661                 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
662             ENDIF()
663         ENDIF()
664     ENDIF()
665 ENDIF()
666 IF(REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
667     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
668 ENDIF()
670 # Check CoreAudio backend
671 IF(COREAUDIO)
672     CHECK_INCLUDE_FILE(/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h HAVE_COREAUDIO_FRAMEWORK)
673     IF(HAVE_COREAUDIO_FRAMEWORK)
674         SET(HAVE_COREAUDIO 1)
675         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
676         SET(BACKENDS  "${BACKENDS} CoreAudio,")
677         SET(EXTRA_LIBS /System/Library/Frameworks/CoreAudio.framework ${EXTRA_LIBS})
678         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
679         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
681         # Some versions of OSX may need the AudioToolbox framework. Add it if
682         # it's found.
683         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
684                      NAMES AudioToolbox
685                      PATHS ~/Library/Frameworks
686                            /Library/Frameworks
687                            /System/Library/Frameworks
688                     )
689         IF(AUDIOTOOLBOX_LIBRARY)
690             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
691         ENDIF()
692     ENDIF()
693 ENDIF()
694 IF(REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
695     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
696 ENDIF()
698 # Check for OpenSL (Android) backend
699 IF(OPENSL)
700     CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
701     IF(HAVE_SLES_OPENSLES_ANDROID_H)
702         CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
703         IF(HAVE_LIBOPENSLES)
704             SET(HAVE_OPENSL 1)
705             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
706             SET(BACKENDS  "${BACKENDS} OpenSL,")
707             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
708         ENDIF()
709     ENDIF()
710 ENDIF()
711 IF(REQUIRE_OPENSL AND NOT HAVE_OPENSL)
712     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
713 ENDIF()
715 # Optionally enable the Wave Writer backend
716 IF(WAVE)
717     SET(HAVE_WAVE 1)
718     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
719     SET(BACKENDS  "${BACKENDS} WaveFile,")
720 ENDIF()
722 # This is always available
723 SET(BACKENDS  "${BACKENDS} Null")
725 IF(EXAMPLES)
726     # Might be able to use earlier versions, but these definitely work
727     PKG_CHECK_MODULES(FFMPEG libavcodec>=52.123.0 libavformat>=52.111.0 libavutil>=51.9.1)
728 ENDIF()
730 IF(LIBTYPE STREQUAL "STATIC")
731     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
732     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
733 ENDIF()
735 # Needed for openal.pc.in
736 SET(prefix ${CMAKE_INSTALL_PREFIX})
737 SET(exec_prefix "\${prefix}")
738 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
739 SET(bindir "\${exec_prefix}/bin")
740 SET(includedir "\${prefix}/include")
741 SET(PACKAGE_VERSION "${LIB_VERSION}")
743 # End configuration
744 CONFIGURE_FILE(
745     "${OpenAL_SOURCE_DIR}/config.h.in"
746     "${OpenAL_BINARY_DIR}/config.h")
747 CONFIGURE_FILE(
748     "${OpenAL_SOURCE_DIR}/openal.pc.in"
749     "${OpenAL_BINARY_DIR}/openal.pc"
750     @ONLY)
752 # Build a library
753 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
754 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
755                                             COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
756                                             VERSION ${LIB_VERSION}.0
757                                             SOVERSION ${LIB_MAJOR_VERSION})
758 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
759     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
760 ENDIF()
762 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
764 # Add an install target here
765 INSTALL(TARGETS ${LIBNAME}
766         RUNTIME DESTINATION bin
767         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
768         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
770 INSTALL(FILES include/AL/al.h
771               include/AL/alc.h
772               include/AL/alext.h
773               include/AL/efx.h
774               include/AL/efx-creative.h
775               include/AL/efx-presets.h
776         DESTINATION include/AL
778 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
779         DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
782 MESSAGE(STATUS "")
783 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
784 MESSAGE(STATUS "    ${BACKENDS}")
785 MESSAGE(STATUS "")
786 MESSAGE(STATUS "Building with support for CPU extensions:")
787 MESSAGE(STATUS "    ${CPU_EXTS}")
788 MESSAGE(STATUS "")
790 IF(WIN32)
791     IF(NOT HAVE_DSOUND)
792         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
793         MESSAGE(STATUS "         This is probably NOT what you want!")
794         MESSAGE(STATUS "")
795     ENDIF()
796 ENDIF()
798 # Install alsoft.conf configuration file
799 IF(ALSOFT_CONFIG)
800     INSTALL(FILES alsoftrc.sample
801             DESTINATION /etc/openal
802             RENAME alsoft.conf
803     )
804     MESSAGE(STATUS "Installing sample alsoft.conf")
805     MESSAGE(STATUS "")
806 ENDIF()
808 IF(UTILS)
809     ADD_EXECUTABLE(openal-info utils/openal-info.c)
810     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
812     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
813     IF(HAVE_LIBM)
814         TARGET_LINK_LIBRARIES(makehrtf m)
815     ENDIF()
817     INSTALL(TARGETS openal-info makehrtf
818             RUNTIME DESTINATION bin
819             LIBRARY DESTINATION "lib${LIB_SUFFIX}"
820             ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
821     )
822     MESSAGE(STATUS "Building utility programs")
823     MESSAGE(STATUS "")
824 ENDIF()
826 IF(EXAMPLES)
827     IF(FFMPEG_FOUND)
828         ADD_EXECUTABLE(alstream examples/alhelpers.c examples/alffmpeg.c examples/alstream.c)
829         TARGET_LINK_LIBRARIES(alstream ${FFMPEG_LIBRARIES} ${LIBNAME})
830         SET_TARGET_PROPERTIES(alstream PROPERTIES COMPILE_FLAGS "${FFMPEG_CFLAGS}")
831         INSTALL(TARGETS alstream
832                 RUNTIME DESTINATION bin
833                 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
834                 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
835         )
837         MESSAGE(STATUS "Building ffmpeg example programs")
838         MESSAGE(STATUS "")
839     ENDIF()
840 ENDIF()