Don't default to AL_FORMAT_STEREO16 when writing to the output buffer
[openal-soft.git] / CMakeLists.txt
blobd7093fa5f763651a704e76f32f7ce5d40f8dfb62
1 # CMake build file list for OpenAL
3 INCLUDE(CheckFunctionExists)
4 INCLUDE(CheckLibraryExists)
5 INCLUDE(CheckIncludeFile)
6 INCLUDE(CheckIncludeFiles)
7 INCLUDE(CheckCCompilerFlag)
8 INCLUDE(CheckCSourceCompiles)
9 INCLUDE(CheckTypeSize)
12 PROJECT(OpenAL)
15 SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE)
18 OPTION(ALSA    "ALSA backend"                ON)
19 OPTION(OSS     "OSS backend"                 ON)
20 OPTION(DSOUND  "DirectSound backend"         ON)
21 OPTION(WINMM   "Windows Multimedia backend"  ON)
23 OPTION(DLOPEN  "Use the dlopen API for loading optional libs"  ON)
25 OPTION(DEBUG    "Build lib in debug mode"                   OFF)
26 OPTION(NODEBUG  "Disable all debug info for optimizations"  OFF)
27 OPTION(WERROR   "Treat compile warnings as errors"          OFF)
30 SET(LIB_MAJOR_VERSION "1")
31 SET(LIB_MINOR_VERSION "0")
32 SET(LIB_BUILD_VERSION "38")
33 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_BUILD_VERSION}")
36 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
37 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
38 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
39 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
42 # Add definitions, compiler switches, etc.
43 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
45 IF("${MSVC}")
46     # ???
47 ELSE()
48     ADD_DEFINITIONS(-Wall)
49     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
50     IF("${HAVE_W_EXTRA}")
51         ADD_DEFINITIONS(-Wextra)
52     ENDIF()
54     IF(WERROR)
55         ADD_DEFINITIONS(-Werror)
56     ENDIF()
58     IF(DEBUG)
59         ADD_DEFINITIONS(-g3)
60     ELSEIF(NODEBUG)
61         ADD_DEFINITIONS(-O2 -funroll-loops -fomit-frame-pointer)
62     ELSE()
63         ADD_DEFINITIONS(-g -O2 -funroll-loops)
64     ENDIF()
66     # The mixer doesn't like GCC's strict aliasing optimizations. Make sure
67     # it's turned off
68     CHECK_C_COMPILER_FLAG(-fstrict-aliasing HAVE_STRICT_ALIASING)
69     IF("${HAVE_STRICT_ALIASING}")
70         ADD_DEFINITIONS(-fno-strict-aliasing)
71     ENDIF()
73     # Set visibility options if available
74     IF(NOT "${WIN32}")
75         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
76                                  int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
78         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
79         IF("${HAVE_VISIBILITY_SWITCH}")
80             CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
81                                      int main() {return 0;}" HAVE_GCC_VISIBILITY)
82             IF("${HAVE_GCC_VISIBILITY}")
83                 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
84             ENDIF()
85         ENDIF()
86     ENDIF()
87 ENDIF()
89 IF(DEBUG)
90     ADD_DEFINITIONS(-D_DEBUG)
91 ELSEIF(NODEBUG)
92     ADD_DEFINITIONS(-DNDEBUG)
93 ENDIF()
95 CHECK_LIBRARY_EXISTS(m  sqrtf  "" HAVE_SQRTF)
96 IF("${HAVE_SQRTF}")
97     SET(EXTRA_LIBS m ${EXTRA_LIBS})
98 ENDIF()
99 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
101 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
102 IF(NOT "${HAVE_STRCASECMP}")
103     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
104     IF(NOT "${HAVE__STRICMP}")
105         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
106     ENDIF()
108     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
109 ENDIF()
111 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
112 IF(NOT "${HAVE_SNPRINTF}")
113     CHECK_FUNCTION_EXISTS(_snprintf HAVE__SNPRINTF)
114     IF(NOT "${HAVE__SNPRINTF}")
115         MESSAGE(FATAL_ERROR "No snprintf function found, please report!")
116     ENDIF()
118     ADD_DEFINITIONS(-Dsnprintf=_snprintf)
119 ENDIF()
121 # Check for the dlopen API (for dynamicly loading backend libs)
122 IF(DLOPEN)
123     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
124     IF("${HAVE_DLFCN_H}")
125         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
126         IF("${HAVE_LIBDL}")
127             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
128         ENDIF()
129     ENDIF()
130 ENDIF()
132 # Check if we have Windows headers
133 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
134 IF(NOT "${HAVE_WINDOWS_H}")
135     # We need pthreads outside of Windows
136     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
137     IF(NOT "${HAVE_PTHREAD_H}")
138         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
139     ENDIF()
141     # _GNU_SOURCE is needed on some systems for extra attributes, and
142     # _REENTRANT is needed for libc thread-safety
143     ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
144     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
145     IF("${HAVE_LIBPTHREAD}")
146         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
147     ENDIF()
148 ENDIF()
150 # Check for a 64-bit type
151 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
152 IF(NOT "${HAVE_STDINT_H}")
153     IF("${HAVE_WINDOWS_H}")
154         CHECK_C_SOURCE_COMPILES("\#include <windows.h>
155                                  __int64 foo;
156                                  int main() {return 0;}" HAVE___INT64)
157     ENDIF()
158     IF(NOT "${HAVE___INT64}")
159         IF(NOT "${SIZEOF_LONG}" MATCHES "8")
160             IF(NOT "${SIZEOF_LONG_LONG}" MATCHES "8")
161                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
162             ENDIF()
163         ENDIF()
164     ENDIF()
165 ENDIF()
168 SET(OPENAL_OBJS  OpenAL32/alBuffer.c
169                  OpenAL32/alError.c
170                  OpenAL32/alExtension.c
171                  OpenAL32/alListener.c
172                  OpenAL32/alSource.c
173                  OpenAL32/alState.c
174                  OpenAL32/alThunk.c
175                  OpenAL32/OpenAL32.c
177 SET(ALC_OBJS  Alc/ALc.c
178               Alc/ALu.c
179               Alc/alcConfig.c
180               Alc/alcRing.c
181               Alc/alcThread.c
184 SET(BACKENDS "")
186 # Check ALSA backend
187 IF(ALSA)
188     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
189     IF("${HAVE_ALSA_ASOUNDLIB_H}")
190         CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
191         IF("${HAVE_DLFCN_H}" OR "${HAVE_LIBASOUND}")
192             SET(HAVE_ALSA 1)
193             SET(ALC_OBJS  ${ALC_OBJS} Alc/alsa.c)
194             IF("${HAVE_DLFCN_H}")
195                 SET(BACKENDS  ${BACKENDS} ALSA)
196             ELSE()
197                 SET(BACKENDS  ${BACKENDS} ALSA\(linked\))
198                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
199             ENDIF()
200         ENDIF()
201     ENDIF()
202 ENDIF()
204 # Check OSS backend
205 IF(OSS)
206     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
207     IF("${HAVE_SYS_SOUNDCARD_H}")
208         SET(HAVE_OSS 1)
209         SET(ALC_OBJS  ${ALC_OBJS} Alc/oss.c)
210         SET(BACKENDS  ${BACKENDS} OSS)
211     ENDIF()
212 ENDIF()
214 # Check DSound/MMSystem backend
215 IF("${HAVE_WINDOWS_H}")
216     SET(CMAKE_REQUIRED_LIBRARIES ole32)
217     CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBOLE32)
218     SET(CMAKE_REQUIRED_LIBRARIES "")
219 #    CHECK_LIBRARY_EXISTS(ole32 CoInitialize "" HAVE_LIBOLE32)
220     IF("${HAVE_LIBOLE32}")
221         SET(EXTRA_LIBS ole32 ${EXTRA_LIBS})
222     ENDIF()
224     IF(DSOUND)
225         CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
226         IF("${HAVE_DSOUND_H}")
227             SET(HAVE_DSOUND 1)
228             SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
229             SET(BACKENDS  ${BACKENDS} DirectSound)
231             CHECK_LIBRARY_EXISTS(dxguid IID_IDirectSound "" HAVE_LIBDXGUID)
232             IF("${HAVE_LIBDXGUID}")
233                 SET(EXTRA_LIBS dxguid ${EXTRA_LIBS})
234             ENDIF()
235         ENDIF()
236     ENDIF()
237     IF(WINMM)
238         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
239         IF("${HAVE_MMSYSTEM_H}")
240             SET(HAVE_WINMM 1)
241             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
242             SET(BACKENDS  ${BACKENDS} WinMM)
244             SET(CMAKE_REQUIRED_LIBRARIES winmm)
245             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
246             SET(CMAKE_REQUIRED_LIBRARIES "")
247 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
248             IF("${HAVE_LIBWINMM}")
249                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
250             ENDIF()
251         ENDIF()
252     ENDIF()
253 ENDIF()
255 # End configuration
256 CONFIGURE_FILE(
257     "${OpenAL_SOURCE_DIR}/config.h.in"
258     "${OpenAL_BINARY_DIR}/config.h")
260 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
262 # Build a shared library
263 IF("${WIN32}")
264     SET(LIBNAME openal32)
265 ELSE()
266     SET(LIBNAME openal)
267 ENDIF()
269 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
270 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION}
271                                             SOVERSION ${LIB_MAJOR_VERSION})
272 IF("${WIN32}")
273     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
274 ENDIF()
276 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
278 # Add an install target here
279 INSTALL(TARGETS ${LIBNAME}
280         RUNTIME DESTINATION bin
281         LIBRARY DESTINATION lib
282         ARCHIVE DESTINATION lib
284 INSTALL(FILES include/AL/al.h
285               include/AL/alc.h
286         DESTINATION include/AL
289 MESSAGE(STATUS "")
290 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
291 MESSAGE(STATUS "    ${BACKENDS}")
292 MESSAGE(STATUS "")