Use LIB_SUFFIX when creating the default lib install dir
[openal-soft.git] / CMakeLists.txt
blobbf2cd4dde5252c1e09d1b72d803b43e7781a8494
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/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         CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
293         IF(HAVE_LIBDSOUND OR WIN32)
294             SET(HAVE_DSOUND 1)
295             SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
297             IF(WIN32)
298                 SET(BACKENDS  "${BACKENDS} DirectSound,")
299             ELSE()
300                 SET(BACKENDS  "${BACKENDS} DirectSound \(linked\),")
301                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
302             ENDIF()
303         ENDIF()
304     ENDIF()
305 ENDIF()
306 IF(HAVE_WINDOWS_H)
307     IF(WINMM)
308         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
309         IF(HAVE_MMSYSTEM_H)
310             SET(HAVE_WINMM 1)
311             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
312             SET(BACKENDS  "${BACKENDS} WinMM,")
314             SET(CMAKE_REQUIRED_LIBRARIES winmm)
315             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
316             SET(CMAKE_REQUIRED_LIBRARIES "")
317 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
318             IF(HAVE_LIBWINMM)
319                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
320             ENDIF()
321         ENDIF()
322     ENDIF()
323 ENDIF()
325 # Check PortAudio backend
326 IF(PORTAUDIO)
327     CHECK_INCLUDE_FILE(portaudio.h HAVE_PORTAUDIO_H)
328     IF(HAVE_PORTAUDIO_H)
329         CHECK_LIBRARY_EXISTS(portaudio Pa_Initialize "" HAVE_LIBPORTAUDIO)
330         IF(HAVE_LIBPORTAUDIO)
331             SET(HAVE_PORTAUDIO 1)
332             SET(ALC_OBJS  ${ALC_OBJS} Alc/portaudio.c)
333             IF(HAVE_DLFCN_H)
334                 SET(BACKENDS  "${BACKENDS} PortAudio,")
335             ELSE()
336                 SET(BACKENDS  "${BACKENDS} PortAudio \(linked\),")
337                 SET(EXTRA_LIBS portaudio ${EXTRA_LIBS})
338             ENDIF()
339         ENDIF()
340     ENDIF()
341 ENDIF()
343 # This is always available
344 SET(BACKENDS  "${BACKENDS} WaveFile")
346 # Needed for openal.pc.in
347 SET(prefix ${CMAKE_INSTALL_PREFIX})
348 SET(exec_prefix "\${prefix}")
349 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
350 SET(bindir "\${exec_prefix}/bin")
351 SET(includedir "\${prefix}/include")
352 SET(PACKAGE_VERSION "${LIB_VERSION}")
354 # End configuration
355 CONFIGURE_FILE(
356     "${OpenAL_SOURCE_DIR}/config.h.in"
357     "${OpenAL_BINARY_DIR}/config.h")
358 CONFIGURE_FILE(
359     "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
360     "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
361     @ONLY)
363 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
365 # Build a library
366 IF(NOT LIBTYPE)
367     SET(LIBTYPE SHARED)
368 ENDIF()
369 ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
370 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
371                                             SOVERSION ${LIB_MAJOR_VERSION})
372 IF(WIN32)
373     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
374 ENDIF()
376 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
378 # Add an install target here
379 INSTALL(TARGETS ${LIBNAME}
380         RUNTIME DESTINATION bin
381         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
382         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
384 INSTALL(FILES include/AL/al.h
385               include/AL/alc.h
386               include/AL/alext.h
387         DESTINATION include/AL
389 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
390         DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")
392 IF(EXAMPLES)
393     ADD_EXECUTABLE(openal-info examples/openal-info.c)
394     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
395     INSTALL(TARGETS openal-info
396             RUNTIME DESTINATION bin
397             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
398             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
399     )
400 ENDIF()
402 MESSAGE(STATUS "")
403 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
404 MESSAGE(STATUS "    ${BACKENDS}")
405 MESSAGE(STATUS "")
407 IF(WIN32)
408     IF(NOT HAVE_DSOUND)
409         MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
410         MESSAGE(STATUS "         This is probably NOT what you want!")
411         MESSAGE(STATUS "")
412     ENDIF()
413 ENDIF()