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