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 "10")
51 SET(LIB_BUILD_VERSION "622")
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."
79 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
81 STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
84 MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
85 SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
86 INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
87 LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
92 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
93 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
94 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
95 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
96 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
98 ADD_DEFINITIONS(-Wall)
99 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
101 ADD_DEFINITIONS(-Wextra)
105 ADD_DEFINITIONS(-Werror)
108 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
109 "Flags used by the compiler during Release with Debug Info builds."
111 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
112 "Flags used by the compiler during release minsize builds."
114 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
115 "Flags used by the compiler during release builds"
117 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
118 "Flags used by the compiler during debug builds."
121 # Set visibility options if available
123 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
124 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
126 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
127 IF(HAVE_VISIBILITY_SWITCH)
128 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
129 int main() {return 0;}" HAVE_GCC_VISIBILITY)
130 IF(HAVE_GCC_VISIBILITY)
131 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
137 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
138 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
140 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
141 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
142 CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
143 CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
145 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
147 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
148 SET(EXTRA_LIBS m ${EXTRA_LIBS})
150 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
151 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
153 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
154 IF(NOT HAVE_STRCASECMP)
155 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
156 IF(NOT HAVE__STRICMP)
157 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
160 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
163 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
164 IF(NOT HAVE_STRNCASECMP)
165 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
166 IF(NOT HAVE__STRNICMP)
167 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
170 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
173 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
174 IF(NOT HAVE_SNPRINTF)
175 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
176 IF(NOT HAVE__SNPRINTF)
177 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
180 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
183 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
184 IF(NOT HAVE_VSNPRINTF)
185 CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
186 IF(NOT HAVE__VSNPRINTF)
187 MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
190 ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
193 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
195 CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
197 MESSAGE(FATAL_ERROR "No isnan function found, please report!")
200 ADD_DEFINITIONS(-Disnan=_isnan)
204 # Check for the dlopen API (for dynamicly loading backend libs)
206 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
208 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
210 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
215 # Check if we have Windows headers
216 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
217 IF(NOT HAVE_WINDOWS_H)
218 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
219 IF(NOT HAVE_GETTIMEOFDAY)
220 MESSAGE(FATAL_ERROR "No timing function found!")
223 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
224 IF(NOT HAVE_NANOSLEEP)
225 MESSAGE(FATAL_ERROR "No sleep function found!")
228 CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
230 ADD_DEFINITIONS(-pthread)
231 SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
234 # We need pthreads outside of Windows
235 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
236 IF(NOT HAVE_PTHREAD_H)
237 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
239 # Some systems need pthread_np.h to get recursive mutexes
240 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
242 # _GNU_SOURCE is needed on some systems for extra attributes, and
243 # _REENTRANT is needed for libc thread-safety
244 ADD_DEFINITIONS(-D_GNU_SOURCE=1)
245 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
247 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
250 CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
252 SET(EXTRA_LIBS rt ${EXTRA_LIBS})
256 # Check for a 64-bit type
257 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
258 IF(NOT HAVE_STDINT_H)
260 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
261 \#include <windows.h>
263 int main() {return 0;}" HAVE___INT64)
266 IF(NOT SIZEOF_LONG MATCHES "8")
267 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
268 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
275 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
277 OpenAL32/alDatabuffer.c
280 OpenAL32/alExtension.c
282 OpenAL32/alListener.c
287 SET(ALC_OBJS Alc/ALc.c
302 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
303 IF(HAVE_ALSA_ASOUNDLIB_H)
304 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
305 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
307 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
309 SET(BACKENDS "${BACKENDS} ALSA,")
311 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
312 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
320 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
321 IF(HAVE_SYS_SOUNDCARD_H)
323 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
324 SET(BACKENDS "${BACKENDS} OSS,")
328 # Check Solaris backend
330 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
331 IF(HAVE_SYS_AUDIOIO_H)
333 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
334 SET(BACKENDS "${BACKENDS} Solaris,")
338 # Check DSound/MMSystem backend
340 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
342 CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
343 IF(HAVE_LIBDSOUND OR WIN32)
345 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
348 SET(BACKENDS "${BACKENDS} DirectSound,")
350 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
351 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
358 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
361 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
362 SET(BACKENDS "${BACKENDS} WinMM,")
364 SET(CMAKE_REQUIRED_LIBRARIES winmm)
365 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
366 SET(CMAKE_REQUIRED_LIBRARIES "")
367 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
369 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
375 # Check PortAudio backend
377 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
379 CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
380 IF(HAVE_LIBPORTAUDIO)
381 SET(HAVE_PORTAUDIO 1)
382 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
384 SET(BACKENDS "${BACKENDS} PortAudio,")
386 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
387 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
393 # Check PortAudio backend
395 CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
396 IF(HAVE_PULSE_PULSEAUDIO_H)
397 CHECK_LIBRARY_EXISTS(pulse pa_context_new "" HAVE_LIBPULSE)
399 SET(HAVE_PULSEAUDIO 1)
400 SET(ALC_OBJS ${ALC_OBJS} Alc/pulseaudio.c)
402 SET(BACKENDS "${BACKENDS} PulseAudio,")
404 SET(BACKENDS "${BACKENDS} PulseAudio \(linked\),")
405 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
411 # This is always available
412 SET(BACKENDS "${BACKENDS} WaveFile")
414 # Needed for openal.pc.in
415 SET(prefix ${CMAKE_INSTALL_PREFIX})
416 SET(exec_prefix "\${prefix}")
417 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
418 SET(bindir "\${exec_prefix}/bin")
419 SET(includedir "\${prefix}/include")
420 SET(PACKAGE_VERSION "${LIB_VERSION}")
424 "${OpenAL_SOURCE_DIR}/config.h.in"
425 "${OpenAL_BINARY_DIR}/config.h")
427 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
428 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
431 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
437 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
438 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
439 SOVERSION ${LIB_MAJOR_VERSION})
441 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
444 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
446 # Add an install target here
447 INSTALL(TARGETS ${LIBNAME}
448 RUNTIME DESTINATION bin
449 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
450 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
452 INSTALL(FILES include/AL/al.h
455 DESTINATION include/AL
457 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
458 DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
460 # Install alsoft.conf configuration file
462 INSTALL(FILES alsoftrc.sample
463 DESTINATION /etc/openal
469 ADD_EXECUTABLE(openal-info examples/openal-info.c)
470 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
471 INSTALL(TARGETS openal-info
472 RUNTIME DESTINATION bin
473 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
474 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
479 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
480 MESSAGE(STATUS " ${BACKENDS}")
485 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
486 MESSAGE(STATUS " This is probably NOT what you want!")