Use the AuxSendAuto property of the effect slot
[openal-soft.git] / CMakeLists.txt
blobd480a0ac5b9bca6db2ab749b002b7178f4120813
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 IF("${WIN32}")
37     SET(LIBNAME openal32)
38 ELSE()
39     SET(LIBNAME openal)
40 ENDIF()
43 CHECK_TYPE_SIZE("long" SIZEOF_LONG)
44 CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
45 CHECK_TYPE_SIZE("unsigned int" SIZEOF_UINT)
46 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDP)
49 # Add definitions, compiler switches, etc.
50 INCLUDE_DIRECTORIES(OpenAL32/Include include "${OpenAL_BINARY_DIR}")
51 SET(EXTRA_LIBS m ${EXTRA_LIBS})
53 IF("${MSVC}")
54     # ???
55 ELSE()
56     ADD_DEFINITIONS(-Wall)
57     CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA)
58     IF("${HAVE_W_EXTRA}")
59         ADD_DEFINITIONS(-Wextra)
60     ENDIF()
62     IF(WERROR)
63         ADD_DEFINITIONS(-Werror)
64     ENDIF()
66     IF(DEBUG)
67         ADD_DEFINITIONS(-g3)
68     ELSEIF(NODEBUG)
69         ADD_DEFINITIONS(-O2 -funroll-loops -fomit-frame-pointer)
70     ELSE()
71         ADD_DEFINITIONS(-g -O2 -funroll-loops)
72     ENDIF()
74     # The mixer doesn't like GCC's strict aliasing optimizations. Make sure
75     # it's turned off
76     CHECK_C_COMPILER_FLAG(-fstrict-aliasing HAVE_STRICT_ALIASING)
77     IF("${HAVE_STRICT_ALIASING}")
78         ADD_DEFINITIONS(-fno-strict-aliasing)
79     ENDIF()
81     # Set visibility options if available
82     IF(NOT "${WIN32}")
83         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((destructor));
84                                  int main() {return 0;}" HAVE_GCC_DESTRUCTOR)
86         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
87         IF("${HAVE_VISIBILITY_SWITCH}")
88             CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"default\")));
89                                      int main() {return 0;}" HAVE_GCC_VISIBILITY)
90             IF("${HAVE_GCC_VISIBILITY}")
91                 ADD_DEFINITIONS(-fvisibility=hidden -DHAVE_GCC_VISIBILITY)
92             ENDIF()
93         ENDIF()
94     ENDIF()
95 ENDIF()
97 IF(DEBUG)
98     ADD_DEFINITIONS(-D_DEBUG)
99 ELSEIF(NODEBUG)
100     ADD_DEFINITIONS(-DNDEBUG)
101 ENDIF()
103 CHECK_LIBRARY_EXISTS(m  sqrtf  "" HAVE_SQRTF)
104 CHECK_FUNCTION_EXISTS(strtof HAVE_STRTOF)
106 CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
107 IF(NOT "${HAVE_STRCASECMP}")
108     CHECK_FUNCTION_EXISTS(_stricmp HAVE__STRICMP)
109     IF(NOT "${HAVE__STRICMP}")
110         MESSAGE(FATAL_ERROR "No case-insensitive compare function found, please report!")
111     ENDIF()
113     ADD_DEFINITIONS(-Dstrcasecmp=_stricmp)
114 ENDIF()
116 # Check for the dlopen API (for dynamicly loading backend libs)
117 IF(DLOPEN)
118     CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
119     IF("${HAVE_DLFCN_H}")
120         CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
121         IF("${HAVE_LIBDL}")
122             SET(EXTRA_LIBS dl ${EXTRA_LIBS})
123         ENDIF()
124     ENDIF()
125 ENDIF()
127 # Check if we have Windows headers
128 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
129 IF(NOT "${HAVE_WINDOWS_H}")
130     # We need pthreads outside of Windows
131     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
132     IF(NOT "${HAVE_PTHREAD_H}")
133         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
134     ENDIF()
136     # _GNU_SOURCE is needed on some systems for extra attributes, and
137     # _REENTRANT is needed for libc thread-safety
138     ADD_DEFINITIONS(-D_GNU_SOURCE=1 -D_REENTRANT)
139     CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
140     IF("${HAVE_LIBPTHREAD}")
141         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
142     ENDIF()
143 ENDIF()
145 # Check for a 64-bit type
146 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
147 IF(NOT "${HAVE_STDINT_H}")
148     IF("${HAVE_WINDOWS_H}")
149         CHECK_C_SOURCE_COMPILES("\#include <windows.h>
150                                  __int64 foo;
151                                  int main() {return 0;}" HAVE___INT64)
152     ENDIF()
153     IF(NOT "${HAVE___INT64}")
154         IF(NOT "${SIZEOF_LONG}" MATCHES "8")
155             IF(NOT "${SIZEOF_LONG_LONG}" MATCHES "8")
156                 MESSAGE(FATAL_ERROR "No 64-bit types found, please report!")
157             ENDIF()
158         ENDIF()
159     ENDIF()
160 ENDIF()
163 SET(OPENAL_OBJS  OpenAL32/alAuxEffectSlot.c
164                  OpenAL32/alBuffer.c
165                  OpenAL32/alEffect.c
166                  OpenAL32/alError.c
167                  OpenAL32/alExtension.c
168                  OpenAL32/alFilter.c
169                  OpenAL32/alListener.c
170                  OpenAL32/alSource.c
171                  OpenAL32/alState.c
172                  OpenAL32/alThunk.c
173                  OpenAL32/OpenAL32.c
175 SET(ALC_OBJS  Alc/ALc.c
176               Alc/ALu.c
177               Alc/alcConfig.c
178               Alc/alcRing.c
179               Alc/alcThread.c
182 SET(BACKENDS "")
184 # Check ALSA backend
185 IF(ALSA)
186     CHECK_INCLUDE_FILE(alsa/asoundlib.h HAVE_ALSA_ASOUNDLIB_H)
187     IF("${HAVE_ALSA_ASOUNDLIB_H}")
188         CHECK_LIBRARY_EXISTS(asound snd_pcm_open "" HAVE_LIBASOUND)
189         IF("${HAVE_DLFCN_H}" OR "${HAVE_LIBASOUND}")
190             SET(HAVE_ALSA 1)
191             SET(ALC_OBJS  ${ALC_OBJS} Alc/alsa.c)
192             IF("${HAVE_DLFCN_H}")
193                 SET(BACKENDS  ${BACKENDS} ALSA)
194             ELSE()
195                 SET(BACKENDS  ${BACKENDS} ALSA\(linked\))
196                 SET(EXTRA_LIBS asound ${EXTRA_LIBS})
197             ENDIF()
198         ENDIF()
199     ENDIF()
200 ENDIF()
202 # Check OSS backend
203 IF(OSS)
204     CHECK_INCLUDE_FILE(sys/soundcard.h HAVE_SYS_SOUNDCARD_H)
205     IF("${HAVE_SYS_SOUNDCARD_H}")
206         SET(HAVE_OSS 1)
207         SET(ALC_OBJS  ${ALC_OBJS} Alc/oss.c)
208         SET(BACKENDS  ${BACKENDS} OSS)
209     ENDIF()
210 ENDIF()
212 # Check DSound/MMSystem backend
213 IF("${HAVE_WINDOWS_H}")
214     SET(CMAKE_REQUIRED_LIBRARIES ole32)
215     CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBOLE32)
216     SET(CMAKE_REQUIRED_LIBRARIES "")
217 #    CHECK_LIBRARY_EXISTS(ole32 CoInitialize "" HAVE_LIBOLE32)
218     IF("${HAVE_LIBOLE32}")
219         SET(EXTRA_LIBS ole32 ${EXTRA_LIBS})
220     ENDIF()
222     IF(DSOUND)
223         CHECK_INCLUDE_FILE(dsound.h HAVE_DSOUND_H)
224         IF("${HAVE_DSOUND_H}")
225             SET(HAVE_DSOUND 1)
226             SET(ALC_OBJS  ${ALC_OBJS} Alc/dsound.c)
227             SET(BACKENDS  ${BACKENDS} DirectSound)
229             CHECK_LIBRARY_EXISTS(dxguid IID_IDirectSound "" HAVE_LIBDXGUID)
230             IF("${HAVE_LIBDXGUID}")
231                 SET(EXTRA_LIBS dxguid ${EXTRA_LIBS})
232             ENDIF()
233         ENDIF()
234     ENDIF()
235     IF(WINMM)
236         CHECK_INCLUDE_FILES("windows.h;mmsystem.h" HAVE_MMSYSTEM_H)
237         IF("${HAVE_MMSYSTEM_H}")
238             SET(HAVE_WINMM 1)
239             SET(ALC_OBJS  ${ALC_OBJS} Alc/winmm.c)
240             SET(BACKENDS  ${BACKENDS} WinMM)
242             SET(CMAKE_REQUIRED_LIBRARIES winmm)
243             CHECK_C_SOURCE_COMPILES("int main() {return 0;}" HAVE_LIBWINMM)
244             SET(CMAKE_REQUIRED_LIBRARIES "")
245 #            CHECK_LIBRARY_EXISTS(winmm waveInOpen "" HAVE_LIBWINMM)
246             IF("${HAVE_LIBWINMM}")
247                 SET(EXTRA_LIBS winmm ${EXTRA_LIBS})
248             ENDIF()
249         ENDIF()
250     ENDIF()
251 ENDIF()
253 # End configuration
254 CONFIGURE_FILE(
255     "${OpenAL_SOURCE_DIR}/config.h.in"
256     "${OpenAL_BINARY_DIR}/config.h")
258 ADD_DEFINITIONS(-DAL_BUILD_LIBRARY)
260 # Build a shared library
261 ADD_LIBRARY(${LIBNAME} SHARED ${OPENAL_OBJS} ${ALC_OBJS})
262 SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION})
264 TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
266 # Add an install target here
267 INSTALL(TARGETS ${LIBNAME}
268         RUNTIME DESTINATION bin
269         LIBRARY DESTINATION lib
270         ARCHIVE DESTINATION lib
272 INSTALL(FILES include/AL/al.h
273               include/AL/alc.h
274         DESTINATION include/AL
277 MESSAGE(STATUS "")
278 MESSAGE(STATUS "Building OpenAL with support for the following backends:")
279 MESSAGE(STATUS "    ${BACKENDS}")
280 MESSAGE(STATUS "")