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}")
56 IF(NOT DEFINED LIB_INSTALL_DIR)
57 SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
58 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
61 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
62 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
63 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
64 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
67 # Add definitions, compiler switches, etc.
68 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
70 IF(NOT CMAKE_BUILD_TYPE)
71 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
72 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
75 IF(NOT CMAKE_DEBUG_POSTFIX)
76 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
77 "Library postfix for debug builds. Normally left blank."
83 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
84 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
85 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
86 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
87 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
88 ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
91 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
93 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
96 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
97 SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
98 INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
99 LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
103 ADD_DEFINITIONS(-Wall)
104 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
106 ADD_DEFINITIONS(-Wextra)
110 ADD_DEFINITIONS(-Werror)
113 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
114 "Flags used by the compiler during Release with Debug Info builds."
116 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
117 "Flags used by the compiler during release minsize builds."
119 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
120 "Flags used by the compiler during release builds"
122 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
123 "Flags used by the compiler during debug builds."
126 # Set visibility options if available
128 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
129 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
131 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
132 IF(HAVE_VISIBILITY_SWITCH)
133 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
134 int main() {return 0;}" HAVE_GCC_VISIBILITY)
135 IF(HAVE_GCC_VISIBILITY)
136 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
142 CHECK_C_SOURCE_COMPILES("int foo(const char *str, ...) __attribute__((format(printf, 1, 2)));
143 int main() {return 0;}" HAVE_GCC_FORMAT)
145 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
146 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
148 CHECK_LIBRARY_EXISTS(m powf "" HAVE_POWF)
149 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
150 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
151 CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
152 CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
154 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
156 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
157 SET(EXTRA_LIBS m ${EXTRA_LIBS})
159 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
160 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
162 CHECK_FUNCTION_EXISTS(stat HAVE_STAT)
163 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
164 IF(NOT HAVE_STRCASECMP)
165 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
166 IF(NOT HAVE__STRICMP)
167 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
170 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
173 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
174 IF(NOT HAVE_STRNCASECMP)
175 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
176 IF(NOT HAVE__STRNICMP)
177 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
180 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
183 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
184 IF(NOT HAVE_SNPRINTF)
185 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
186 IF(NOT HAVE__SNPRINTF)
187 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
190 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
193 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
194 IF(NOT HAVE_VSNPRINTF)
195 CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
196 IF(NOT HAVE__VSNPRINTF)
197 MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
200 ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
203 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
205 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
207 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
210 ADD_DEFINITIONS(-Disnan=_isnan)
214 # Check for the dlopen API (for dynamicly loading backend libs)
216 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
218 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
220 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
225 # Check if we have Windows headers
226 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
227 IF(NOT HAVE_WINDOWS_H)
228 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
229 IF(NOT HAVE_GETTIMEOFDAY)
230 MESSAGE(FATAL_ERROR "No timing function found!")
233 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
234 IF(NOT HAVE_NANOSLEEP)
235 MESSAGE(FATAL_ERROR "No sleep function found!")
238 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
240 ADD_DEFINITIONS(-pthread)
241 SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
244 # We need pthreads outside of Windows
245 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
246 IF(NOT HAVE_PTHREAD_H)
247 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
249 # Some systems need pthread_np.h to get recursive mutexes
250 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
252 # _GNU_SOURCE is needed on some systems for extra attributes, and
253 # _REENTRANT is needed for libc thread-safety
254 ADD_DEFINITIONS(-D_GNU_SOURCE=1)
255 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
257 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
260 CHECK_LIBRARY_EXISTS(pthread pthread_setschedparam "" HAVE_PTHREAD_SETSCHEDPARAM)
262 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
264 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
268 # Check for a 64-bit type
269 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
270 IF(NOT HAVE_STDINT_H)
272 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
273 \#include <windows.h>
275 int main() {return 0;}" HAVE___INT64)
278 IF(NOT SIZEOF_LONG MATCHES "8")
279 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
280 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
287 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
289 OpenAL32/alDatabuffer.c
292 OpenAL32/alExtension.c
294 OpenAL32/alListener.c
299 SET(ALC_OBJS Alc/ALc.c
315 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
316 IF(HAVE_ALSA_ASOUNDLIB_H)
317 CHECK_SHARED_LIBRARY_EXISTS(asound snd_pcm_open 4 "" HAVE_LIBASOUND)
318 IF(HAVE_LIBASOUND OR HAVE_DLFCN_H OR WIN32)
320 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
321 IF(HAVE_DLFCN_H OR WIN32)
322 SET(BACKENDS "${BACKENDS} ALSA,")
324 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
325 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
333 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
334 IF(HAVE_SYS_SOUNDCARD_H)
336 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
337 SET(BACKENDS "${BACKENDS} OSS,")
341 # Check Solaris backend
343 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
344 IF(HAVE_SYS_AUDIOIO_H)
346 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
347 SET(BACKENDS "${BACKENDS} Solaris,")
351 # Check DSound/MMSystem backend
353 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
355 CHECK_SHARED_LIBRARY_EXISTS(dsound DirectSoundCreate 3 "" HAVE_LIBDSOUND)
356 IF(HAVE_LIBDSOUND OR HAVE_DLFCN_H OR WIN32)
358 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
360 IF(HAVE_DLFCN_H OR WIN32)
361 SET(BACKENDS "${BACKENDS} DirectSound,")
363 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
364 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
371 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
373 CHECK_SHARED_LIBRARY_EXISTS(winmm waveInOpen 6 "" HAVE_LIBWINMM)
376 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
377 SET(BACKENDS "${BACKENDS} WinMM,")
379 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
385 # Check PortAudio backend
387 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
389 CHECK_SHARED_LIBRARY_EXISTS(portaudio Pa_Initialize 0 "" HAVE_LIBPORTAUDIO)
390 IF(HAVE_LIBPORTAUDIO OR HAVE_DLFCN_H OR WIN32)
391 SET(HAVE_PORTAUDIO 1)
392 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
393 IF(HAVE_DLFCN_H OR WIN32)
394 SET(BACKENDS "${BACKENDS} PortAudio,")
396 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
397 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
403 # Check PortAudio backend
405 CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
406 IF(HAVE_PULSE_PULSEAUDIO_H)
407 CHECK_SHARED_LIBRARY_EXISTS(pulse pa_context_new 2 "" HAVE_LIBPULSE)
408 IF(HAVE_LIBPULSE OR HAVE_DLFCN_H OR WIN32)
409 SET(HAVE_PULSEAUDIO 1)
410 SET(ALC_OBJS ${ALC_OBJS} Alc/pulseaudio.c)
411 IF(HAVE_DLFCN_H OR WIN32)
412 SET(BACKENDS "${BACKENDS} PulseAudio,")
414 SET(BACKENDS "${BACKENDS} PulseAudio \(linked\),")
415 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
421 # This is always available
422 SET(BACKENDS "${BACKENDS} WaveFile")
424 # Needed for openal.pc.in
425 SET(prefix ${CMAKE_INSTALL_PREFIX})
426 SET(exec_prefix "\${prefix}")
427 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
428 SET(bindir "\${exec_prefix}/bin")
429 SET(includedir "\${prefix}/include")
430 SET(PACKAGE_VERSION "${LIB_VERSION}")
434 "${OpenAL_SOURCE_DIR}/config.h.in"
435 "${OpenAL_BINARY_DIR}/config.h")
437 "${OpenAL_SOURCE_DIR}/openal.pc.in"
438 "${OpenAL_BINARY_DIR}/openal.pc"
445 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
446 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL AL_BUILD_LIBRARY
447 COMPILE_FLAGS -DAL_ALEXT_PROTOTYPES
448 VERSION ${LIB_VERSION}
449 SOVERSION ${LIB_MAJOR_VERSION})
451 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
454 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
456 # Add an install target here
457 INSTALL(TARGETS ${LIBNAME}
458 RUNTIME DESTINATION bin
459 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
460 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
462 INSTALL(FILES include/AL/al.h
466 DESTINATION include/AL
468 INSTALL(FILES "${OpenAL_BINARY_DIR}/openal.pc"
469 DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
471 # Install alsoft.conf configuration file
473 INSTALL(FILES alsoftrc.sample
474 DESTINATION /etc/openal
480 ADD_EXECUTABLE(openal-info examples/openal-info.c)
481 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
482 INSTALL(TARGETS openal-info
483 RUNTIME DESTINATION bin
484 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
485 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
490 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
491 MESSAGE(STATUS " ${BACKENDS}")
496 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
497 MESSAGE(STATUS " This is probably NOT what you want!")