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 INCLUDE(CheckFunctionExists)
10 INCLUDE(CheckLibraryExists)
11 INCLUDE(CheckIncludeFile)
12 INCLUDE(CheckIncludeFiles)
13 INCLUDE(CheckCCompilerFlag)
14 INCLUDE(CheckCSourceCompiles)
15 INCLUDE(CheckTypeSize)
21 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
24 OPTION(ALSA "Check for ALSA backend" ON)
25 OPTION(OSS "Check for OSS backend" ON)
26 OPTION(SOLARIS "Check for Solaris backend" ON)
27 OPTION(DSOUND "Check for DirectSound backend" ON)
28 OPTION(WINMM "Check for Windows Multimedia backend" ON)
29 OPTION(PORTAUDIO "Check for PortAudio backend" ON)
31 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
33 OPTION(WERROR "Treat compile warnings as errors" OFF)
35 OPTION(EXAMPLES "Build example programs" ON)
40 ADD_DEFINITIONS("-D_WIN32")
45 SET(LIB_MAJOR_VERSION "1")
46 SET(LIB_MINOR_VERSION "7")
47 SET(LIB_BUILD_VERSION "411")
48 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
49 IF(NOT DEFINED LIB_INSTALL_DIR)
50 SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
51 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
54 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
55 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
56 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
57 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
60 # Add definitions, compiler switches, etc.
61 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
63 IF(NOT CMAKE_BUILD_TYPE)
64 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
65 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
68 IF(NOT CMAKE_DEBUG_POSTFIX)
69 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
70 "Library postfix for debug builds. Normally left blank."
76 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
77 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
78 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
79 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
81 ADD_DEFINITIONS(-Wall)
82 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
84 ADD_DEFINITIONS(-Wextra)
88 ADD_DEFINITIONS(-Werror)
91 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
92 "Flags used by the compiler during Release with Debug Info builds."
94 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
95 "Flags used by the compiler during release minsize builds."
97 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
98 "Flags used by the compiler during release builds"
100 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
101 "Flags used by the compiler during debug builds."
104 # Set visibility options if available
106 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
107 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
109 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
110 IF(HAVE_VISIBILITY_SWITCH)
111 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
112 int main() {return 0;}" HAVE_GCC_VISIBILITY)
113 IF(HAVE_GCC_VISIBILITY)
114 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
120 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
121 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
123 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
124 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
125 CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
126 CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
128 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
130 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
131 SET(EXTRA_LIBS m ${EXTRA_LIBS})
133 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
134 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
136 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
137 IF(NOT HAVE_STRCASECMP)
138 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
139 IF(NOT HAVE__STRICMP)
140 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
143 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
146 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
147 IF(NOT HAVE_STRNCASECMP)
148 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
149 IF(NOT HAVE__STRNICMP)
150 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
153 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
156 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
157 IF(NOT HAVE_SNPRINTF)
158 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
159 IF(NOT HAVE__SNPRINTF)
160 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
163 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
166 # Check for the dlopen API (for dynamicly loading backend libs)
168 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
170 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
172 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
177 # Check if we have Windows headers
178 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
179 IF(NOT HAVE_WINDOWS_H)
180 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
181 IF(NOT HAVE_GETTIMEOFDAY)
182 MESSAGE(FATAL_ERROR "No timing function found!")
185 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
186 IF(NOT HAVE_NANOSLEEP)
187 MESSAGE(FATAL_ERROR "No sleep function found!")
190 # We need pthreads outside of Windows
191 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
192 IF(NOT HAVE_PTHREAD_H)
193 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
196 # Some systems need pthread_np.h to get recursive mutexes
197 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
199 # _GNU_SOURCE is needed on some systems for extra attributes, and
200 # _REENTRANT is needed for libc thread-safety
201 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
202 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
204 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
208 # Check for a 64-bit type
209 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
210 IF(NOT HAVE_STDINT_H)
212 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
213 \#include <windows.h>
215 int main() {return 0;}" HAVE___INT64)
218 IF(NOT SIZEOF_LONG MATCHES "8")
219 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
220 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
227 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
231 OpenAL32/alExtension.c
233 OpenAL32/alListener.c
238 SET(ALC_OBJS Alc/ALc.c
252 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
253 IF(HAVE_ALSA_ASOUNDLIB_H)
254 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
255 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
257 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
259 SET(BACKENDS "${BACKENDS} ALSA,")
261 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
262 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
270 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
271 IF(HAVE_SYS_SOUNDCARD_H)
273 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
274 SET(BACKENDS "${BACKENDS} OSS,")
278 # Check Solaris backend
280 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
281 IF(HAVE_SYS_AUDIOIO_H)
283 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
284 SET(BACKENDS "${BACKENDS} Solaris,")
288 # Check DSound/MMSystem backend
290 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
292 CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
293 IF(HAVE_LIBDSOUND OR WIN32)
295 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
298 SET(BACKENDS "${BACKENDS} DirectSound,")
300 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
301 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
308 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
311 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
312 SET(BACKENDS "${BACKENDS} WinMM,")
314 SET(CMAKE_REQUIRED_LIBRARIES winmm)
315 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
316 SET(CMAKE_REQUIRED_LIBRARIES "")
317 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
319 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
325 # Check PortAudio backend
327 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
329 CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
330 IF(HAVE_LIBPORTAUDIO)
331 SET(HAVE_PORTAUDIO 1)
332 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
334 SET(BACKENDS "${BACKENDS} PortAudio,")
336 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
337 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
343 # This is always available
344 SET(BACKENDS "${BACKENDS} WaveFile")
346 # Needed for openal.pc.in
347 SET(prefix ${CMAKE_INSTALL_PREFIX})
348 SET(exec_prefix "\${prefix}")
349 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
350 SET(bindir "\${exec_prefix}/bin")
351 SET(includedir "\${prefix}/include")
352 SET(PACKAGE_VERSION "${LIB_VERSION}")
356 "${OpenAL_SOURCE_DIR}/config.h.in"
357 "${OpenAL_BINARY_DIR}/config.h")
359 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
360 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
363 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
369 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
370 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
371 SOVERSION ${LIB_MAJOR_VERSION})
373 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
376 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
378 # Add an install target here
379 INSTALL(TARGETS ${LIBNAME}
380 RUNTIME DESTINATION bin
381 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
382 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
384 INSTALL(FILES include/AL/al.h
387 DESTINATION include/AL
389 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
390 DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
393 ADD_EXECUTABLE(openal-info examples/openal-info.c)
394 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
395 INSTALL(TARGETS openal-info
396 RUNTIME DESTINATION bin
397 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
398 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
403 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
404 MESSAGE(STATUS " ${BACKENDS}")
409 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
410 MESSAGE(STATUS " This is probably NOT what you want!")