Use a 2-pole filter for the wet path low-pass filter
[openal-soft.git] / CMakeLists.txt
blob59c8c78d378a317c6c810b72cab414da590144f4
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)
18 PROJECT(OpenAL C)
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)
31 OPTION(DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
33 OPTION(WERROR  "Treat compile warnings as errors"      OFF)
35 OPTION(EXAMPLES  "Build example programs"              ON)
38 IF(WIN32)
39     SET(LIBNAME OpenAL32)
40     ADD_DEFINITIONS("-D_WIN32")
41 ELSE()
42     SET(LIBNAME openal)
43 ENDIF()
45 SET(LIB_MAJOR_VERSION "1")
46 SET(LIB_MINOR_VERSION "7")
47 SET(LIB_BUILD_VERSION "411")
48 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
49 IF(NOT DEFINED LIB_INSTALL_DIR)
50   SET(LIB_INSTALL_DIR "lib${LIB_SUFFIX}")
51 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
54 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
55 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
56 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
57 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
60 # Add definitions, compiler switches, etc.
61 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
63 IF(NOT CMAKE_BUILD_TYPE)
64     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
65         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
66         FORCE)
67 ENDIF()
68 IF(NOT CMAKE_DEBUG_POSTFIX)
69     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
70         "Library postfix for debug builds. Normally left blank."
71         FORCE)
72 ENDIF()
74 IF(MSVC)
75     # ???
76     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
77     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
78     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
79     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
80 ELSE()
81     ADD_DEFINITIONS(-Wall)
82     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
83     IF(HAVE_W_EXTRA)
84         ADD_DEFINITIONS(-Wextra)
85     ENDIF()
87     IF(WERROR)
88         ADD_DEFINITIONS(-Werror)
89     ENDIF()
91     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
92         "Flags used by the compiler during Release with Debug Info builds."
93         FORCE)
94     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
95         "Flags used by the compiler during release minsize builds."
96         FORCE)
97     SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
98         "Flags used by the compiler during release builds"
99         FORCE)
100     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
101         "Flags used by the compiler during debug builds."
102         FORCE)
104     # Set visibility options if available
105     IF(NOT WIN32)
106         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
107                                  int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
109         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
110         IF(HAVE_VISIBILITY_SWITCH)
111             CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
112                                      int main() {return 0;}" HAVE_GCC_VISIBILITY)
113             IF(HAVE_GCC_VISIBILITY)
114                 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
115             ENDIF()
116         ENDIF()
117     ENDIF()
118 ENDIF()
120 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
121 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
123 CHECK_LIBRARY_EXISTS(m  sqrtf  "" HAVE_SQRTF)
124 CHECK_LIBRARY_EXISTS(m  acosf  "" HAVE_ACOSF)
125 CHECK_LIBRARY_EXISTS(m  atanf  "" HAVE_ATANF)
126 CHECK_LIBRARY_EXISTS(m  fabsf  "" HAVE_FABSF)
127 IF(HAVE_FENV_H)
128     CHECK_LIBRARY_EXISTS(m  fesetround  "" HAVE_FESETROUND)
129 ENDIF()
130 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
131     SET(EXTRA_LIBS m ${EXTRA_LIBS})
132 ENDIF()
133 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
134 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
136 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
137 IF(NOT HAVE_STRCASECMP)
138     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
139     IF(NOT HAVE__STRICMP)
140         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
141     ENDIF()
143     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
144 ENDIF()
146 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
147 IF(NOT HAVE_STRNCASECMP)
148     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
149     IF(NOT HAVE__STRNICMP)
150         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
151     ENDIF()
153     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
154 ENDIF()
156 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
157 IF(NOT HAVE_SNPRINTF)
158     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
159     IF(NOT HAVE__SNPRINTF)
160         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
161     ENDIF()
163     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
164 ENDIF()
166 # Check for the dlopen API (for dynamicly loading backend libs)
167 IF(DLOPEN)
168     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
169     IF(HAVE_DLFCN_H)
170         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
171         IF(HAVE_LIBDL)
172             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
173         ENDIF()
174     ENDIF()
175 ENDIF()
177 # Check if we have Windows headers
178 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
179 IF(NOT HAVE_WINDOWS_H)
180     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
181     IF(NOT HAVE_GETTIMEOFDAY)
182         MESSAGE(FATAL_ERROR "No timing function found!")
183     ENDIF()
185     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
186     IF(NOT HAVE_NANOSLEEP)
187         MESSAGE(FATAL_ERROR "No sleep function found!")
188     ENDIF()
190     # We need pthreads outside of Windows
191     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
192     IF(NOT HAVE_PTHREAD_H)
193         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
194     ENDIF()
196     # Some systems need pthread_np.h to get recursive mutexes
197     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
199     # _GNU_SOURCE is needed on some systems for extra attributes, and
200     # _REENTRANT is needed for libc thread-safety
201     ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
202     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
203     IF(HAVE_LIBPTHREAD)
204         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
205     ENDIF()
206 ENDIF()
208 # Check for a 64-bit type
209 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
210 IF(NOT HAVE_STDINT_H)
211     IF(HAVE_WINDOWS_H)
212         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
213                                  \#include <windows.h>
214                                  __int64 foo;
215                                  int main() {return 0;}" HAVE___INT64)
216     ENDIF()
217     IF(NOT HAVE___INT64)
218         IF(NOT SIZEOF_LONG MATCHES "8")
219             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
220                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
221             ENDIF()
222         ENDIF()
223     ENDIF()
224 ENDIF()
227 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
228                  OpenAL32/alBuffer.c
229                  OpenAL32/alEffect.c
230                  OpenAL32/alError.c
231                  OpenAL32/alExtension.c
232                  OpenAL32/alFilter.c
233                  OpenAL32/alListener.c
234                  OpenAL32/alSource.c
235                  OpenAL32/alState.c
236                  OpenAL32/alThunk.c
238 SET(ALC_OBJS  Alc/ALc.c
239               Alc/ALu.c
240               Alc/alcConfig.c
241               Alc/alcEcho.c
242               Alc/alcReverb.c
243               Alc/alcRing.c
244               Alc/alcThread.c
245               Alc/bs2b.c
246               Alc/wave.c
249 SET(BACKENDS "")
251 # Check ALSA backend
252 IF(ALSA)
253     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
254     IF(HAVE_ALSA_ASOUNDLIB_H)
255         CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
256         IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
257             SET(HAVE_ALSA 1)
258             SET(ALC_OBJS  ${ALC_OBJS} Alc/alsa.c)
259             IF(HAVE_DLFCN_H)
260                 SET(BACKENDS  "${BACKENDS} ALSA,")
261             ELSE()
262                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
263                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
264             ENDIF()
265         ENDIF()
266     ENDIF()
267 ENDIF()
269 # Check OSS backend
270 IF(OSS)
271     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
272     IF(HAVE_SYS_SOUNDCARD_H)
273         SET(HAVE_OSS 1)
274         SET(ALC_OBJS  ${ALC_OBJS} Alc/oss.c)
275         SET(BACKENDS  "${BACKENDS} OSS,")
276     ENDIF()
277 ENDIF()
279 # Check Solaris backend
280 IF(SOLARIS)
281     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
282     IF(HAVE_SYS_AUDIOIO_H)
283         SET(HAVE_SOLARIS 1)
284         SET(ALC_OBJS  ${ALC_OBJS} Alc/solaris.c)
285         SET(BACKENDS  "${BACKENDS} Solaris,")
286     ENDIF()
287 ENDIF()
289 # Check DSound/MMSystem backend
290 IF(DSOUND)
291     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
292     IF(HAVE_DSOUND_H)
293         CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
294         IF(HAVE_LIBDSOUND OR WIN32)
295             SET(HAVE_DSOUND 1)
296             SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
298             IF(WIN32)
299                 SET(BACKENDS  "${BACKENDS} DirectSound,")
300             ELSE()
301                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
302                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
303             ENDIF()
304         ENDIF()
305     ENDIF()
306 ENDIF()
307 IF(HAVE_WINDOWS_H)
308     IF(WINMM)
309         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
310         IF(HAVE_MMSYSTEM_H)
311             SET(HAVE_WINMM 1)
312             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
313             SET(BACKENDS  "${BACKENDS} WinMM,")
315             SET(CMAKE_REQUIRED_LIBRARIES winmm)
316             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
317             SET(CMAKE_REQUIRED_LIBRARIES "")
318 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
319             IF(HAVE_LIBWINMM)
320                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
321             ENDIF()
322         ENDIF()
323     ENDIF()
324 ENDIF()
326 # Check PortAudio backend
327 IF(PORTAUDIO)
328     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
329     IF(HAVE_PORTAUDIO_H)
330         CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
331         IF(HAVE_LIBPORTAUDIO)
332             SET(HAVE_PORTAUDIO 1)
333             SET(ALC_OBJS  ${ALC_OBJS} Alc/portaudio.c)
334             IF(HAVE_DLFCN_H)
335                 SET(BACKENDS  "${BACKENDS} PortAudio,")
336             ELSE()
337                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
338                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
339             ENDIF()
340         ENDIF()
341     ENDIF()
342 ENDIF()
344 # This is always available
345 SET(BACKENDS  "${BACKENDS} WaveFile")
347 # Needed for openal.pc.in
348 SET(prefix ${CMAKE_INSTALL_PREFIX})
349 SET(exec_prefix "\${prefix}")
350 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
351 SET(bindir "\${exec_prefix}/bin")
352 SET(includedir "\${prefix}/include")
353 SET(PACKAGE_VERSION "${LIB_VERSION}")
355 # End configuration
356 CONFIGURE_FILE(
357     "${OpenAL_SOURCE_DIR}/config.h.in"
358     "${OpenAL_BINARY_DIR}/config.h")
359 CONFIGURE_FILE(
360     "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
361     "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
362     @ONLY)
364 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
366 # Build a library
367 IF(NOT LIBTYPE)
368     SET(LIBTYPE SHARED)
369 ENDIF()
370 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
371 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
372                                             SOVERSION ${LIB_MAJOR_VERSION})
373 IF(WIN32)
374     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
375 ENDIF()
377 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
379 # Add an install target here
380 INSTALL(TARGETS ${LIBNAME}
381         RUNTIME DESTINATION bin
382         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
383         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
385 INSTALL(FILES include/AL/al.h
386               include/AL/alc.h
387               include/AL/alext.h
388         DESTINATION include/AL
390 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
391         DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
393 IF(EXAMPLES)
394     ADD_EXECUTABLE(openal-info examples/openal-info.c)
395     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
396     INSTALL(TARGETS openal-info
397             RUNTIME DESTINATION bin
398             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
399             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
400     )
401 ENDIF()
403 MESSAGE(STATUS "")
404 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
405 MESSAGE(STATUS "    ${BACKENDS}")
406 MESSAGE(STATUS "")
408 IF(WIN32)
409     IF(NOT HAVE_DSOUND)
410         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
411         MESSAGE(STATUS "         This is probably NOT what you want!")
412         MESSAGE(STATUS "")
413     ENDIF()
414 ENDIF()