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
253 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
254 IF(HAVE_ALSA_ASOUNDLIB_H)
255 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
256 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
258 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
260 SET(BACKENDS "${BACKENDS} ALSA,")
262 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
263 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
271 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
272 IF(HAVE_SYS_SOUNDCARD_H)
274 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
275 SET(BACKENDS "${BACKENDS} OSS,")
279 # Check Solaris backend
281 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
282 IF(HAVE_SYS_AUDIOIO_H)
284 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
285 SET(BACKENDS "${BACKENDS} Solaris,")
289 # Check DSound/MMSystem backend
291 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
293 CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
294 IF(HAVE_LIBDSOUND OR WIN32)
296 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
299 SET(BACKENDS "${BACKENDS} DirectSound,")
301 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
302 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
309 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
312 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
313 SET(BACKENDS "${BACKENDS} WinMM,")
315 SET(CMAKE_REQUIRED_LIBRARIES winmm)
316 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
317 SET(CMAKE_REQUIRED_LIBRARIES "")
318 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
320 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
326 # Check PortAudio backend
328 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
330 CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
331 IF(HAVE_LIBPORTAUDIO)
332 SET(HAVE_PORTAUDIO 1)
333 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
335 SET(BACKENDS "${BACKENDS} PortAudio,")
337 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
338 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
344 # This is always available
345 SET(BACKENDS "${BACKENDS} WaveFile")
347 # Needed for openal.pc.in
348 SET(prefix ${CMAKE_INSTALL_PREFIX})
349 SET(exec_prefix "\${prefix}")
350 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
351 SET(bindir "\${exec_prefix}/bin")
352 SET(includedir "\${prefix}/include")
353 SET(PACKAGE_VERSION "${LIB_VERSION}")
357 "${OpenAL_SOURCE_DIR}/config.h.in"
358 "${OpenAL_BINARY_DIR}/config.h")
360 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
361 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
364 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
370 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
371 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
372 SOVERSION ${LIB_MAJOR_VERSION})
374 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
377 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
379 # Add an install target here
380 INSTALL(TARGETS ${LIBNAME}
381 RUNTIME DESTINATION bin
382 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
383 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
385 INSTALL(FILES include/AL/al.h
388 DESTINATION include/AL
390 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
391 DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
394 ADD_EXECUTABLE(openal-info examples/openal-info.c)
395 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
396 INSTALL(TARGETS openal-info
397 RUNTIME DESTINATION bin
398 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
399 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
404 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
405 MESSAGE(STATUS " ${BACKENDS}")
410 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
411 MESSAGE(STATUS " This is probably NOT what you want!")