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