1 # CMake build file list for OpenAL
3 INCLUDE(CheckFunctionExists)
4 INCLUDE(CheckLibraryExists)
5 INCLUDE(CheckIncludeFile)
6 INCLUDE(CheckIncludeFiles)
7 INCLUDE(CheckCCompilerFlag)
8 INCLUDE(CheckCSourceCompiles)
15 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
18 OPTION(ALSA "ALSA backend" ON)
19 OPTION(OSS "OSS backend" ON)
20 OPTION(DSOUND "DirectSound backend" ON)
21 OPTION(WINMM "Windows Multimedia backend" ON)
23 OPTION(DLOPEN "Use the dlopen API for loading optional libs" ON)
25 OPTION(DEBUG "Build lib in debug mode" OFF)
26 OPTION(NODEBUG "Disable all debug info for optimizations" OFF)
27 OPTION(WERROR "Treat compile warnings as errors" OFF)
30 SET(LIB_MAJOR_VERSION "1")
31 SET(LIB_MINOR_VERSION "0")
32 SET(LIB_BUILD_VERSION "38")
33 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
36 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
37 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
38 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
39 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
42 # Add definitions, compiler switches, etc.
43 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
48 ADD_DEFINITIONS(-Wall)
49 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
51 ADD_DEFINITIONS(-Wextra)
55 ADD_DEFINITIONS(-Werror)
61 ADD_DEFINITIONS(-O2 -funroll-loops -fomit-frame-pointer)
63 ADD_DEFINITIONS(-g -O2 -funroll-loops)
66 # The mixer doesn't like GCC's strict aliasing optimizations. Make sure
68 CHECK_C_COMPILER_FLAG(-fstrict-aliasing HAVE_STRICT_ALIASING)
69 IF("${HAVE_STRICT_ALIASING}")
70 ADD_DEFINITIONS(-fno-strict-aliasing)
73 # Set visibility options if available
75 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
76 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
78 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
79 IF("${HAVE_VISIBILITY_SWITCH}")
80 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
81 int main() {return 0;}" HAVE_GCC_VISIBILITY)
82 IF("${HAVE_GCC_VISIBILITY}")
83 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
90 ADD_DEFINITIONS(-D_DEBUG)
92 ADD_DEFINITIONS(-DNDEBUG)
95 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
97 SET(EXTRA_LIBS m ${EXTRA_LIBS})
99 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
101 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
102 IF(NOT "${HAVE_STRCASECMP}")
103 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
104 IF(NOT "${HAVE__STRICMP}")
105 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
108 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
111 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
112 IF(NOT "${HAVE_SNPRINTF}")
113 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
114 IF(NOT "${HAVE__SNPRINTF}")
115 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
118 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
121 # Check for the dlopen API (for dynamicly loading backend libs)
123 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
124 IF("${HAVE_DLFCN_H}")
125 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
127 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
132 # Check if we have Windows headers
133 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
134 IF(NOT "${HAVE_WINDOWS_H}")
135 # We need pthreads outside of Windows
136 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
137 IF(NOT "${HAVE_PTHREAD_H}")
138 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
141 # _GNU_SOURCE is needed on some systems for extra attributes, and
142 # _REENTRANT is needed for libc thread-safety
143 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
144 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
145 IF("${HAVE_LIBPTHREAD}")
146 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
150 # Check for a 64-bit type
151 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
152 IF(NOT "${HAVE_STDINT_H}")
153 IF("${HAVE_WINDOWS_H}")
154 CHECK_C_SOURCE_COMPILES("\#include <windows.h>
156 int main() {return 0;}" HAVE___INT64)
158 IF(NOT "${HAVE___INT64}")
159 IF(NOT "${SIZEOF_LONG}" MATCHES "8")
160 IF(NOT "${SIZEOF_LONG_LONG}" MATCHES "8")
161 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
168 SET(OPENAL_OBJS OpenAL32/alBuffer.c
170 OpenAL32/alExtension.c
171 OpenAL32/alListener.c
177 SET(ALC_OBJS Alc/ALc.c
188 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
189 IF("${HAVE_ALSA_ASOUNDLIB_H}")
190 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
191 IF("${HAVE_DLFCN_H}" OR "${HAVE_LIBASOUND}")
193 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
194 IF("${HAVE_DLFCN_H}")
195 SET(BACKENDS ${BACKENDS} ALSA)
197 SET(BACKENDS ${BACKENDS} ALSA\(linked\))
198 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
206 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
207 IF("${HAVE_SYS_SOUNDCARD_H}")
209 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
210 SET(BACKENDS ${BACKENDS} OSS)
214 # Check DSound/MMSystem backend
215 IF("${HAVE_WINDOWS_H}")
216 SET(CMAKE_REQUIRED_LIBRARIES ole32)
217 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBOLE32)
218 SET(CMAKE_REQUIRED_LIBRARIES "")
219 # CHECK_LIBRARY_EXISTS(ole32 CoInitialize "" HAVE_LIBOLE32)
220 IF("${HAVE_LIBOLE32}")
221 SET(EXTRA_LIBS ole32 ${EXTRA_LIBS})
225 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
226 IF("${HAVE_DSOUND_H}")
228 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
229 SET(BACKENDS ${BACKENDS} DirectSound)
231 CHECK_LIBRARY_EXISTS(dxguid IID_IDirectSound "" HAVE_LIBDXGUID)
232 IF("${HAVE_LIBDXGUID}")
233 SET(EXTRA_LIBS dxguid ${EXTRA_LIBS})
238 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
239 IF("${HAVE_MMSYSTEM_H}")
241 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
242 SET(BACKENDS ${BACKENDS} WinMM)
244 SET(CMAKE_REQUIRED_LIBRARIES winmm)
245 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
246 SET(CMAKE_REQUIRED_LIBRARIES "")
247 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
248 IF("${HAVE_LIBWINMM}")
249 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
257 "${OpenAL_SOURCE_DIR}/config.h.in"
258 "${OpenAL_BINARY_DIR}/config.h")
260 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
262 # Build a shared library
264 SET(LIBNAME openal32)
269 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
270 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
271 SOVERSION ${LIB_MAJOR_VERSION})
273 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
276 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
278 # Add an install target here
279 INSTALL(TARGETS ${LIBNAME}
280 RUNTIME DESTINATION bin
281 LIBRARY DESTINATION lib
282 ARCHIVE DESTINATION lib
284 INSTALL(FILES include/AL/al.h
286 DESTINATION include/AL
290 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
291 MESSAGE(STATUS " ${BACKENDS}")