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)
30 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
32 OPTION(WERROR "Treat compile warnings as errors" OFF)
34 OPTION(EXAMPLES "Build example programs" ON)
43 SET(LIB_MAJOR_VERSION "1")
44 SET(LIB_MINOR_VERSION "5")
45 SET(LIB_BUILD_VERSION "304")
46 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
47 IF(NOT DEFINED LIB_INSTALL_DIR)
48 SET(LIB_INSTALL_DIR "lib")
49 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
52 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
53 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
54 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
55 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
58 # Add definitions, compiler switches, etc.
59 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
61 IF(NOT CMAKE_BUILD_TYPE)
62 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
63 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
69 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
70 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
71 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
72 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
74 ADD_DEFINITIONS(-Wall)
75 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
77 ADD_DEFINITIONS(-Wextra)
81 ADD_DEFINITIONS(-Werror)
84 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
85 "Flags used by the compiler during Release with Debug Info builds."
87 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
88 "Flags used by the compiler during release minsize builds."
90 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
91 "Flags used by the compiler during release builds"
93 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
94 "Flags used by the compiler during debug builds."
97 # Set visibility options if available
99 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
100 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
102 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
103 IF("${HAVE_VISIBILITY_SWITCH}")
104 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
105 int main() {return 0;}" HAVE_GCC_VISIBILITY)
106 IF("${HAVE_GCC_VISIBILITY}")
107 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
113 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
114 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
116 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
117 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
119 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
121 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_FESETROUND)
122 SET(EXTRA_LIBS m ${EXTRA_LIBS})
124 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
125 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
127 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
128 IF(NOT HAVE_STRCASECMP)
129 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
130 IF(NOT HAVE__STRICMP)
131 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
134 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
137 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
138 IF(NOT HAVE_STRNCASECMP)
139 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
140 IF(NOT HAVE__STRNICMP)
141 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
144 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
147 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
148 IF(NOT HAVE_SNPRINTF)
149 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
150 IF(NOT HAVE__SNPRINTF)
151 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
154 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
157 # Check for the dlopen API (for dynamicly loading backend libs)
159 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
161 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
163 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
168 # Check if we have Windows headers
169 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
170 IF(NOT HAVE_WINDOWS_H)
171 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
172 IF(NOT HAVE_GETTIMEOFDAY)
173 MESSAGE(FATAL_ERROR "No timing function found!")
176 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
177 IF(NOT HAVE_NANOSLEEP)
178 MESSAGE(FATAL_ERROR "No sleep function found!")
181 # We need pthreads outside of Windows
182 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
183 IF(NOT HAVE_PTHREAD_H)
184 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
187 # Some systems need pthread_np.h to get recursive mutexes
188 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
190 # _GNU_SOURCE is needed on some systems for extra attributes, and
191 # _REENTRANT is needed for libc thread-safety
192 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
193 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
195 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
199 # Check for a 64-bit type
200 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
201 IF(NOT HAVE_STDINT_H)
203 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
204 \#include <windows.h>
206 int main() {return 0;}" HAVE___INT64)
209 IF(NOT SIZEOF_LONG MATCHES "8")
210 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
211 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
218 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
222 OpenAL32/alExtension.c
224 OpenAL32/alListener.c
229 SET(ALC_OBJS Alc/ALc.c
242 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
243 IF(HAVE_ALSA_ASOUNDLIB_H)
244 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
245 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
247 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
249 SET(BACKENDS "${BACKENDS} ALSA,")
251 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
252 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
260 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
261 IF(HAVE_SYS_SOUNDCARD_H)
263 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
264 SET(BACKENDS "${BACKENDS} OSS,")
268 # Check Solaris backend
270 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
271 IF(HAVE_SYS_AUDIOIO_H)
273 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
274 SET(BACKENDS "${BACKENDS} Solaris,")
278 # Check DSound/MMSystem backend
281 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
284 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
285 SET(BACKENDS "${BACKENDS} DirectSound,")
287 SET(CMAKE_REQUIRED_LIBRARIES dsound)
288 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBDSOUND)
289 SET(CMAKE_REQUIRED_LIBRARIES "")
290 # CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
292 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
297 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
300 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
301 SET(BACKENDS "${BACKENDS} WinMM,")
303 SET(CMAKE_REQUIRED_LIBRARIES winmm)
304 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
305 SET(CMAKE_REQUIRED_LIBRARIES "")
306 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
308 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
314 # This is always available
315 SET(BACKENDS "${BACKENDS} WaveFile")
317 # Needed for openal.pc.in
318 SET(prefix ${CMAKE_INSTALL_PREFIX})
319 SET(exec_prefix "\${prefix}")
320 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
321 SET(bindir "\${exec_prefix}/bin")
322 SET(includedir "\${prefix}/include")
323 SET(PACKAGE_VERSION "${LIB_VERSION}")
327 "${OpenAL_SOURCE_DIR}/config.h.in"
328 "${OpenAL_BINARY_DIR}/config.h")
330 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
331 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
334 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
340 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
341 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
342 SOVERSION ${LIB_MAJOR_VERSION})
344 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
347 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
349 # Add an install target here
350 INSTALL(TARGETS ${LIBNAME}
351 RUNTIME DESTINATION bin
352 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
353 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
355 INSTALL(FILES include/AL/al.h
358 DESTINATION include/AL
360 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
361 DESTINATION lib/pkgconfig)
364 ADD_EXECUTABLE(openal-info examples/openal-info.c)
365 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
366 INSTALL(TARGETS openal-info
367 RUNTIME DESTINATION bin
368 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
369 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
374 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
375 MESSAGE(STATUS " ${BACKENDS}")
378 IF(WIN32 AND NOT HAVE_DSOUND)
379 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
380 MESSAGE(STATUS " This is probably NOT what you want!")