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}")
43 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
44 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
45 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
46 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
49 # Add definitions, compiler switches, etc.
50 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
51 SET(EXTRA_LIBS m ${EXTRA_LIBS})
56 ADD_DEFINITIONS(-Wall)
57 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
59 ADD_DEFINITIONS(-Wextra)
63 ADD_DEFINITIONS(-Werror)
69 ADD_DEFINITIONS(-O2 -funroll-loops -fomit-frame-pointer)
71 ADD_DEFINITIONS(-g -O2 -funroll-loops)
74 # The mixer doesn't like GCC's strict aliasing optimizations. Make sure
76 CHECK_C_COMPILER_FLAG(-fstrict-aliasing HAVE_STRICT_ALIASING)
77 IF("${HAVE_STRICT_ALIASING}")
78 ADD_DEFINITIONS(-fno-strict-aliasing)
81 # Set visibility options if available
83 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
84 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
86 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
87 IF("${HAVE_VISIBILITY_SWITCH}")
88 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
89 int main() {return 0;}" HAVE_GCC_VISIBILITY)
90 IF("${HAVE_GCC_VISIBILITY}")
91 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
98 ADD_DEFINITIONS(-D_DEBUG)
100 ADD_DEFINITIONS(-DNDEBUG)
103 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
104 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
106 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
107 IF(NOT "${HAVE_STRCASECMP}")
108 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
109 IF(NOT "${HAVE__STRICMP}")
110 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
113 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
116 # Check for the dlopen API (for dynamicly loading backend libs)
118 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
119 IF("${HAVE_DLFCN_H}")
120 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
122 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
127 # Check if we have Windows headers
128 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
129 IF(NOT "${HAVE_WINDOWS_H}")
130 # We need pthreads outside of Windows
131 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
132 IF(NOT "${HAVE_PTHREAD_H}")
133 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
136 # _GNU_SOURCE is needed on some systems for extra attributes, and
137 # _REENTRANT is needed for libc thread-safety
138 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
139 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
140 IF("${HAVE_LIBPTHREAD}")
141 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
145 # Check for a 64-bit type
146 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
147 IF(NOT "${HAVE_STDINT_H}")
148 IF("${HAVE_WINDOWS_H}")
149 CHECK_C_SOURCE_COMPILES("\#include <windows.h>
151 int main() {return 0;}" HAVE___INT64)
153 IF(NOT "${HAVE___INT64}")
154 IF(NOT "${SIZEOF_LONG}" MATCHES "8")
155 IF(NOT "${SIZEOF_LONG_LONG}" MATCHES "8")
156 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
163 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
167 OpenAL32/alExtension.c
169 OpenAL32/alListener.c
175 SET(ALC_OBJS Alc/ALc.c
186 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
187 IF("${HAVE_ALSA_ASOUNDLIB_H}")
188 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
189 IF("${HAVE_DLFCN_H}" OR "${HAVE_LIBASOUND}")
191 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
192 IF("${HAVE_DLFCN_H}")
193 SET(BACKENDS ${BACKENDS} ALSA)
195 SET(BACKENDS ${BACKENDS} ALSA\(linked\))
196 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
204 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
205 IF("${HAVE_SYS_SOUNDCARD_H}")
207 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
208 SET(BACKENDS ${BACKENDS} OSS)
212 # Check DSound/MMSystem backend
213 IF("${HAVE_WINDOWS_H}")
214 SET(CMAKE_REQUIRED_LIBRARIES ole32)
215 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBOLE32)
216 SET(CMAKE_REQUIRED_LIBRARIES "")
217 # CHECK_LIBRARY_EXISTS(ole32 CoInitialize "" HAVE_LIBOLE32)
218 IF("${HAVE_LIBOLE32}")
219 SET(EXTRA_LIBS ole32 ${EXTRA_LIBS})
223 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
224 IF("${HAVE_DSOUND_H}")
226 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
227 SET(BACKENDS ${BACKENDS} DirectSound)
229 CHECK_LIBRARY_EXISTS(dxguid IID_IDirectSound "" HAVE_LIBDXGUID)
230 IF("${HAVE_LIBDXGUID}")
231 SET(EXTRA_LIBS dxguid ${EXTRA_LIBS})
236 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
237 IF("${HAVE_MMSYSTEM_H}")
239 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
240 SET(BACKENDS ${BACKENDS} WinMM)
242 SET(CMAKE_REQUIRED_LIBRARIES winmm)
243 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
244 SET(CMAKE_REQUIRED_LIBRARIES "")
245 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
246 IF("${HAVE_LIBWINMM}")
247 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
255 "${OpenAL_SOURCE_DIR}/config.h.in"
256 "${OpenAL_BINARY_DIR}/config.h")
258 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
260 # Build a shared library
261 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
262 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION})
264 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
266 # Add an install target here
267 INSTALL(TARGETS ${LIBNAME}
268 RUNTIME DESTINATION bin
269 LIBRARY DESTINATION lib
270 ARCHIVE DESTINATION lib
272 INSTALL(FILES include/AL/al.h
274 DESTINATION include/AL
278 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
279 MESSAGE(STATUS " ${BACKENDS}")