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