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(DSOUND "Check for DirectSound backend" ON)
27 OPTION(WINMM "Check for Windows Multimedia backend" ON)
29 OPTION(DLOPEN "Check for the dlopen API for loading optional libs" ON)
31 OPTION(WERROR "Treat compile warnings as errors" OFF)
33 OPTION(EXAMPLES "Build example programs" ON)
42 SET(LIB_MAJOR_VERSION "1")
43 SET(LIB_MINOR_VERSION "4")
44 SET(LIB_BUILD_VERSION "272")
45 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
46 IF(NOT DEFINED LIB_INSTALL_DIR)
47 SET(LIB_INSTALL_DIR "lib")
48 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
51 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
52 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
53 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
54 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
57 # Add definitions, compiler switches, etc.
58 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
60 IF(NOT CMAKE_BUILD_TYPE)
61 SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
62 "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
68 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
69 SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
70 SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
71 SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
73 ADD_DEFINITIONS(-Wall)
74 CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
76 ADD_DEFINITIONS(-Wextra)
80 ADD_DEFINITIONS(-Werror)
83 SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
84 "Flags used by the compiler during Release with Debug Info builds."
86 SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
87 "Flags used by the compiler during release minsize builds."
89 SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
90 "Flags used by the compiler during release builds"
92 SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
93 "Flags used by the compiler during debug builds."
96 # Set visibility options if available
98 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
99 int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
101 CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
102 IF("${HAVE_VISIBILITY_SWITCH}")
103 CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
104 int main() {return 0;}" HAVE_GCC_VISIBILITY)
105 IF("${HAVE_GCC_VISIBILITY}")
106 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
113 CHECK_LIBRARY_EXISTS(m sqrtf "" HAVE_SQRTF)
114 CHECK_LIBRARY_EXISTS(m acosf "" HAVE_ACOSF)
115 IF(HAVE_SQRTF OR HAVE_ACOSF)
116 SET(EXTRA_LIBS m ${EXTRA_LIBS})
118 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
120 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
121 IF(NOT HAVE_STRCASECMP)
122 CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
123 IF(NOT HAVE__STRICMP)
124 MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
127 ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
130 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
131 IF(NOT HAVE_STRNCASECMP)
132 CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
133 IF(NOT HAVE__STRNICMP)
134 MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
137 ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
140 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
141 IF(NOT HAVE_SNPRINTF)
142 CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
143 IF(NOT HAVE__SNPRINTF)
144 MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
147 ADD_DEFINITIONS(-Dsnprintf=_snprintf)
150 # Check for the dlopen API (for dynamicly loading backend libs)
152 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
154 CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
156 SET(EXTRA_LIBS dl ${EXTRA_LIBS})
161 # Check if we have Windows headers
162 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
163 IF(NOT HAVE_WINDOWS_H)
164 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
165 IF(NOT HAVE_GETTIMEOFDAY)
166 MESSAGE(FATAL_ERROR "No timing function found!")
169 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
170 IF(NOT HAVE_NANOSLEEP)
171 MESSAGE(FATAL_ERROR "No sleep function found!")
174 # We need pthreads outside of Windows
175 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
176 IF(NOT HAVE_PTHREAD_H)
177 MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
180 # Some systems need pthread_np.h to get recursive mutexes
181 CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
183 # _GNU_SOURCE is needed on some systems for extra attributes, and
184 # _REENTRANT is needed for libc thread-safety
185 ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
186 CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
188 SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
192 # Check for a 64-bit type
193 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
194 IF(NOT HAVE_STDINT_H)
196 CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
197 \#include <windows.h>
199 int main() {return 0;}" HAVE___INT64)
202 IF(NOT SIZEOF_LONG MATCHES "8")
203 IF(NOT SIZEOF_LONG_LONG MATCHES "8")
204 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
211 SET(OPENAL_OBJS OpenAL32/alAuxEffectSlot.c
215 OpenAL32/alExtension.c
217 OpenAL32/alListener.c
222 SET(ALC_OBJS Alc/ALc.c
235 CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
236 IF(HAVE_ALSA_ASOUNDLIB_H)
237 CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
238 IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
240 SET(ALC_OBJS ${ALC_OBJS} Alc/alsa.c)
242 SET(BACKENDS "${BACKENDS} ALSA,")
244 SET(BACKENDS "${BACKENDS} ALSA \(linked\),")
245 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
253 CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
254 IF(HAVE_SYS_SOUNDCARD_H)
256 SET(ALC_OBJS ${ALC_OBJS} Alc/oss.c)
257 SET(BACKENDS "${BACKENDS} OSS,")
261 # Check DSound/MMSystem backend
264 CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
267 SET(ALC_OBJS ${ALC_OBJS} Alc/dsound.c)
268 SET(BACKENDS "${BACKENDS} DirectSound,")
270 SET(CMAKE_REQUIRED_LIBRARIES dsound)
271 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBDSOUND)
272 SET(CMAKE_REQUIRED_LIBRARIES "")
273 # CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
275 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
280 CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
283 SET(ALC_OBJS ${ALC_OBJS} Alc/winmm.c)
284 SET(BACKENDS "${BACKENDS} WinMM,")
286 SET(CMAKE_REQUIRED_LIBRARIES winmm)
287 CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
288 SET(CMAKE_REQUIRED_LIBRARIES "")
289 # CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
291 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
297 # This is always available
298 SET(BACKENDS "${BACKENDS} WaveFile")
300 # Needed for openal.pc.in
301 SET(prefix ${CMAKE_INSTALL_PREFIX})
302 SET(exec_prefix "\${prefix}")
303 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
304 SET(bindir "\${exec_prefix}/bin")
305 SET(includedir "\${prefix}/include")
306 SET(PACKAGE_VERSION "${LIB_VERSION}")
310 "${OpenAL_SOURCE_DIR}/config.h.in"
311 "${OpenAL_BINARY_DIR}/config.h")
313 "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
314 "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
317 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
319 # Build a shared library
320 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
321 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
322 SOVERSION ${LIB_MAJOR_VERSION})
324 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
327 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
329 # Add an install target here
330 INSTALL(TARGETS ${LIBNAME}
331 RUNTIME DESTINATION bin
332 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
333 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
335 INSTALL(FILES include/AL/al.h
338 DESTINATION include/AL
340 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
341 DESTINATION lib/pkgconfig)
344 ADD_EXECUTABLE(openal-info examples/openal-info.c)
345 TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
346 INSTALL(TARGETS openal-info
347 RUNTIME DESTINATION bin
348 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
349 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
354 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
355 MESSAGE(STATUS " ${BACKENDS}")
358 IF(WIN32 AND NOT HAVE_DSOUND)
359 MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
360 MESSAGE(STATUS " This is probably NOT what you want!")