Place the alignment attribute before the variable declaration
[openal-soft.git] / CMakeLists.txt
blob5f08d736bcc94875121a702d247a0a0e48dbf196
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(fpu_control.h HAVE_FPU_CONTROL_H)
244 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
245 CHECK_INCLUDE_FILE(ieeefp.h HAVE_IEEEFP_H)
246 CHECK_INCLUDE_FILE(guiddef.h HAVE_GUIDDEF_H)
247 IF(NOT HAVE_GUIDDEF_H)
248     CHECK_INCLUDE_FILE(initguid.h HAVE_INITGUID_H)
249 ENDIF()
251 # Some systems need libm for some of the following math functions to work
252 CHECK_LIBRARY_EXISTS(m pow "" HAVE_LIBM)
253 IF(HAVE_LIBM)
254     SET(EXTRA_LIBS m ${EXTRA_LIBS})
255     SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} m)
256 ENDIF()
259 CHECK_SYMBOL_EXISTS(aligned_alloc    stdlib.h HAVE_ALIGNED_ALLOC)
260 CHECK_SYMBOL_EXISTS(posix_memalign   stdlib.h HAVE_POSIX_MEMALIGN)
261 CHECK_SYMBOL_EXISTS(_aligned_malloc  malloc.h HAVE__ALIGNED_MALLOC)
262 CHECK_SYMBOL_EXISTS(powf   math.h HAVE_POWF)
263 CHECK_SYMBOL_EXISTS(powf   math.h HAVE_POWF)
264 CHECK_SYMBOL_EXISTS(sqrtf  math.h HAVE_SQRTF)
265 CHECK_SYMBOL_EXISTS(cosf   math.h HAVE_COSF)
266 CHECK_SYMBOL_EXISTS(sinf   math.h HAVE_SINF)
267 CHECK_SYMBOL_EXISTS(acosf  math.h HAVE_ACOSF)
268 CHECK_SYMBOL_EXISTS(asinf  math.h HAVE_ASINF)
269 CHECK_SYMBOL_EXISTS(atanf  math.h HAVE_ATANF)
270 CHECK_SYMBOL_EXISTS(atan2f math.h HAVE_ATAN2F)
271 CHECK_SYMBOL_EXISTS(fabsf  math.h HAVE_FABSF)
272 CHECK_SYMBOL_EXISTS(log10f math.h HAVE_LOG10F)
273 CHECK_SYMBOL_EXISTS(floorf math.h HAVE_FLOORF)
275 IF(HAVE_FENV_H)
276     CHECK_SYMBOL_EXISTS(fesetround fenv.h HAVE_FESETROUND)
277 ENDIF()
279 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
280 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
282 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
283 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
284 IF(NOT HAVE_STRCASECMP)
285     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
286     IF(NOT HAVE__STRICMP)
287         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
288     ENDIF()
290     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
291 ENDIF()
293 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
294 IF(NOT HAVE_STRNCASECMP)
295     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
296     IF(NOT HAVE__STRNICMP)
297         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
298     ENDIF()
300     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
301 ENDIF()
303 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
304 IF(NOT HAVE_SNPRINTF)
305     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
306     IF(NOT HAVE__SNPRINTF)
307         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
308     ENDIF()
310     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
311 ENDIF()
313 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
314 IF(NOT HAVE_VSNPRINTF)
315     CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
316     IF(NOT HAVE__VSNPRINTF)
317         MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
318     ENDIF()
320     ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
321 ENDIF()
323 CHECK_SYMBOL_EXISTS(isfinite math.h HAVE_ISFINITE)
324 IF(NOT HAVE_ISFINITE)
325     CHECK_FUNCTION_EXISTS(finite HAVE_FINITE)
326     IF(NOT HAVE_FINITE)
327         CHECK_FUNCTION_EXISTS(_finite HAVE__FINITE)
328         IF(NOT HAVE__FINITE)
329             MESSAGE(FATAL_ERROR "No isfinite function found, please report!")
330         ENDIF()
331         ADD_DEFINITIONS(-Disfinite=_finite)
332     ELSE()
333         ADD_DEFINITIONS(-Disfinite=finite)
334     ENDIF()
335 ENDIF()
337 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
338 IF(NOT HAVE_ISNAN)
339     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
340     IF(NOT HAVE__ISNAN)
341         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
342     ENDIF()
344     ADD_DEFINITIONS(-Disnan=_isnan)
345 ENDIF()
348 # Check for the dlopen API (for dynamicly loading backend libs)
349 IF(DLOPEN)
350     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
351     IF(HAVE_DLFCN_H)
352         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
353         IF(HAVE_LIBDL)
354             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
355         ENDIF()
356     ENDIF()
357 ENDIF()
359 # Check if we have Windows headers
360 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0501)
361 IF(NOT HAVE_WINDOWS_H)
362     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
363     IF(NOT HAVE_GETTIMEOFDAY)
364         MESSAGE(FATAL_ERROR "No timing function found!")
365     ENDIF()
367     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
368     IF(NOT HAVE_NANOSLEEP)
369         MESSAGE(FATAL_ERROR "No sleep function found!")
370     ENDIF()
372     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
373     IF(HAVE_PTHREAD)
374         ADD_DEFINITIONS(-pthread)
375         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
376     ENDIF()
378     # We need pthreads outside of Windows
379     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
380     IF(NOT HAVE_PTHREAD_H)
381         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
382     ENDIF()
383     # Some systems need pthread_np.h to get recursive mutexes
384     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
386     # _GNU_SOURCE is needed on some systems for extra attributes
387     ADD_DEFINITIONS(-D_GNU_SOURCE=1)
388     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
389     IF(HAVE_LIBPTHREAD)
390         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
391     ENDIF()
393     CHECK_LIBRARY_EXISTS(pthread pthread_setschedparam "" HAVE_PTHREAD_SETSCHEDPARAM)
395     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
396     IF(HAVE_LIBRT)
397         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
398     ENDIF()
399 ENDIF()
401 # Check for a 64-bit type
402 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
403 IF(NOT HAVE_STDINT_H)
404     IF(HAVE_WINDOWS_H)
405         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0501
406                                  \#include <windows.h>
407                                  __int64 foo;
408                                  int main() {return 0;}" HAVE___INT64)
409     ENDIF()
410     IF(NOT HAVE___INT64)
411         IF(NOT SIZEOF_LONG MATCHES "8")
412             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
413                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
414             ENDIF()
415         ENDIF()
416     ENDIF()
417 ENDIF()
419 # Windows needs winmm for timeGetTime, even if the backend is disabled
420 CHECK_SHARED_FUNCTION_EXISTS(timeGetTime "windows.h;mmsystem.h" winmm "" HAVE_LIBWINMM)
421 IF(HAVE_LIBWINMM)
422     SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
423     SET(PKG_CONFIG_LIBS ${PKG_CONFIG_LIBS} -lwinmm)
424 ENDIF()
427 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
428                  OpenAL32/alBuffer.c
429                  OpenAL32/alEffect.c
430                  OpenAL32/alError.c
431                  OpenAL32/alExtension.c
432                  OpenAL32/alFilter.c
433                  OpenAL32/alListener.c
434                  OpenAL32/alSource.c
435                  OpenAL32/alState.c
436                  OpenAL32/alThunk.c
438 SET(ALC_OBJS  Alc/ALc.c
439               Alc/ALu.c
440               Alc/alcConfig.c
441               Alc/alcDedicated.c
442               Alc/alcEcho.c
443               Alc/alcModulator.c
444               Alc/alcReverb.c
445               Alc/alcRing.c
446               Alc/alcThread.c
447               Alc/bs2b.c
448               Alc/helpers.c
449               Alc/panning.c
450               Alc/hrtf.c
451               Alc/mixer.c
452               Alc/mixer_c.c
456 SET(CPU_EXTS "Default")
457 SET(HAVE_SSE  0)
458 SET(HAVE_NEON 0)
460 # Check for SSE support
461 IF(SSE)
462     CHECK_INCLUDE_FILE(xmmintrin.h HAVE_XMMINTRIN_H "${SSE_SWITCH}")
463     IF(HAVE_XMMINTRIN_H)
464         SET(HAVE_SSE 1)
465         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_sse.c)
466         IF(SSE_SWITCH)
467             SET_SOURCE_FILES_PROPERTIES(Alc/mixer_sse.c PROPERTIES
468                                         COMPILE_FLAGS "${SSE_SWITCH}")
469         ENDIF()
470         SET(CPU_EXTS "${CPU_EXTS}, SSE")
471     ENDIF()
472 ENDIF()
473 IF(REQUIRE_SSE AND NOT HAVE_SSE)
474     MESSAGE(FATAL_ERROR "Failed to enabled required SSE CPU extensions")
475 ENDIF()
477 # Check for ARM Neon support
478 IF(NEON)
479     CHECK_INCLUDE_FILE(arm_neon.h HAVE_ARM_NEON_H)
480     IF(HAVE_ARM_NEON_H)
481         SET(HAVE_NEON 1)
482         SET(ALC_OBJS  ${ALC_OBJS} Alc/mixer_neon.c)
483         SET(CPU_EXTS "${CPU_EXTS}, Neon")
484     ENDIF()
485 ENDIF()
486 IF(REQUIRE_NEON AND NOT HAVE_NEON)
487     MESSAGE(FATAL_ERROR "Failed to enabled required ARM Neon CPU extensions")
488 ENDIF()
491 SET(ALC_OBJS  ${ALC_OBJS}
492               # Default backends, always available
493               Alc/backends/loopback.c
494               Alc/backends/null.c
497 SET(BACKENDS "")
498 SET(HAVE_ALSA       0)
499 SET(HAVE_OSS        0)
500 SET(HAVE_SOLARIS    0)
501 SET(HAVE_SNDIO      0)
502 SET(HAVE_DSOUND     0)
503 SET(HAVE_MMDEVAPI   0)
504 SET(HAVE_WINMM      0)
505 SET(HAVE_PORTAUDIO  0)
506 SET(HAVE_PULSEAUDIO 0)
507 SET(HAVE_COREAUDIO  0)
508 SET(HAVE_OPENSL     0)
509 SET(HAVE_WAVE       0)
511 # Check ALSA backend
512 IF(ALSA)
513     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
514     IF(HAVE_ALSA_ASOUNDLIB_H)
515         CHECK_SHARED_FUNCTION_EXISTS(snd_pcm_open "alsa/asoundlib.h" asound "" HAVE_LIBASOUND)
516         IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
517             SET(HAVE_ALSA 1)
518             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/alsa.c)
519             IF(HAVE_DLFCN_H OR WIN32)
520                 SET(BACKENDS  "${BACKENDS} ALSA,")
521             ELSE()
522                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
523                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
524             ENDIF()
525         ENDIF()
526     ENDIF()
527 ENDIF()
528 IF(REQUIRE_ALSA AND NOT HAVE_ALSA)
529     MESSAGE(FATAL_ERROR "Failed to enabled required ALSA backend")
530 ENDIF()
532 # Check OSS backend
533 IF(OSS)
534     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
535     IF(HAVE_SYS_SOUNDCARD_H)
536         SET(HAVE_OSS 1)
537         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/oss.c)
538         SET(BACKENDS  "${BACKENDS} OSS,")
539     ENDIF()
540 ENDIF()
541 IF(REQUIRE_OSS AND NOT HAVE_OSS)
542     MESSAGE(FATAL_ERROR "Failed to enabled required OSS backend")
543 ENDIF()
545 # Check Solaris backend
546 IF(SOLARIS)
547     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
548     IF(HAVE_SYS_AUDIOIO_H)
549         SET(HAVE_SOLARIS 1)
550         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/solaris.c)
551         SET(BACKENDS  "${BACKENDS} Solaris,")
552     ENDIF()
553 ENDIF()
554 IF(REQUIRE_SOLARIS AND NOT HAVE_SOLARIS)
555     MESSAGE(FATAL_ERROR "Failed to enabled required Solaris backend")
556 ENDIF()
558 # Check SndIO backend
559 IF(SNDIO)
560     CHECK_INCLUDE_FILE(sndio.h HAVE_SNDIO_H)
561     IF(HAVE_SNDIO_H)
562         CHECK_SHARED_FUNCTION_EXISTS(sio_open "sndio.h" sndio "" HAVE_LIBSNDIO)
563         IF(HAVE_LIBSNDIO)
564             SET(HAVE_SNDIO 1)
565             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/sndio.c)
566             SET(BACKENDS  "${BACKENDS} SndIO \(linked\),")
567             SET(EXTRA_LIBS sndio ${EXTRA_LIBS})
568         ENDIF()
569     ENDIF()
570 ENDIF()
571 IF(REQUIRE_SNDIO AND NOT HAVE_SNDIO)
572     MESSAGE(FATAL_ERROR "Failed to enabled required SndIO backend")
573 ENDIF()
575 # Check for MMDevApi backend
576 IF(HAVE_WINDOWS_H)
577     IF(MMDEVAPI)
578         CHECK_INCLUDE_FILE(mmdeviceapi.h HAVE_MMDEVICEAPI_H)
579         IF(HAVE_MMDEVICEAPI_H)
580             SET(HAVE_MMDEVAPI 1)
581             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/mmdevapi.c)
583             SET(BACKENDS  "${BACKENDS} MMDevApi,")
584         ENDIF()
585     ENDIF()
586 ENDIF()
587 IF(REQUIRE_MMDEVAPI AND NOT HAVE_MMDEVAPI)
588     MESSAGE(FATAL_ERROR "Failed to enabled required MMDevApi backend")
589 ENDIF()
591 # Check DSound/MMSystem backend
592 IF(DSOUND)
593     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
594     IF(HAVE_DSOUND_H)
595         CHECK_SHARED_FUNCTION_EXISTS(DirectSoundCreate "dsound.h" dsound "" HAVE_LIBDSOUND)
596         IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
597             SET(HAVE_DSOUND 1)
598             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/dsound.c)
600             IF(HAVE_DLFCN_H OR WIN32)
601                 SET(BACKENDS  "${BACKENDS} DirectSound,")
602             ELSE()
603                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
604                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
605             ENDIF()
606         ENDIF()
607     ENDIF()
608 ENDIF()
609 IF(REQUIRE_DSOUND AND NOT HAVE_DSOUND)
610     MESSAGE(FATAL_ERROR "Failed to enabled required DSound backend")
611 ENDIF()
613 IF(HAVE_WINDOWS_H)
614     IF(WINMM)
615         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0501)
616         IF(HAVE_MMSYSTEM_H AND HAVE_LIBWINMM)
617             SET(HAVE_WINMM 1)
618             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/winmm.c)
619             SET(BACKENDS  "${BACKENDS} WinMM,")
620         ENDIF()
621     ENDIF()
622 ENDIF()
623 IF(REQUIRE_WINMM AND NOT HAVE_WINMM)
624     MESSAGE(FATAL_ERROR "Failed to enabled required WinMM backend")
625 ENDIF()
627 # Check PortAudio backend
628 IF(PORTAUDIO)
629     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
630     IF(HAVE_PORTAUDIO_H)
631         CHECK_SHARED_FUNCTION_EXISTS(Pa_Initialize "portaudio.h" portaudio "" HAVE_LIBPORTAUDIO)
632         IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
633             SET(HAVE_PORTAUDIO 1)
634             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/portaudio.c)
635             IF(HAVE_DLFCN_H OR WIN32)
636                 SET(BACKENDS  "${BACKENDS} PortAudio,")
637             ELSE()
638                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
639                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
640             ENDIF()
641         ENDIF()
642     ENDIF()
643 ENDIF()
644 IF(REQUIRE_PORTAUDIO AND NOT HAVE_PORTAUDIO)
645     MESSAGE(FATAL_ERROR "Failed to enabled required PortAudio backend")
646 ENDIF()
648 # Check PulseAudio backend
649 IF(PULSEAUDIO)
650     CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
651     IF(HAVE_PULSE_PULSEAUDIO_H)
652         CHECK_SHARED_FUNCTION_EXISTS(pa_context_new "pulse/pulseaudio.h" pulse "" HAVE_LIBPULSE)
653         IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
654             SET(HAVE_PULSEAUDIO 1)
655             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/pulseaudio.c)
656             IF(HAVE_DLFCN_H OR WIN32)
657                 SET(BACKENDS  "${BACKENDS} PulseAudio,")
658             ELSE()
659                 SET(BACKENDS  "${BACKENDS} PulseAudio \(linked\),")
660                 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
661             ENDIF()
662         ENDIF()
663     ENDIF()
664 ENDIF()
665 IF(REQUIRE_PULSEAUDIO AND NOT HAVE_PULSEAUDIO)
666     MESSAGE(FATAL_ERROR "Failed to enabled required PulseAudio backend")
667 ENDIF()
669 # Check CoreAudio backend
670 IF(COREAUDIO)
671     CHECK_INCLUDE_FILE(/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h HAVE_COREAUDIO_FRAMEWORK)
672     IF(HAVE_COREAUDIO_FRAMEWORK)
673         SET(HAVE_COREAUDIO 1)
674         SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/coreaudio.c)
675         SET(BACKENDS  "${BACKENDS} CoreAudio,")
676         SET(EXTRA_LIBS /System/Library/Frameworks/CoreAudio.framework ${EXTRA_LIBS})
677         SET(EXTRA_LIBS /System/Library/Frameworks/AudioUnit.framework ${EXTRA_LIBS})
678         SET(EXTRA_LIBS /System/Library/Frameworks/ApplicationServices.framework ${EXTRA_LIBS})
680         # Some versions of OSX may need the AudioToolbox framework. Add it if
681         # it's found.
682         FIND_LIBRARY(AUDIOTOOLBOX_LIBRARY
683                      NAMES AudioToolbox
684                      PATHS ~/Library/Frameworks
685                            /Library/Frameworks
686                            /System/Library/Frameworks
687                     )
688         IF(AUDIOTOOLBOX_LIBRARY)
689             SET(EXTRA_LIBS ${AUDIOTOOLBOX_LIBRARY} ${EXTRA_LIBS})
690         ENDIF()
691     ENDIF()
692 ENDIF()
693 IF(REQUIRE_COREAUDIO AND NOT HAVE_COREAUDIO)
694     MESSAGE(FATAL_ERROR "Failed to enabled required CoreAudio backend")
695 ENDIF()
697 # Check for OpenSL (Android) backend
698 IF(OPENSL)
699     CHECK_INCLUDE_FILES("SLES/OpenSLES.h;SLES/OpenSLES_Android.h" HAVE_SLES_OPENSLES_ANDROID_H)
700     IF(HAVE_SLES_OPENSLES_ANDROID_H)
701         CHECK_SHARED_FUNCTION_EXISTS(slCreateEngine "SLES/OpenSLES.h" OpenSLES "" HAVE_LIBOPENSLES)
702         IF(HAVE_LIBOPENSLES)
703             SET(HAVE_OPENSL 1)
704             SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/opensl.c)
705             SET(BACKENDS  "${BACKENDS} OpenSL,")
706             SET(EXTRA_LIBS OpenSLES ${EXTRA_LIBS})
707         ENDIF()
708     ENDIF()
709 ENDIF()
710 IF(REQUIRE_OPENSL AND NOT HAVE_OPENSL)
711     MESSAGE(FATAL_ERROR "Failed to enabled required OpenSL backend")
712 ENDIF()
714 # Optionally enable the Wave Writer backend
715 IF(WAVE)
716     SET(HAVE_WAVE 1)
717     SET(ALC_OBJS  ${ALC_OBJS} Alc/backends/wave.c)
718     SET(BACKENDS  "${BACKENDS} WaveFile,")
719 ENDIF()
721 # This is always available
722 SET(BACKENDS  "${BACKENDS} Null")
724 IF(EXAMPLES)
725     # Might be able to use earlier versions, but these definitely work
726     PKG_CHECK_MODULES(FFMPEG libavcodec>=52.123.0 libavformat>=52.111.0 libavutil>=51.9.1)
727 ENDIF()
729 IF(LIBTYPE STREQUAL "STATIC")
730     ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC)
731     SET(PKG_CONFIG_CFLAGS -DAL_LIBTYPE_STATIC ${PKG_CONFIG_CFLAGS})
732 ENDIF()
734 # Needed for openal.pc.in
735 SET(prefix ${CMAKE_INSTALL_PREFIX})
736 SET(exec_prefix "\${prefix}")
737 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
738 SET(bindir "\${exec_prefix}/bin")
739 SET(includedir "\${prefix}/include")
740 SET(PACKAGE_VERSION "${LIB_VERSION}")
742 # End configuration
743 CONFIGURE_FILE(
744     "${OpenAL_SOURCE_DIR}/config.h.in"
745     "${OpenAL_BINARY_DIR}/config.h")
746 CONFIGURE_FILE(
747     "${OpenAL_SOURCE_DIR}/openal.pc.in"
748     "${OpenAL_BINARY_DIR}/openal.pc"
749     @ONLY)
751 # Build a library
752 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
753 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
754                                             COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
755                                             VERSION ${LIB_VERSION}.0
756                                             SOVERSION ${LIB_MAJOR_VERSION})
757 IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
758     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
759 ENDIF()
761 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
763 # Add an install target here
764 INSTALL(TARGETS ${LIBNAME}
765         RUNTIME DESTINATION bin
766         LIBRARY DESTINATION "lib${LIB_SUFFIX}"
767         ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
769 INSTALL(FILES include/AL/al.h
770               include/AL/alc.h
771               include/AL/alext.h
772               include/AL/efx.h
773               include/AL/efx-creative.h
774               include/AL/efx-presets.h
775         DESTINATION include/AL
777 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
778         DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
781 MESSAGE(STATUS "")
782 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
783 MESSAGE(STATUS "    ${BACKENDS}")
784 MESSAGE(STATUS "")
785 MESSAGE(STATUS "Building with support for CPU extensions:")
786 MESSAGE(STATUS "    ${CPU_EXTS}")
787 MESSAGE(STATUS "")
789 IF(WIN32)
790     IF(NOT HAVE_DSOUND)
791         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
792         MESSAGE(STATUS "         This is probably NOT what you want!")
793         MESSAGE(STATUS "")
794     ENDIF()
795 ENDIF()
797 # Install alsoft.conf configuration file
798 IF(ALSOFT_CONFIG)
799     INSTALL(FILES alsoftrc.sample
800             DESTINATION /etc/openal
801             RENAME alsoft.conf
802     )
803     MESSAGE(STATUS "Installing sample alsoft.conf")
804     MESSAGE(STATUS "")
805 ENDIF()
807 IF(UTILS)
808     ADD_EXECUTABLE(openal-info utils/openal-info.c)
809     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
811     ADD_EXECUTABLE(makehrtf utils/makehrtf.c)
812     IF(HAVE_LIBM)
813         TARGET_LINK_LIBRARIES(makehrtf m)
814     ENDIF()
816     INSTALL(TARGETS openal-info makehrtf
817             RUNTIME DESTINATION bin
818             LIBRARY DESTINATION "lib${LIB_SUFFIX}"
819             ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
820     )
821     MESSAGE(STATUS "Building utility programs")
822     MESSAGE(STATUS "")
823 ENDIF()
825 IF(EXAMPLES)
826     IF(FFMPEG_FOUND)
827         ADD_EXECUTABLE(alstream examples/alhelpers.c examples/alffmpeg.c examples/alstream.c)
828         TARGET_LINK_LIBRARIES(alstream ${FFMPEG_LIBRARIES} ${LIBNAME})
829         SET_TARGET_PROPERTIES(alstream PROPERTIES COMPILE_FLAGS "${FFMPEG_CFLAGS}")
830         INSTALL(TARGETS alstream
831                 RUNTIME DESTINATION bin
832                 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
833                 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
834         )
836         MESSAGE(STATUS "Building ffmpeg example programs")
837         MESSAGE(STATUS "")
838     ENDIF()
839 ENDIF()