Move NextPowerOf2 to alMain.h
[openal-soft.git] / CMakeLists.txt
blob10f0214fac1229999fc4cbcc98910209e6285ace
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 "10")
51 SET(LIB_BUILD_VERSION "622")
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(NOT DXSDK_DIR)
79     STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "$ENV{DXSDK_DIR}")
80 ELSE()
81     STRING(REGEX REPLACE "\\\\" "/" DXSDK_DIR "${DXSDK_DIR}")
82 ENDIF()
83 IF(DXSDK_DIR)
84     MESSAGE(STATUS "Using DirectX SDK directory: ${DXSDK_DIR}")
85     SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} "${DXSDK_DIR}/Include")
86     INCLUDE_DIRECTORIES("${DXSDK_DIR}/Include")
87     LINK_DIRECTORIES("${DXSDK_DIR}/Lib")
88 ENDIF()
90 IF(MSVC)
91     # ???
92     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
93     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
94     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
95     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
96     ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
97 ELSE()
98     ADD_DEFINITIONS(-Wall)
99     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
100     IF(HAVE_W_EXTRA)
101         ADD_DEFINITIONS(-Wextra)
102     ENDIF()
104     IF(WERROR)
105         ADD_DEFINITIONS(-Werror)
106     ENDIF()
108     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
109         "Flags used by the compiler during Release with Debug Info builds."
110         FORCE)
111     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
112         "Flags used by the compiler during release minsize builds."
113         FORCE)
114     SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
115         "Flags used by the compiler during release builds"
116         FORCE)
117     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
118         "Flags used by the compiler during debug builds."
119         FORCE)
121     # Set visibility options if available
122     IF(NOT WIN32)
123         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
124                                  int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
126         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
127         IF(HAVE_VISIBILITY_SWITCH)
128             CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
129                                      int main() {return 0;}" HAVE_GCC_VISIBILITY)
130             IF(HAVE_GCC_VISIBILITY)
131                 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
132             ENDIF()
133         ENDIF()
134     ENDIF()
135 ENDIF()
137 CHECK_INCLUDE_FILE(fenv.h HAVE_FENV_H)
138 CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H)
140 CHECK_LIBRARY_EXISTS(m  sqrtf  "" HAVE_SQRTF)
141 CHECK_LIBRARY_EXISTS(m  acosf  "" HAVE_ACOSF)
142 CHECK_LIBRARY_EXISTS(m  atanf  "" HAVE_ATANF)
143 CHECK_LIBRARY_EXISTS(m  fabsf  "" HAVE_FABSF)
144 IF(HAVE_FENV_H)
145     CHECK_LIBRARY_EXISTS(m  fesetround  "" HAVE_FESETROUND)
146 ENDIF()
147 IF(HAVE_SQRTF OR HAVE_ACOSF OR HAVE_ATANF OR HAVE_FABSF OR HAVE_FESETROUND)
148     SET(EXTRA_LIBS m ${EXTRA_LIBS})
149 ENDIF()
150 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
151 CHECK_FUNCTION_EXISTS(_controlfp HAVE__CONTROLFP)
153 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
154 IF(NOT HAVE_STRCASECMP)
155     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
156     IF(NOT HAVE__STRICMP)
157         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
158     ENDIF()
160     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
161 ENDIF()
163 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
164 IF(NOT HAVE_STRNCASECMP)
165     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
166     IF(NOT HAVE__STRNICMP)
167         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
168     ENDIF()
170     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
171 ENDIF()
173 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
174 IF(NOT HAVE_SNPRINTF)
175     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
176     IF(NOT HAVE__SNPRINTF)
177         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
178     ENDIF()
180     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
181 ENDIF()
183 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
184 IF(NOT HAVE_VSNPRINTF)
185     CHECK_FUNCTION_EXISTS(_vsnprintf HAVE__VSNPRINTF)
186     IF(NOT HAVE__VSNPRINTF)
187         MESSAGE(FATAL_ERROR "No vsnprintf function found, please report!")
188     ENDIF()
190     ADD_DEFINITIONS(-Dvsnprintf=_vsnprintf)
191 ENDIF()
193 CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
194 IF(NOT HAVE_ISNAN)
195     CHECK_FUNCTION_EXISTS(_isnan HAVE__ISNAN)
196     IF(NOT HAVE__ISNAN)
197         MESSAGE(FATAL_ERROR "No isnan function found, please report!")
198     ENDIF()
200     ADD_DEFINITIONS(-Disnan=_isnan)
201 ENDIF()
204 # Check for the dlopen API (for dynamicly loading backend libs)
205 IF(DLOPEN)
206     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
207     IF(HAVE_DLFCN_H)
208         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
209         IF(HAVE_LIBDL)
210             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
211         ENDIF()
212     ENDIF()
213 ENDIF()
215 # Check if we have Windows headers
216 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
217 IF(NOT HAVE_WINDOWS_H)
218     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
219     IF(NOT HAVE_GETTIMEOFDAY)
220         MESSAGE(FATAL_ERROR "No timing function found!")
221     ENDIF()
223     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
224     IF(NOT HAVE_NANOSLEEP)
225         MESSAGE(FATAL_ERROR "No sleep function found!")
226     ENDIF()
228     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
229     IF(HAVE_PTHREAD)
230         ADD_DEFINITIONS(-pthread)
231         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
232     ENDIF()
234     # We need pthreads outside of Windows
235     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
236     IF(NOT HAVE_PTHREAD_H)
237         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
238     ENDIF()
239     # Some systems need pthread_np.h to get recursive mutexes
240     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
242     # _GNU_SOURCE is needed on some systems for extra attributes, and
243     # _REENTRANT is needed for libc thread-safety
244     ADD_DEFINITIONS(-D_GNU_SOURCE=1)
245     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
246     IF(HAVE_LIBPTHREAD)
247         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
248     ENDIF()
250     CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_LIBRT)
251     IF(HAVE_LIBRT)
252         SET(EXTRA_LIBS rt ${EXTRA_LIBS})
253     ENDIF()
254 ENDIF()
256 # Check for a 64-bit type
257 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
258 IF(NOT HAVE_STDINT_H)
259     IF(HAVE_WINDOWS_H)
260         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
261                                  \#include <windows.h>
262                                  __int64 foo;
263                                  int main() {return 0;}" HAVE___INT64)
264     ENDIF()
265     IF(NOT HAVE___INT64)
266         IF(NOT SIZEOF_LONG MATCHES "8")
267             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
268                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
269             ENDIF()
270         ENDIF()
271     ENDIF()
272 ENDIF()
275 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
276                  OpenAL32/alBuffer.c
277                  OpenAL32/alDatabuffer.c
278                  OpenAL32/alEffect.c
279                  OpenAL32/alError.c
280                  OpenAL32/alExtension.c
281                  OpenAL32/alFilter.c
282                  OpenAL32/alListener.c
283                  OpenAL32/alSource.c
284                  OpenAL32/alState.c
285                  OpenAL32/alThunk.c
287 SET(ALC_OBJS  Alc/ALc.c
288               Alc/ALu.c
289               Alc/alcConfig.c
290               Alc/alcEcho.c
291               Alc/alcReverb.c
292               Alc/alcRing.c
293               Alc/alcThread.c
294               Alc/bs2b.c
295               Alc/wave.c
298 SET(BACKENDS "")
300 # Check ALSA backend
301 IF(ALSA)
302     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
303     IF(HAVE_ALSA_ASOUNDLIB_H)
304         CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
305         IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
306             SET(HAVE_ALSA 1)
307             SET(ALC_OBJS  ${ALC_OBJS} Alc/alsa.c)
308             IF(HAVE_DLFCN_H)
309                 SET(BACKENDS  "${BACKENDS} ALSA,")
310             ELSE()
311                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
312                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
313             ENDIF()
314         ENDIF()
315     ENDIF()
316 ENDIF()
318 # Check OSS backend
319 IF(OSS)
320     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
321     IF(HAVE_SYS_SOUNDCARD_H)
322         SET(HAVE_OSS 1)
323         SET(ALC_OBJS  ${ALC_OBJS} Alc/oss.c)
324         SET(BACKENDS  "${BACKENDS} OSS,")
325     ENDIF()
326 ENDIF()
328 # Check Solaris backend
329 IF(SOLARIS)
330     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
331     IF(HAVE_SYS_AUDIOIO_H)
332         SET(HAVE_SOLARIS 1)
333         SET(ALC_OBJS  ${ALC_OBJS} Alc/solaris.c)
334         SET(BACKENDS  "${BACKENDS} Solaris,")
335     ENDIF()
336 ENDIF()
338 # Check DSound/MMSystem backend
339 IF(DSOUND)
340     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
341     IF(HAVE_DSOUND_H)
342         CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
343         IF(HAVE_LIBDSOUND OR WIN32)
344             SET(HAVE_DSOUND 1)
345             SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
347             IF(WIN32)
348                 SET(BACKENDS  "${BACKENDS} DirectSound,")
349             ELSE()
350                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
351                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
352             ENDIF()
353         ENDIF()
354     ENDIF()
355 ENDIF()
356 IF(HAVE_WINDOWS_H)
357     IF(WINMM)
358         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
359         IF(HAVE_MMSYSTEM_H)
360             SET(HAVE_WINMM 1)
361             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
362             SET(BACKENDS  "${BACKENDS} WinMM,")
364             SET(CMAKE_REQUIRED_LIBRARIES winmm)
365             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
366             SET(CMAKE_REQUIRED_LIBRARIES "")
367 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
368             IF(HAVE_LIBWINMM)
369                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
370             ENDIF()
371         ENDIF()
372     ENDIF()
373 ENDIF()
375 # Check PortAudio backend
376 IF(PORTAUDIO)
377     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
378     IF(HAVE_PORTAUDIO_H)
379         CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
380         IF(HAVE_LIBPORTAUDIO)
381             SET(HAVE_PORTAUDIO 1)
382             SET(ALC_OBJS  ${ALC_OBJS} Alc/portaudio.c)
383             IF(HAVE_DLFCN_H)
384                 SET(BACKENDS  "${BACKENDS} PortAudio,")
385             ELSE()
386                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
387                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
388             ENDIF()
389         ENDIF()
390     ENDIF()
391 ENDIF()
393 # Check PortAudio backend
394 IF(PULSEAUDIO)
395     CHECK_INCLUDE_FILE(pulse/pulseaudio.h HAVE_PULSE_PULSEAUDIO_H)
396     IF(HAVE_PULSE_PULSEAUDIO_H)
397         CHECK_LIBRARY_EXISTS(pulse pa_context_new "" HAVE_LIBPULSE)
398         IF(HAVE_LIBPULSE)
399             SET(HAVE_PULSEAUDIO 1)
400             SET(ALC_OBJS  ${ALC_OBJS} Alc/pulseaudio.c)
401             IF(HAVE_DLFCN_H)
402                 SET(BACKENDS  "${BACKENDS} PulseAudio,")
403             ELSE()
404                 SET(BACKENDS  "${BACKENDS} PulseAudio \(linked\),")
405                 SET(EXTRA_LIBS pulse ${EXTRA_LIBS})
406             ENDIF()
407         ENDIF()
408     ENDIF()
409 ENDIF()
411 # This is always available
412 SET(BACKENDS  "${BACKENDS} WaveFile")
414 # Needed for openal.pc.in
415 SET(prefix ${CMAKE_INSTALL_PREFIX})
416 SET(exec_prefix "\${prefix}")
417 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
418 SET(bindir "\${exec_prefix}/bin")
419 SET(includedir "\${prefix}/include")
420 SET(PACKAGE_VERSION "${LIB_VERSION}")
422 # End configuration
423 CONFIGURE_FILE(
424     "${OpenAL_SOURCE_DIR}/config.h.in"
425     "${OpenAL_BINARY_DIR}/config.h")
426 CONFIGURE_FILE(
427     "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
428     "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
429     @ONLY)
431 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
433 # Build a library
434 IF(NOT LIBTYPE)
435     SET(LIBTYPE SHARED)
436 ENDIF()
437 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
438 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
439                                             SOVERSION ${LIB_MAJOR_VERSION})
440 IF(WIN32)
441     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
442 ENDIF()
444 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
446 # Add an install target here
447 INSTALL(TARGETS ${LIBNAME}
448         RUNTIME DESTINATION bin
449         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
450         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
452 INSTALL(FILES include/AL/al.h
453               include/AL/alc.h
454               include/AL/alext.h
455         DESTINATION include/AL
457 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
458         DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
460 # Install alsoft.conf configuration file
461 IF(ALSOFT_CONFIG)
462     INSTALL(FILES alsoftrc.sample
463             DESTINATION /etc/openal
464             RENAME alsoft.conf
465     )
466 ENDIF()
468 IF(EXAMPLES)
469     ADD_EXECUTABLE(openal-info examples/openal-info.c)
470     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
471     INSTALL(TARGETS openal-info
472             RUNTIME DESTINATION bin
473             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
474             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
475     )
476 ENDIF()
478 MESSAGE(STATUS "")
479 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
480 MESSAGE(STATUS "    ${BACKENDS}")
481 MESSAGE(STATUS "")
483 IF(WIN32)
484     IF(NOT HAVE_DSOUND)
485         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
486         MESSAGE(STATUS "         This is probably NOT what you want!")
487         MESSAGE(STATUS "")
488     ENDIF()
489 ENDIF()