Don't advertise extra samples for mixing
[openal-soft/openal-hmr.git] / CMakeLists.txt
blob2f49d3b65f744e0339ef67e62452a5cc759a9f07
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(DSOUND  "Check for DirectSound backend"         ON)
27 OPTION(WINMM   "Check for Windows Multimedia backend"  ON)
29 OPTION(DLOPEN  "Check for the dlopen API for loading optional libs"  ON)
31 OPTION(WERROR  "Treat compile warnings as errors"      OFF)
33 OPTION(EXAMPLES  "Build example programs"              ON)
36 IF(WIN32)
37     SET(LIBNAME openal32)
38 ELSE()
39     SET(LIBNAME openal)
40 ENDIF()
42 SET(LIB_MAJOR_VERSION "1")
43 SET(LIB_MINOR_VERSION "4")
44 SET(LIB_BUILD_VERSION "272")
45 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
46 IF(NOT DEFINED LIB_INSTALL_DIR)
47   SET(LIB_INSTALL_DIR "lib")
48 ENDIF(NOT DEFINED LIB_INSTALL_DIR)
51 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
52 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
53 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
54 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
57 # Add definitions, compiler switches, etc.
58 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
60 IF(NOT CMAKE_BUILD_TYPE)
61     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
62         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
63         FORCE)
64 ENDIF()
66 IF(MSVC)
67     # ???
68     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -D_DEBUG")
69     SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -DNDEBUG")
70     SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
71     SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
72 ELSE()
73     ADD_DEFINITIONS(-Wall)
74     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
75     IF("${HAVE_W_EXTRA}")
76         ADD_DEFINITIONS(-Wextra)
77     ENDIF()
79     IF(WERROR)
80         ADD_DEFINITIONS(-Werror)
81     ENDIF()
83     SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -funroll-loops -D_DEBUG" CACHE STRING
84         "Flags used by the compiler during Release with Debug Info builds."
85         FORCE)
86     SET(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG" CACHE STRING
87         "Flags used by the compiler during release minsize builds."
88         FORCE)
89     SET(CMAKE_C_FLAGS_RELEASE "-O2 -funroll-loops -fomit-frame-pointer -DNDEBUG" CACHE STRING
90         "Flags used by the compiler during release builds"
91         FORCE)
92     SET(CMAKE_C_FLAGS_DEBUG "-g3 -D_DEBUG" CACHE STRING
93         "Flags used by the compiler during debug builds."
94         FORCE)
96     # Set visibility options if available
97     IF(NOT WIN32)
98         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
99                                  int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
101         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
102         IF("${HAVE_VISIBILITY_SWITCH}")
103             CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
104                                      int main() {return 0;}" HAVE_GCC_VISIBILITY)
105             IF("${HAVE_GCC_VISIBILITY}")
106                 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
107             ENDIF()
108         ENDIF()
109     ENDIF()
110 ENDIF()
113 CHECK_LIBRARY_EXISTS(m  sqrtf  "" HAVE_SQRTF)
114 CHECK_LIBRARY_EXISTS(m  acosf  "" HAVE_ACOSF)
115 IF(HAVE_SQRTF OR HAVE_ACOSF)
116     SET(EXTRA_LIBS m ${EXTRA_LIBS})
117 ENDIF()
118 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
120 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
121 IF(NOT HAVE_STRCASECMP)
122     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
123     IF(NOT HAVE__STRICMP)
124         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
125     ENDIF()
127     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
128 ENDIF()
130 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
131 IF(NOT HAVE_STRNCASECMP)
132     CHECK_FUNCTION_EXISTS(_strnicmp HAVE__STRNICMP)
133     IF(NOT HAVE__STRNICMP)
134         MESSAGE(FATAL_ERROR "No case-insensitive size-limitted compare function found, please report!")
135     ENDIF()
137     ADD_DEFINITIONS(-Dstrncasecmp=_strnicmp)
138 ENDIF()
140 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
141 IF(NOT HAVE_SNPRINTF)
142     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
143     IF(NOT HAVE__SNPRINTF)
144         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
145     ENDIF()
147     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
148 ENDIF()
150 # Check for the dlopen API (for dynamicly loading backend libs)
151 IF(DLOPEN)
152     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
153     IF(HAVE_DLFCN_H)
154         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
155         IF(HAVE_LIBDL)
156             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
157         ENDIF()
158     ENDIF()
159 ENDIF()
161 # Check if we have Windows headers
162 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
163 IF(NOT HAVE_WINDOWS_H)
164     CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
165     IF(NOT HAVE_GETTIMEOFDAY)
166         MESSAGE(FATAL_ERROR "No timing function found!")
167     ENDIF()
169     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
170     IF(NOT HAVE_NANOSLEEP)
171         MESSAGE(FATAL_ERROR "No sleep function found!")
172     ENDIF()
174     # We need pthreads outside of Windows
175     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
176     IF(NOT HAVE_PTHREAD_H)
177         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
178     ENDIF()
180     # Some systems need pthread_np.h to get recursive mutexes
181     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
183     # _GNU_SOURCE is needed on some systems for extra attributes, and
184     # _REENTRANT is needed for libc thread-safety
185     ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
186     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
187     IF(HAVE_LIBPTHREAD)
188         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
189     ENDIF()
190 ENDIF()
192 # Check for a 64-bit type
193 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
194 IF(NOT HAVE_STDINT_H)
195     IF(HAVE_WINDOWS_H)
196         CHECK_C_SOURCE_COMPILES("\#define _WIN32_WINNT 0x0500
197                                  \#include <windows.h>
198                                  __int64 foo;
199                                  int main() {return 0;}" HAVE___INT64)
200     ENDIF()
201     IF(NOT HAVE___INT64)
202         IF(NOT SIZEOF_LONG MATCHES "8")
203             IF(NOT SIZEOF_LONG_LONG MATCHES "8")
204                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
205             ENDIF()
206         ENDIF()
207     ENDIF()
208 ENDIF()
211 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
212                  OpenAL32/alBuffer.c
213                  OpenAL32/alEffect.c
214                  OpenAL32/alError.c
215                  OpenAL32/alExtension.c
216                  OpenAL32/alFilter.c
217                  OpenAL32/alListener.c
218                  OpenAL32/alSource.c
219                  OpenAL32/alState.c
220                  OpenAL32/alThunk.c
222 SET(ALC_OBJS  Alc/ALc.c
223               Alc/ALu.c
224               Alc/alcConfig.c
225               Alc/alcRing.c
226               Alc/alcThread.c
227               Alc/bs2b.c
228               Alc/wave.c
231 SET(BACKENDS "")
233 # Check ALSA backend
234 IF(ALSA)
235     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
236     IF(HAVE_ALSA_ASOUNDLIB_H)
237         CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
238         IF(HAVE_DLFCN_H OR HAVE_LIBASOUND)
239             SET(HAVE_ALSA 1)
240             SET(ALC_OBJS  ${ALC_OBJS} Alc/alsa.c)
241             IF(HAVE_DLFCN_H)
242                 SET(BACKENDS  "${BACKENDS} ALSA,")
243             ELSE()
244                 SET(BACKENDS  "${BACKENDS} ALSA \(linked\),")
245                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
246             ENDIF()
247         ENDIF()
248     ENDIF()
249 ENDIF()
251 # Check OSS backend
252 IF(OSS)
253     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
254     IF(HAVE_SYS_SOUNDCARD_H)
255         SET(HAVE_OSS 1)
256         SET(ALC_OBJS  ${ALC_OBJS} Alc/oss.c)
257         SET(BACKENDS  "${BACKENDS} OSS,")
258     ENDIF()
259 ENDIF()
261 # Check DSound/MMSystem backend
262 IF(HAVE_WINDOWS_H)
263     IF(DSOUND)
264         CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
265         IF(HAVE_DSOUND_H)
266             SET(HAVE_DSOUND 1)
267             SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
268             SET(BACKENDS  "${BACKENDS} DirectSound,")
270             SET(CMAKE_REQUIRED_LIBRARIES dsound)
271             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBDSOUND)
272             SET(CMAKE_REQUIRED_LIBRARIES "")
273 #            CHECK_LIBRARY_EXISTS(dsound DirectSoundCreate "" HAVE_LIBDSOUND)
274             IF(HAVE_LIBDSOUND)
275                 SET(EXTRA_LIBS dsound ${EXTRA_LIBS})
276             ENDIF()
277         ENDIF()
278     ENDIF()
279     IF(WINMM)
280         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H -D_WIN32_WINNT=0x0500)
281         IF(HAVE_MMSYSTEM_H)
282             SET(HAVE_WINMM 1)
283             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
284             SET(BACKENDS  "${BACKENDS} WinMM,")
286             SET(CMAKE_REQUIRED_LIBRARIES winmm)
287             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
288             SET(CMAKE_REQUIRED_LIBRARIES "")
289 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
290             IF(HAVE_LIBWINMM)
291                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
292             ENDIF()
293         ENDIF()
294     ENDIF()
295 ENDIF()
297 # This is always available
298 SET(BACKENDS  "${BACKENDS} WaveFile")
300 # Needed for openal.pc.in
301 SET(prefix ${CMAKE_INSTALL_PREFIX})
302 SET(exec_prefix "\${prefix}")
303 SET(libdir "\${exec_prefix}/${LIB_INSTALL_DIR}")
304 SET(bindir "\${exec_prefix}/bin")
305 SET(includedir "\${prefix}/include")
306 SET(PACKAGE_VERSION "${LIB_VERSION}")
308 # End configuration
309 CONFIGURE_FILE(
310     "${OpenAL_SOURCE_DIR}/config.h.in"
311     "${OpenAL_BINARY_DIR}/config.h")
312 CONFIGURE_FILE(
313     "${OpenAL_SOURCE_DIR}/admin/pkgconfig/openal.pc.in"
314     "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
315     @ONLY)
317 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
319 # Build a shared library
320 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
321 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
322                                             SOVERSION ${LIB_MAJOR_VERSION})
323 IF(WIN32)
324     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
325 ENDIF()
327 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
329 # Add an install target here
330 INSTALL(TARGETS ${LIBNAME}
331         RUNTIME DESTINATION bin
332         LIBRARY DESTINATION ${LIB_INSTALL_DIR}
333         ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
335 INSTALL(FILES include/AL/al.h
336               include/AL/alc.h
337               include/AL/alext.h
338         DESTINATION include/AL
340 INSTALL(FILES "${OpenAL_BINARY_DIR}/admin/pkgconfig/openal.pc"
341         DESTINATION lib/pkgconfig)
343 IF(EXAMPLES)
344     ADD_EXECUTABLE(openal-info examples/openal-info.c)
345     TARGET_LINK_LIBRARIES(openal-info ${LIBNAME})
346     INSTALL(TARGETS openal-info
347             RUNTIME DESTINATION bin
348             LIBRARY DESTINATION ${LIB_INSTALL_DIR}
349             ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
350     )
351 ENDIF()
353 MESSAGE(STATUS "")
354 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
355 MESSAGE(STATUS "    ${BACKENDS}")
356 MESSAGE(STATUS "")
358 IF(WIN32 AND NOT HAVE_DSOUND)
359     MESSAGE(STATUS "WARNING: Building the Windows version without DirectSound output")
360     MESSAGE(STATUS "         This is probably NOT what you want!")
361     MESSAGE(STATUS "")
362 ENDIF()