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)
30 OPTION(PULSEAUDIO "Check for PulseAudio backend" ON)
32 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
34 OPTION(WERROR "Treat compile warnings as errors" OFF)
36 OPTION(EXAMPLES "Build example programs" ON)
38 OPTION(ALSOFT_CONFIG "Install alsoft.conf configuration file" OFF)
43 ADD_DEFINITIONS("-D_WIN32")
48 SET(LIB_MAJOR_VERSION "1")
49 SET(LIB_MINOR_VERSION "7")
50 SET(LIB_BUILD_VERSION "411")
51 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
52 IF(NOT DEFINED LIB_INSTALL_DIR)
53 SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
54 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
57 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
58 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
59 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
60 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
63 # Add definitions, compiler switches, etc.
64 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
66 IF(NOT CMAKE_BUILD_TYPE)
67 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
68 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
71 IF(NOT CMAKE_DEBUG_POSTFIX)
72 SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
73 "Library postfix for debug builds. Normally left blank."
79 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
80 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
81 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
82 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
83 ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
85 ADD_DEFINITIONS(-Wall)
86 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
88 ADD_DEFINITIONS(-Wextra)
92 ADD_DEFINITIONS(-Werror)
95 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
96 "Flags used by the compiler during Release with Debug Info builds."
98 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
99 "Flags used by the compiler during release minsize builds."
101 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
102 "Flags used by the compiler during release builds"
104 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
105 "Flags used by the compiler during debug builds."
108 # Set visibility options if available
110 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
111 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
113 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
114 IF(HAVE_VISIBILITY_SWITCH)
115 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
116 int main() {return 0;}" HAVE_GCC_VISIBILITY)
117 IF(HAVE_GCC_VISIBILITY)
118 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
124 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
125 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
127 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
128 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
129 CHECK_LIBRARY_EXISTS(m atanf "" HAVE_ATANF)
130 CHECK_LIBRARY_EXISTS(m fabsf "" HAVE_FABSF)
132 CHECK_LIBRARY_EXISTS(m fesetround "" HAVE_FESETROUND)
134 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
135 SET(EXTRA_LIBS m ${EXTRA_LIBS})
137 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
138 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
140 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
141 IF(NOT HAVE_STRCASECMP)
142 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
143 IF(NOT HAVE__STRICMP)
144 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
147 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
150 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
151 IF(NOT HAVE_STRNCASECMP)
152 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
153 IF(NOT HAVE__STRNICMP)
154 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
157 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
160 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
161 IF(NOT HAVE_SNPRINTF)
162 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
163 IF(NOT HAVE__SNPRINTF)
164 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
167 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
170 # Check for the dlopen API (for dynamicly loading backend libs)
172 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
174 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
176 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
181 # Check if we have Windows headers
182 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
183 IF(NOT HAVE_WINDOWS_H)
184 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
185 IF(NOT HAVE_GETTIMEOFDAY)
186 MESSAGE(FATAL_ERROR "No timing function found!")
189 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
190 IF(NOT HAVE_NANOSLEEP)
191 MESSAGE(FATAL_ERROR "No sleep function found!")
194 # We need pthreads outside of Windows
195 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
196 IF(NOT HAVE_PTHREAD_H)
197 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
200 # Some systems need pthread_np.h to get recursive mutexes
201 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
203 # _GNU_SOURCE is needed on some systems for extra attributes, and
204 # _REENTRANT is needed for libc thread-safety
205 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
206 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
208 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
212 # Check for a 64-bit type
213 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
214 IF(NOT HAVE_STDINT_H)
216 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
217 \#include <windows.h>
219 int main() {return 0;}" HAVE___INT64)
222 IF(NOT SIZEOF_LONG MATCHES "8")
223 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
224 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
231 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
235 OpenAL32/alExtension.c
237 OpenAL32/alListener.c
242 SET(ALC_OBJS Alc/ALc.c
257 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
258 IF(HAVE_ALSA_ASOUNDLIB_H)
259 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
260 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
262 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
264 SET(BACKENDS "${BACKENDS} ALSA,")
266 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
267 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
275 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
276 IF(HAVE_SYS_SOUNDCARD_H)
278 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
279 SET(BACKENDS "${BACKENDS} OSS,")
283 # Check Solaris backend
285 CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
286 IF(HAVE_SYS_AUDIOIO_H)
288 SET(ALC_OBJS ${ALC_OBJS} Alc/solaris.c)
289 SET(BACKENDS "${BACKENDS} Solaris,")
293 # Check DSound/MMSystem backend
295 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
297 CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
298 IF(HAVE_LIBDSOUND OR WIN32)
300 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
303 SET(BACKENDS "${BACKENDS} DirectSound,")
305 SET(BACKENDS "${BACKENDS} DirectSound \(linked\),")
306 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
313 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
316 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
317 SET(BACKENDS "${BACKENDS} WinMM,")
319 SET(CMAKE_REQUIRED_LIBRARIES winmm)
320 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
321 SET(CMAKE_REQUIRED_LIBRARIES "")
322 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
324 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
330 # Check PortAudio backend
332 CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
334 CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
335 IF(HAVE_LIBPORTAUDIO)
336 SET(HAVE_PORTAUDIO 1)
337 SET(ALC_OBJS ${ALC_OBJS} Alc/portaudio.c)
339 SET(BACKENDS "${BACKENDS} PortAudio,")
341 SET(BACKENDS "${BACKENDS} PortAudio \(linked\),")
342 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
348 # Check PortAudio backend
350 CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
351 IF(HAVE_PULSE_PULSEAUDIO_H)
352 CHECK_LIBRARY_EXISTS(pulse pa_context_new "" HAVE_LIBPULSE)
354 SET(HAVE_PULSEAUDIO 1)
355 SET(ALC_OBJS ${ALC_OBJS} Alc/pulseaudio.c)
357 SET(BACKENDS "${BACKENDS} PulseAudio,")
359 SET(BACKENDS "${BACKENDS} PulseAudio \(linked\),")
360 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
366 # This is always available
367 SET(BACKENDS "${BACKENDS} WaveFile")
369 # Needed for openal.pc.in
370 SET(prefix ${CMAKE_INSTALL_PREFIX})
371 SET(exec_prefix "\${prefix}")
372 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
373 SET(bindir "\${exec_prefix}/bin")
374 SET(includedir "\${prefix}/include")
375 SET(PACKAGE_VERSION "${LIB_VERSION}")
379 "${OpenAL_SOURCE_DIR}/config.h.in"
380 "${OpenAL_BINARY_DIR}/config.h")
382 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
383 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
386 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
392 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
393 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
394 SOVERSION ${LIB_MAJOR_VERSION})
396 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
399 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
401 # Add an install target here
402 INSTALL(TARGETS ${LIBNAME}
403 RUNTIME DESTINATION bin
404 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
405 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
407 INSTALL(FILES include/AL/al.h
410 DESTINATION include/AL
412 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
413 DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
415 # Install alsoft.conf configuration file
417 INSTALL(FILES alsoftrc.sample
418 DESTINATION /etc/openal
424 ADD_EXECUTABLE(openal-info examples/openal-info.c)
425 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
426 INSTALL(TARGETS openal-info
427 RUNTIME DESTINATION bin
428 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
429 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
434 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
435 MESSAGE(STATUS " ${BACKENDS}")
440 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
441 MESSAGE(STATUS " This is probably NOT what you want!")