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(CheckSharedLibraryExists)
14 INCLUDE(CheckIncludeFile)
15 INCLUDE(CheckIncludeFiles)
16 INCLUDE(CheckSymbolExists)
17 INCLUDE(CheckCCompilerFlag)
18 INCLUDE(CheckCSourceCompiles)
19 INCLUDE(CheckTypeSize)
25 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
28 OPTION(ALSA "Check for ALSA backend" ON)
29 OPTION(OSS "Check for OSS backend" ON)
30 OPTION(SOLARIS "Check for Solaris backend" ON)
31 OPTION(DSOUND "Check for DirectSound backend" ON)
32 OPTION(WINMM "Check for Windows Multimedia backend" ON)
33 OPTION(PORTAUDIO "Check for PortAudio backend" ON)
34 OPTION(PULSEAUDIO "Check for PulseAudio backend" ON)
36 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
38 OPTION(WERROR "Treat compile warnings as errors" OFF)
40 OPTION(EXAMPLES "Build example programs" ON)
42 OPTION(ALSOFT_CONFIG "Install alsoft.conf configuration file" OFF)
47 ADD_DEFINITIONS("-D_WIN32")
52 SET(LIB_MAJOR_VERSION "1")
53 SET(LIB_MINOR_VERSION "12")
54 SET(LIB_BUILD_VERSION "854")
55 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
58 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
59 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
60 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
61 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
64 # Add definitions, compiler switches, etc.
65 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
67 IF(NOT CMAKE_BUILD_TYPE)
68 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
69 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
72 IF(NOT CMAKE_DEBUG_POSTFIX)
73 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
74 "Library postfix for debug builds. Normally left blank."
80 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
81 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
82 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
83 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
84 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
85 ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
88 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
90 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
93 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
94 SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
95 INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
96 LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
100 ADD_DEFINITIONS(-Wall)
101 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
103 ADD_DEFINITIONS(-Wextra)
107 ADD_DEFINITIONS(-Werror)
110 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
111 "Flags used by the compiler during Release with Debug Info builds."
113 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
114 "Flags used by the compiler during release minsize builds."
116 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
117 "Flags used by the compiler during release builds"
119 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
120 "Flags used by the compiler during debug builds."
123 # Set visibility options if available
125 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
126 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
128 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
129 IF(HAVE_VISIBILITY_SWITCH)
130 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
131 int main() {return 0;}" HAVE_GCC_VISIBILITY)
132 IF(HAVE_GCC_VISIBILITY)
133 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
139 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
140 int main() {return 0;}" HAVE_GCC_FORMAT)
142 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
143 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
145 CHECK_LIBRARY_EXISTS(m powf "" HAVE_POWF)
146 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
147 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
148 CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
149 CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
151 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
153 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
154 SET(EXTRA_LIBS m ${EXTRA_LIBS})
156 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
157 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
159 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
160 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
161 IF(NOT HAVE_STRCASECMP)
162 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
163 IF(NOT HAVE__STRICMP)
164 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
167 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
170 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
171 IF(NOT HAVE_STRNCASECMP)
172 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
173 IF(NOT HAVE__STRNICMP)
174 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
177 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
180 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
181 IF(NOT HAVE_SNPRINTF)
182 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
183 IF(NOT HAVE__SNPRINTF)
184 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
187 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
190 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
191 IF(NOT HAVE_VSNPRINTF)
192 CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
193 IF(NOT HAVE__VSNPRINTF)
194 MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
197 ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
200 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
202 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
204 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
207 ADD_DEFINITIONS(-Disnan=_isnan)
211 # Check for the dlopen API (for dynamicly loading backend libs)
213 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
215 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
217 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
222 # Check if we have Windows headers
223 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
224 IF(NOT HAVE_WINDOWS_H)
225 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
226 IF(NOT HAVE_GETTIMEOFDAY)
227 MESSAGE(FATAL_ERROR "No timing function found!")
230 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
231 IF(NOT HAVE_NANOSLEEP)
232 MESSAGE(FATAL_ERROR "No sleep function found!")
235 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
237 ADD_DEFINITIONS(-pthread)
238 SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
241 # We need pthreads outside of Windows
242 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
243 IF(NOT HAVE_PTHREAD_H)
244 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
246 # Some systems need pthread_np.h to get recursive mutexes
247 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
249 # _GNU_SOURCE is needed on some systems for extra attributes, and
250 # _REENTRANT is needed for libc thread-safety
251 ADD_DEFINITIONS(-D_GNU_SOURCE=1)
252 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
254 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
257 CHECK_LIBRARY_EXISTS(pthread pthread_setschedparam "" HAVE_PTHREAD_SETSCHEDPARAM)
259 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
261 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
265 # Check for a 64-bit type
266 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
267 IF(NOT HAVE_STDINT_H)
269 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
270 \#include <windows.h>
272 int main() {return 0;}" HAVE___INT64)
275 IF(NOT SIZEOF_LONG MATCHES "8")
276 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
277 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
284 # Windows needs winmm for timeGetTime, even if the backend is disabled
285 CHECK_SHARED_LIBRARY_EXISTS(winmm timeGetTime 0 "" HAVE_LIBWINMM)
287 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
292 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
294 OpenAL32/alDatabuffer.c
297 OpenAL32/alExtension.c
299 OpenAL32/alListener.c
304 SET(ALC_OBJS Alc/ALc.c
320 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
321 IF(HAVE_ALSA_ASOUNDLIB_H)
322 CHECK_SHARED_LIBRARY_EXISTS(asound snd_pcm_open 4 "" HAVE_LIBASOUND)
323 IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
325 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
326 IF(HAVE_DLFCN_H OR WIN32)
327 SET(BACKENDS "${BACKENDS} ALSA,")
329 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
330 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
338 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
339 IF(HAVE_SYS_SOUNDCARD_H)
341 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
342 SET(BACKENDS "${BACKENDS} OSS,")
346 # Check Solaris backend
348 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
349 IF(HAVE_SYS_AUDIOIO_H)
351 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
352 SET(BACKENDS "${BACKENDS} Solaris,")
356 # Check DSound/MMSystem backend
358 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
360 CHECK_SHARED_LIBRARY_EXISTS(dsound DirectSoundCreate 3 "" HAVE_LIBDSOUND)
361 IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
363 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
365 IF(HAVE_DLFCN_H OR WIN32)
366 SET(BACKENDS "${BACKENDS} DirectSound,")
368 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
369 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
376 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
378 CHECK_SHARED_LIBRARY_EXISTS(winmm waveInOpen 6 "" HAVE_LIBWINMM)
381 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
382 SET(BACKENDS "${BACKENDS} WinMM,")
384 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
390 # Check PortAudio backend
392 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
394 CHECK_SHARED_LIBRARY_EXISTS(portaudio Pa_Initialize 0 "" HAVE_LIBPORTAUDIO)
395 IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
396 SET(HAVE_PORTAUDIO 1)
397 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
398 IF(HAVE_DLFCN_H OR WIN32)
399 SET(BACKENDS "${BACKENDS} PortAudio,")
401 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
402 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
408 # Check PortAudio backend
410 CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
411 IF(HAVE_PULSE_PULSEAUDIO_H)
412 CHECK_SHARED_LIBRARY_EXISTS(pulse pa_context_new 2 "" HAVE_LIBPULSE)
413 IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
414 SET(HAVE_PULSEAUDIO 1)
415 SET(ALC_OBJS ${ALC_OBJS} Alc/pulseaudio.c)
416 IF(HAVE_DLFCN_H OR WIN32)
417 SET(BACKENDS "${BACKENDS} PulseAudio,")
419 SET(BACKENDS "${BACKENDS} PulseAudio \(linked\),")
420 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
426 # This is always available
427 SET(BACKENDS "${BACKENDS} WaveFile")
429 # Needed for openal.pc.in
430 SET(prefix ${CMAKE_INSTALL_PREFIX})
431 SET(exec_prefix "\${prefix}")
432 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
433 SET(bindir "\${exec_prefix}/bin")
434 SET(includedir "\${prefix}/include")
435 SET(PACKAGE_VERSION "${LIB_VERSION}")
439 "${OpenAL_SOURCE_DIR}/config.h.in"
440 "${OpenAL_BINARY_DIR}/config.h")
442 "${OpenAL_SOURCE_DIR}/openal.pc.in"
443 "${OpenAL_BINARY_DIR}/openal.pc"
450 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
451 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
452 COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
453 VERSION ${LIB_VERSION}
454 SOVERSION ${LIB_MAJOR_VERSION})
456 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
459 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
461 # Add an install target here
462 INSTALL(TARGETS ${LIBNAME}
463 RUNTIME DESTINATION bin
464 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
465 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
467 INSTALL(FILES include/AL/al.h
471 DESTINATION include/AL
473 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
474 DESTINATION "lib${LIB_SUFFIX}/pkgconfig")
476 # Install alsoft.conf configuration file
478 INSTALL(FILES alsoftrc.sample
479 DESTINATION /etc/openal
485 ADD_EXECUTABLE(openal-info examples/openal-info.c)
486 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
487 INSTALL(TARGETS openal-info
488 RUNTIME DESTINATION bin
489 LIBRARY DESTINATION "lib${LIB_SUFFIX}"
490 ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
495 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
496 MESSAGE(STATUS " ${BACKENDS}")
501 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
502 MESSAGE(STATUS " This is probably NOT what you want!")