Fix incorrect comment
[openal-soft.git] / CMakeLists.txt
blob845442c3d8037b4a27ea9abbe10f33844bcb08e3
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(SDL     "Check for SDL 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 "6")
47 SET(LIB_BUILD_VERSION "372")
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")
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/alcReverb.c
242               Alc/alcRing.c
243               Alc/alcThread.c
244               Alc/bs2b.c
245               Alc/wave.c
248 SET(BACKENDS "")
250 # Check ALSA backend
251 IF(ALSA)
252     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
253     IF(HAVE_ALSA_ASOUNDLIB_H)
254         CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
255         IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
256             SET(HAVE_ALSA 1)
257             SET(ALC_OBJS  ${ALC_OBJS} Alc/alsa.c)
258             IF(HAVE_DLFCN_H)
259                 SET(BACKENDS  "${BACKENDS} ALSA,")
260             ELSE()
261                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
262                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
263             ENDIF()
264         ENDIF()
265     ENDIF()
266 ENDIF()
268 # Check OSS backend
269 IF(OSS)
270     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
271     IF(HAVE_SYS_SOUNDCARD_H)
272         SET(HAVE_OSS 1)
273         SET(ALC_OBJS  ${ALC_OBJS} Alc/oss.c)
274         SET(BACKENDS  "${BACKENDS} OSS,")
275     ENDIF()
276 ENDIF()
278 # Check Solaris backend
279 IF(SOLARIS)
280     CHECK_INCLUDE_FILE(sys/audioio.h HAVE_SYS_AUDIOIO_H)
281     IF(HAVE_SYS_AUDIOIO_H)
282         SET(HAVE_SOLARIS 1)
283         SET(ALC_OBJS  ${ALC_OBJS} Alc/solaris.c)
284         SET(BACKENDS  "${BACKENDS} Solaris,")
285     ENDIF()
286 ENDIF()
288 # Check DSound/MMSystem backend
289 IF(DSOUND)
290     CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
291     IF(HAVE_DSOUND_H)
292         SET(HAVE_DSOUND 1)
293         SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
294         SET(BACKENDS  "${BACKENDS} DirectSound,")
296         SET(CMAKE_REQUIRED_LIBRARIES dsound)
297         CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBDSOUND)
298         SET(CMAKE_REQUIRED_LIBRARIES "")
299 #        CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
300         IF(HAVE_LIBDSOUND)
301             SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
302         ENDIF()
303     ENDIF()
304 ENDIF()
305 IF(HAVE_WINDOWS_H)
306     IF(WINMM)
307         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
308         IF(HAVE_MMSYSTEM_H)
309             SET(HAVE_WINMM 1)
310             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
311             SET(BACKENDS  "${BACKENDS} WinMM,")
313             SET(CMAKE_REQUIRED_LIBRARIES winmm)
314             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
315             SET(CMAKE_REQUIRED_LIBRARIES "")
316 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
317             IF(HAVE_LIBWINMM)
318                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
319             ENDIF()
320         ENDIF()
321     ENDIF()
322 ENDIF()
324 # Check SDL backend
325 IF(SDL)
326     CHECK_INCLUDE_FILE(SDL.h HAVE_SDL_H)
327     IF(NOT HAVE_SDL_H)
328         CHECK_INCLUDE_FILE(SDL/SDL.h HAVE_SDL_SDL_H)
329     ENDIF()
330     IF(HAVE_SDL_H OR HAVE_SDL_SDL_H)
331         CHECK_LIBRARY_EXISTS(SDL SDL_Init "" HAVE_LIBSDL)
332         IF(HAVE_DLFCN_H OR HAVE_LIBSDL)
333             SET(HAVE_SDL 1)
334             SET(ALC_OBJS  ${ALC_OBJS} Alc/sdl.c)
335             IF(HAVE_DLFCN_H)
336                 SET(BACKENDS  "${BACKENDS} SDL,")
337             ELSE()
338                 SET(BACKENDS  "${BACKENDS} SDL \(linked\),")
339                 SET(EXTRA_LIBS SDL ${EXTRA_LIBS})
340             ENDIF()
341         ENDIF()
342     ENDIF()
343 ENDIF()
345 # This is always available
346 SET(BACKENDS  "${BACKENDS} WaveFile")
348 # Needed for openal.pc.in
349 SET(prefix ${CMAKE_INSTALL_PREFIX})
350 SET(exec_prefix "\${prefix}")
351 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
352 SET(bindir "\${exec_prefix}/bin")
353 SET(includedir "\${prefix}/include")
354 SET(PACKAGE_VERSION "${LIB_VERSION}")
356 # End configuration
357 CONFIGURE_FILE(
358     "${OpenAL_SOURCE_DIR}/config.h.in"
359     "${OpenAL_BINARY_DIR}/config.h")
360 CONFIGURE_FILE(
361     "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
362     "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
363     @ONLY)
365 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
367 # Build a library
368 IF(NOT LIBTYPE)
369     SET(LIBTYPE SHARED)
370 ENDIF()
371 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
372 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
373                                             SOVERSION ${LIB_MAJOR_VERSION})
374 IF(WIN32)
375     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
376 ENDIF()
378 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
380 # Add an install target here
381 INSTALL(TARGETS ${LIBNAME}
382         RUNTIME DESTINATION bin
383         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
384         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
386 INSTALL(FILES include/AL/al.h
387               include/AL/alc.h
388               include/AL/alext.h
389         DESTINATION include/AL
391 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
392         DESTINATION lib/pkgconfig)
394 IF(EXAMPLES)
395     ADD_EXECUTABLE(openal-info examples/openal-info.c)
396     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
397     INSTALL(TARGETS openal-info
398             RUNTIME DESTINATION bin
399             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
400             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
401     )
402 ENDIF()
404 MESSAGE(STATUS "")
405 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
406 MESSAGE(STATUS "    ${BACKENDS}")
407 MESSAGE(STATUS "")
409 IF(WIN32)
410     IF(NOT HAVE_DSOUND)
411         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
412         MESSAGE(STATUS "         This is probably NOT what you want!")
413         MESSAGE(STATUS "")
414     ENDIF()
415 ENDIF()