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 "Check for ALSA backend" ON)
19 OPTION(OSS "Check for OSS backend" ON)
20 OPTION(DSOUND "Check for DirectSound backend" ON)
21 OPTION(WINMM "Check for Windows Multimedia backend" ON)
23 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
25 OPTION(WERROR "Treat compile warnings as errors" OFF)
27 OPTION(EXAMPLES "Build example programs" ON)
30 SET(LIB_MAJOR_VERSION "1")
31 SET(LIB_MINOR_VERSION "4")
32 SET(LIB_BUILD_VERSION "272")
33 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
34 IF(NOT DEFINED LIB_INSTALL_DIR)
35 SET(LIB_INSTALL_DIR "lib")
36 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
39 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
40 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
41 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
42 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
45 # Add definitions, compiler switches, etc.
46 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
48 IF(NOT CMAKE_BUILD_TYPE)
49 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
50 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
56 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
57 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
58 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
59 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
61 ADD_DEFINITIONS(-Wall)
62 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
64 ADD_DEFINITIONS(-Wextra)
68 ADD_DEFINITIONS(-Werror)
71 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
72 "Flags used by the compiler during Release with Debug Info builds."
74 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
75 "Flags used by the compiler during release minsize builds."
77 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
78 "Flags used by the compiler during release builds"
80 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
81 "Flags used by the compiler during debug builds."
84 # Set visibility options if available
86 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
87 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
89 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
90 IF("${HAVE_VISIBILITY_SWITCH}")
91 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
92 int main() {return 0;}" HAVE_GCC_VISIBILITY)
93 IF("${HAVE_GCC_VISIBILITY}")
94 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
101 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
102 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
103 IF(HAVE_SQRTF OR HAVE_ACOSF)
104 SET(EXTRA_LIBS m ${EXTRA_LIBS})
106 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
108 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
109 IF(NOT HAVE_STRCASECMP)
110 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
111 IF(NOT HAVE__STRICMP)
112 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
115 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
118 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
119 IF(NOT HAVE_STRNCASECMP)
120 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
121 IF(NOT HAVE__STRNICMP)
122 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
125 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
128 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
129 IF(NOT HAVE_SNPRINTF)
130 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
131 IF(NOT HAVE__SNPRINTF)
132 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
135 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
138 # Check for the dlopen API (for dynamicly loading backend libs)
140 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
142 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
144 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
149 # Check if we have Windows headers
150 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
151 IF(NOT HAVE_WINDOWS_H)
152 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
153 IF(NOT HAVE_GETTIMEOFDAY)
154 MESSAGE(FATAL_ERROR "No timing function found!")
157 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
158 IF(NOT HAVE_NANOSLEEP)
159 MESSAGE(FATAL_ERROR "No sleep function found!")
162 # We need pthreads outside of Windows
163 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
164 IF(NOT HAVE_PTHREAD_H)
165 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
168 # Some systems need pthread_np.h to get recursive mutexes
169 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
171 # _GNU_SOURCE is needed on some systems for extra attributes, and
172 # _REENTRANT is needed for libc thread-safety
173 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
174 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
176 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
180 # Check for a 64-bit type
181 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
182 IF(NOT HAVE_STDINT_H)
184 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
185 \#include <windows.h>
187 int main() {return 0;}" HAVE___INT64)
190 IF(NOT SIZEOF_LONG MATCHES "8")
191 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
192 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
199 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
203 OpenAL32/alExtension.c
205 OpenAL32/alListener.c
211 SET(ALC_OBJS Alc/ALc.c
224 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
225 IF(HAVE_ALSA_ASOUNDLIB_H)
226 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
227 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
229 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
231 SET(BACKENDS "${BACKENDS} ALSA,")
233 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
234 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
242 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
243 IF(HAVE_SYS_SOUNDCARD_H)
245 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
246 SET(BACKENDS "${BACKENDS} OSS,")
250 # Check DSound/MMSystem backend
253 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
256 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
257 SET(BACKENDS "${BACKENDS} DirectSound,")
259 SET(CMAKE_REQUIRED_LIBRARIES dsound)
260 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBDSOUND)
261 SET(CMAKE_REQUIRED_LIBRARIES "")
262 # CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
264 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
269 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
272 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
273 SET(BACKENDS "${BACKENDS} WinMM,")
275 SET(CMAKE_REQUIRED_LIBRARIES winmm)
276 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
277 SET(CMAKE_REQUIRED_LIBRARIES "")
278 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
280 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
286 # This is always available
287 SET(BACKENDS "${BACKENDS} WaveFile")
291 "${OpenAL_SOURCE_DIR}/config.h.in"
292 "${OpenAL_BINARY_DIR}/config.h")
294 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
296 # Build a shared library
298 SET(LIBNAME openal32)
303 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
304 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
305 SOVERSION ${LIB_MAJOR_VERSION})
307 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
310 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
312 # Add an install target here
313 INSTALL(TARGETS ${LIBNAME}
314 RUNTIME DESTINATION bin
315 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
316 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
318 INSTALL(FILES include/AL/al.h
321 DESTINATION include/AL
325 ADD_EXECUTABLE(openal-info examples/openal-info.c)
326 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
327 INSTALL(TARGETS openal-info
328 RUNTIME DESTINATION bin
329 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
330 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
335 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
336 MESSAGE(STATUS " ${BACKENDS}")