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(CheckSymbolExists)
14 INCLUDE(CheckCCompilerFlag)
15 INCLUDE(CheckCSourceCompiles)
16 INCLUDE(CheckTypeSize)
22 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
25 OPTION(ALSA "Check for ALSA backend" ON)
26 OPTION(OSS "Check for OSS backend" ON)
27 OPTION(SOLARIS "Check for Solaris backend" ON)
28 OPTION(DSOUND "Check for DirectSound backend" ON)
29 OPTION(WINMM "Check for Windows Multimedia backend" ON)
30 OPTION(PORTAUDIO "Check for PortAudio backend" ON)
31 OPTION(PULSEAUDIO "Check for PulseAudio backend" ON)
33 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
35 OPTION(WERROR "Treat compile warnings as errors" OFF)
37 OPTION(EXAMPLES "Build example programs" ON)
39 OPTION(ALSOFT_CONFIG "Install alsoft.conf configuration file" OFF)
44 ADD_DEFINITIONS("-D_WIN32")
49 SET(LIB_MAJOR_VERSION "1")
50 SET(LIB_MINOR_VERSION "9")
51 SET(LIB_BUILD_VERSION "563")
52 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
53 IF(NOT DEFINED LIB_INSTALL_DIR)
54 SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
55 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
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)
86 ADD_DEFINITIONS(-Wall)
87 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
89 ADD_DEFINITIONS(-Wextra)
93 ADD_DEFINITIONS(-Werror)
96 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
97 "Flags used by the compiler during Release with Debug Info builds."
99 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
100 "Flags used by the compiler during release minsize builds."
102 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
103 "Flags used by the compiler during release builds"
105 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
106 "Flags used by the compiler during debug builds."
109 # Set visibility options if available
111 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
112 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
114 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
115 IF(HAVE_VISIBILITY_SWITCH)
116 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
117 int main() {return 0;}" HAVE_GCC_VISIBILITY)
118 IF(HAVE_GCC_VISIBILITY)
119 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
125 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
126 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
128 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
129 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
130 CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
131 CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
133 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
135 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
136 SET(EXTRA_LIBS m ${EXTRA_LIBS})
138 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
139 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
141 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
142 IF(NOT HAVE_STRCASECMP)
143 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
144 IF(NOT HAVE__STRICMP)
145 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
148 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
151 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
152 IF(NOT HAVE_STRNCASECMP)
153 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
154 IF(NOT HAVE__STRNICMP)
155 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
158 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
161 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
162 IF(NOT HAVE_SNPRINTF)
163 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
164 IF(NOT HAVE__SNPRINTF)
165 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
168 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
171 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
172 IF(NOT HAVE_VSNPRINTF)
173 CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
174 IF(NOT HAVE__VSNPRINTF)
175 MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
178 ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
181 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
183 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
185 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
188 ADD_DEFINITIONS(-Disnan=_isnan)
192 # Check for the dlopen API (for dynamicly loading backend libs)
194 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
196 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
198 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
203 # Check if we have Windows headers
204 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
205 IF(NOT HAVE_WINDOWS_H)
206 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
207 IF(NOT HAVE_GETTIMEOFDAY)
208 MESSAGE(FATAL_ERROR "No timing function found!")
211 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
212 IF(NOT HAVE_NANOSLEEP)
213 MESSAGE(FATAL_ERROR "No sleep function found!")
216 # We need pthreads outside of Windows
217 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
218 IF(NOT HAVE_PTHREAD_H)
219 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
222 # Some systems need pthread_np.h to get recursive mutexes
223 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
225 # _GNU_SOURCE is needed on some systems for extra attributes, and
226 # _REENTRANT is needed for libc thread-safety
227 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
228 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
230 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
234 # Check for a 64-bit type
235 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
236 IF(NOT HAVE_STDINT_H)
238 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
239 \#include <windows.h>
241 int main() {return 0;}" HAVE___INT64)
244 IF(NOT SIZEOF_LONG MATCHES "8")
245 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
246 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
253 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
255 OpenAL32/alDatabuffer.c
258 OpenAL32/alExtension.c
260 OpenAL32/alListener.c
265 SET(ALC_OBJS Alc/ALc.c
280 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
281 IF(HAVE_ALSA_ASOUNDLIB_H)
282 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
283 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
285 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
287 SET(BACKENDS "${BACKENDS} ALSA,")
289 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
290 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
298 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
299 IF(HAVE_SYS_SOUNDCARD_H)
301 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
302 SET(BACKENDS "${BACKENDS} OSS,")
306 # Check Solaris backend
308 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
309 IF(HAVE_SYS_AUDIOIO_H)
311 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
312 SET(BACKENDS "${BACKENDS} Solaris,")
316 # Check DSound/MMSystem backend
318 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
320 CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
321 IF(HAVE_LIBDSOUND OR WIN32)
323 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
326 SET(BACKENDS "${BACKENDS} DirectSound,")
328 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
329 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
336 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
339 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
340 SET(BACKENDS "${BACKENDS} WinMM,")
342 SET(CMAKE_REQUIRED_LIBRARIES winmm)
343 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
344 SET(CMAKE_REQUIRED_LIBRARIES "")
345 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
347 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
353 # Check PortAudio backend
355 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
357 CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
358 IF(HAVE_LIBPORTAUDIO)
359 SET(HAVE_PORTAUDIO 1)
360 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
362 SET(BACKENDS "${BACKENDS} PortAudio,")
364 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
365 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
371 # Check PortAudio backend
373 CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
374 IF(HAVE_PULSE_PULSEAUDIO_H)
375 CHECK_LIBRARY_EXISTS(pulse pa_context_new "" HAVE_LIBPULSE)
377 SET(HAVE_PULSEAUDIO 1)
378 SET(ALC_OBJS ${ALC_OBJS} Alc/pulseaudio.c)
380 SET(BACKENDS "${BACKENDS} PulseAudio,")
382 SET(BACKENDS "${BACKENDS} PulseAudio \(linked\),")
383 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
389 # This is always available
390 SET(BACKENDS "${BACKENDS} WaveFile")
392 # Needed for openal.pc.in
393 SET(prefix ${CMAKE_INSTALL_PREFIX})
394 SET(exec_prefix "\${prefix}")
395 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
396 SET(bindir "\${exec_prefix}/bin")
397 SET(includedir "\${prefix}/include")
398 SET(PACKAGE_VERSION "${LIB_VERSION}")
402 "${OpenAL_SOURCE_DIR}/config.h.in"
403 "${OpenAL_BINARY_DIR}/config.h")
405 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
406 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
409 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
415 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
416 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
417 SOVERSION ${LIB_MAJOR_VERSION})
419 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
422 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
424 # Add an install target here
425 INSTALL(TARGETS ${LIBNAME}
426 RUNTIME DESTINATION bin
427 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
428 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
430 INSTALL(FILES include/AL/al.h
433 DESTINATION include/AL
435 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
436 DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
438 # Install alsoft.conf configuration file
440 INSTALL(FILES alsoftrc.sample
441 DESTINATION /etc/openal
447 ADD_EXECUTABLE(openal-info examples/openal-info.c)
448 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
449 INSTALL(TARGETS openal-info
450 RUNTIME DESTINATION bin
451 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
452 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
457 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
458 MESSAGE(STATUS " ${BACKENDS}")
463 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
464 MESSAGE(STATUS " This is probably NOT what you want!")