Fix default CMAKE_FIND_ROOT_PATH for XCompile.txt
[alure.git] / CMakeLists.txt
blob87ba54905465620925d0096586688e1bf391c1c7
1 # CMakeLists.txt for ALURE
2 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
4 IF(COMMAND CMAKE_POLICY)
5     CMAKE_POLICY(SET CMP0003 NEW)
6 ENDIF(COMMAND CMAKE_POLICY)
8 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
10 INCLUDE(CheckCCompilerFlag)
11 INCLUDE(CheckCSourceCompiles)
12 INCLUDE(CheckFunctionExists)
13 INCLUDE(CheckIncludeFile)
14 INCLUDE(CheckIncludeFiles)
15 INCLUDE(CheckLibraryExists)
16 INCLUDE(CheckSharedLibraryExists)
17 INCLUDE(FindPkgConfig)
18 INCLUDE(UsePkgConfig)
19 INCLUDE(CheckFileOffsetBits)
21 PROJECT(ALURE)
23 IF(WIN32)
24     SET(LIBNAME ALURE32)
25 ELSE(WIN32)
26     SET(LIBNAME alure)
27 ENDIF(WIN32)
29 SET(LIB_MAJOR_VERSION "1")
30 SET(LIB_MINOR_VERSION "1")
31 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}")
34 INCLUDE_DIRECTORIES(include "${ALURE_BINARY_DIR}")
37 OPTION(BUILD_SHARED "Build the shared version of the library" ON)
38 OPTION(BUILD_STATIC "Build the static version of the library" ON)
40 IF(NOT BUILD_SHARED AND NOT BUILD_STATIC)
41     MESSAGE(FATAL_ERROR "No libtype being built!")
42 ENDIF(NOT BUILD_SHARED AND NOT BUILD_STATIC)
44 IF(NOT CMAKE_BUILD_TYPE)
45     SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
46         "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel."
47         FORCE)
48 ENDIF(NOT CMAKE_BUILD_TYPE)
49 IF(NOT DEFINED CMAKE_DEBUG_POSTFIX)
50     SET(CMAKE_DEBUG_POSTFIX "" CACHE STRING
51         "Library postfix for debug builds. Normally left blank."
52         FORCE)
53 ENDIF(NOT DEFINED CMAKE_DEBUG_POSTFIX)
56 CHECK_SHARED_LIBRARY_EXISTS(stdc++ memset "" HAS_STDCXX)
57 IF(HAS_STDCXX)
58     SET(EXTRA_LIBS stdc++ ${EXTRA_LIBS})
59 ENDIF(HAS_STDCXX)
61 CHECK_SHARED_LIBRARY_EXISTS(m pow "" HAS_LIBM)
62 IF(HAS_LIBM)
63     SET(EXTRA_LIBS m ${EXTRA_LIBS})
64 ENDIF(HAS_LIBM)
66 CHECK_FILE_OFFSET_BITS()
67 IF(_FILE_OFFSET_BITS)
68     ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
69     SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D_FILE_OFFSET_BITS=${_FILE_OFFSET_BITS})
70 ENDIF(_FILE_OFFSET_BITS)
72 CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO)
73 IF(NOT HAVE_FSEEKO)
74     CHECK_FUNCTION_EXISTS(_fseeki64 HAVE__FSEEKI64)
75 ENDIF(NOT HAVE_FSEEKO)
77 SET(STATIC_CFLAGS "${STATIC_CFLAGS} -DALURE_STATIC_LIBRARY")
79 IF(MSVC)
80     # ???
81 ELSE(MSVC)
82     IF(NOT WIN32)
83         CHECK_C_SOURCE_COMPILES("int foo() __attribute__((constructor));
84                                  int main() {return 0;}" HAVE_GCC_CONSTRUCTOR)
86         CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_GCC_VISIBILITY)
87         IF(HAVE_GCC_VISIBILITY)
88             ADD_DEFINITIONS(-fvisibility=hidden)
89         ENDIF(HAVE_GCC_VISIBILITY)
91         # Force -fPIC for the static lib, because it causes problems when the
92         # static version is linked to a dynamic lib
93         SET(STATIC_CFLAGS "${STATIC_CFLAGS} -fPIC")
94     ENDIF(NOT WIN32)
96     CHECK_C_COMPILER_FLAG(-Wextra HAVE_WEXTRA)
97     IF(HAVE_WEXTRA)
98         ADD_DEFINITIONS(-Wextra)
99     ENDIF(HAVE_WEXTRA)
100     ADD_DEFINITIONS(-Wall)
102     CHECK_C_COMPILER_FLAG(-funswitch-loops HAVE_FUNSWITCH_LOOPS)
103     IF(HAVE_FUNSWITCH_LOOPS)
104         ADD_DEFINITIONS(-funswitch-loops)
105     ENDIF(HAVE_FUNSWITCH_LOOPS)
106 ENDIF(MSVC)
109 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
110 IF(HAVE_WINDOWS_H)
111     CHECK_INCLUDE_FILE(ddk/ntddcdrm.h HAVE_DDK_NTDDCDRM_H)
112 ELSE(HAVE_WINDOWS_H)
113     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
114     IF(HAVE_PTHREAD)
115         ADD_DEFINITIONS(-pthread)
116         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
117     ENDIF(HAVE_PTHREAD)
119     # We need pthreads outside of Windows
120     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
121     IF(NOT HAVE_PTHREAD_H)
122         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
123     ENDIF()
124     # Some systems need pthread_np.h to get recursive mutexes
125     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
127     # _GNU_SOURCE is needed on some systems for extra attributes, and
128     # _REENTRANT is needed for libc thread-safety
129     ADD_DEFINITIONS(-D_GNU_SOURCE=1)
130     CHECK_FUNCTION_EXISTS(pthread_create HAS_PTHREAD_CREATE)
131     IF(NOT HAS_PTHREAD_CREATE)
132         CHECK_SHARED_LIBRARY_EXISTS(pthread pthread_create "" HAVE_LIBPTHREAD)
133         IF(NOT HAVE_LIBPTHREAD)
134             MESSAGE(FATAL_ERROR "pthread_create not found on non-Windows target!")
135         ENDIF(NOT HAVE_LIBPTHREAD)
136         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
137     ENDIF(NOT HAS_PTHREAD_CREATE)
139     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
140     IF(NOT HAVE_NANOSLEEP)
141         MESSAGE(FATAL_ERROR "No sleep function found!")
142     ENDIF(NOT HAVE_NANOSLEEP)
143 ENDIF(HAVE_WINDOWS_H)
145 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
146 CHECK_INCLUDE_FILE(sys/wait.h HAVE_SYS_WAIT_H)
147 CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H)
148 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
150 IF(HAVE_DLFCN_H)
151     CHECK_SHARED_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
152     IF(HAVE_LIBDL)
153         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
154     ENDIF(HAVE_LIBDL)
155 ENDIF(HAVE_DLFCN_H)
157 OPTION(DYNLOAD    "Dynamically load support libs at run-time" ON)
158 OPTION(SNDFILE    "SoundFile support (for various formats)" ON)
159 OPTION(VORBIS     "VorbisFile support (for Ogg Vorbis)"  ON)
160 OPTION(FLAC       "FLAC support (for FLAC and Ogg FLAC)" ON)
161 OPTION(MPG123     "MPG123 support (for MP1/MP2/MP3)" ON)
162 OPTION(DUMB       "DUMB support (for IT/XM/S3M/MOD)" ON)
163 OPTION(MODPLUG    "ModPlug support (for IT/XM/S3M/MOD)" OFF)
164 OPTION(FLUIDSYNTH "FluidSynth support (for MID)" ON)
166 IF(WIN32)
167     ADD_DEFINITIONS(-D_WIN32)
169     IF(CMAKE_SIZEOF_VOID_P MATCHES "8")
170         SET(WIN_TYPE Win64)
171         SET(XBITS x64)
172     ELSE(CMAKE_SIZEOF_VOID_P MATCHES "8")
173         SET(WIN_TYPE Win32)
174         SET(XBITS x86)
175     ENDIF(CMAKE_SIZEOF_VOID_P MATCHES "8")
177     SET(OPENAL_SEARCH_PATHS
178         ENV ALSDK_DIR
179         ENV MINGDIR
180         "C:/Program Files/OpenAL 1.1 SDK"
181         "C:/Program Files (x86)/OpenAL 1.1 SDK"
182         "E:/Programs/Dev/OpenAL"
183         "E:/Program Files (x86)/OpenAL 1.1 SDK" )
185     FIND_PATH(OPENAL_INCLUDE_DIR al.h
186               PATHS ${OPENAL_SEARCH_PATHS}
187               PATH_SUFFIXES include include/AL )
188     IF(OPENAL_INCLUDE_DIR)
189         INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
190         FIND_LIBRARY(OPENAL_LIBRARIES OpenAL32
191                      PATHS ${OPENAL_SEARCH_PATHS}
192                      PATH_SUFFIXES lib libs/${WIN_TYPE} )
193     ENDIF(OPENAL_INCLUDE_DIR)
195     IF(NOT OPENAL_LIBRARIES)
196         MESSAGE(FATAL_ERROR "OpenAL not found!\nPlease try setting the ALSDK_DIR environment variable and try again.")
197     ENDIF(NOT OPENAL_LIBRARIES)
199     MESSAGE(STATUS "OpenAL include: ${OPENAL_INCLUDE_DIR}")
200     MESSAGE(STATUS "OpenAL lib: ${OPENAL_LIBRARIES}")
201 ELSE(WIN32)
202     IF(NOT HAVE_DLFCN_H OR NOT HAVE_LIBDL)
203         SET(DYNLOAD OFF)
204     ENDIF(NOT HAVE_DLFCN_H OR NOT HAVE_LIBDL)
206     PKG_CHECK_MODULES(OPENAL openal)
207     IF(NOT OPENAL_FOUND)
208         IF(APPLE)
209             CHECK_INCLUDE_FILE(OpenAL/al.h HAVE_OPENAL_AL_H)
210             IF(HAVE_OPENAL_AL_H)
211                 SET(OPENAL_LIBRARIES "-framework OpenAL")
212                 SET(HAS_OPENAL 1)
213             ENDIF(HAVE_OPENAL_AL_H)
214         ELSE(APPLE)
215             CHECK_INCLUDE_FILE(AL/al.h HAVE_AL_AL_H)
216             IF(HAVE_AL_AL_H)
217                 CHECK_SHARED_LIBRARY_EXISTS(openal alcOpenDevice "" HAS_OPENAL)
218                 IF(HAS_OPENAL)
219                     SET(OPENAL_LIBRARIES openal)
220                 ENDIF(HAS_OPENAL)
221             ENDIF(HAVE_AL_AL_H)
222         ENDIF(APPLE)
223         IF(NOT HAS_OPENAL)
224             MESSAGE(FATAL_ERROR "OpenAL not found!")
225         ENDIF(NOT HAS_OPENAL)
226     ELSE(NOT OPENAL_FOUND)
227         INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIRS})
228         LINK_DIRECTORIES(${OPENAL_LIBRARY_DIRS})
229     ENDIF(NOT OPENAL_FOUND)
230 ENDIF(WIN32)
232 # Base source files
233 SET(ALURE_OBJS  src/alure.cpp
234                 src/buffer.cpp
235                 src/istream.cpp
236                 src/stream.cpp
237                 src/streamdec.cpp
238                 src/streamplay.cpp
239                 src/codec_wav.cpp
240                 src/codec_aiff.cpp
243 # SndFile support
244 IF(SNDFILE)
245     PKG_CHECK_MODULES(SNDFILE sndfile)
246     IF(NOT SNDFILE_FOUND)
247         CHECK_INCLUDE_FILE(sndfile.h HAVE_SNDFILE_H)
248         IF(HAVE_SNDFILE_H)
249             CHECK_SHARED_LIBRARY_EXISTS(sndfile sf_open "" HAVE_LIBSNDFILE)
250             CHECK_SHARED_LIBRARY_EXISTS(libsndfile-1 sf_open "" HAVE_LIBSNDFILE1)
251             IF(DYNLOAD OR HAVE_LIBSNDFILE OR HAVE_LIBSNDFILE1)
252                 SET(HAS_SNDFILE 1)
253                 IF(HAVE_LIBSNDFILE)
254                     SET(SNDFILE_LIBRARIES "sndfile")
255                 ELSEIF(HAVE_LIBSNDFILE1)
256                     SET(SNDFILE_LIBRARIES "libsndfile-1")
257                 ENDIF(HAVE_LIBSNDFILE)
258             ENDIF(DYNLOAD OR HAVE_LIBSNDFILE OR HAVE_LIBSNDFILE1)
259         ENDIF(HAVE_SNDFILE_H)
260     ELSE(NOT SNDFILE_FOUND)
261         SET(HAS_SNDFILE 1)
262         LINK_DIRECTORIES(${SNDFILE_LIBRARY_DIRS})
263         SET_SOURCE_FILES_PROPERTIES(src/codec_sndfile.cpp PROPERTIES
264                                     COMPILE_FLAGS "${SNDFILE_CFLAGS}")
265     ENDIF(NOT SNDFILE_FOUND)
266     IF(HAS_SNDFILE)
267         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_sndfile.cpp)
268     ENDIF(HAS_SNDFILE)
269 ELSE(SNDFILE)
270     SET(SNDFILE_LIBRARIES "")
271 ENDIF(SNDFILE)
273 # Vorbis support
274 IF(VORBIS)
275     PKG_CHECK_MODULES(VORBISFILE vorbisfile)
276     IF(NOT VORBISFILE_FOUND)
277         CHECK_INCLUDE_FILE(vorbis/vorbisfile.h HAVE_VORBIS_VORBISFILE_H)
278         IF(HAVE_VORBIS_VORBISFILE_H)
279             CHECK_SHARED_LIBRARY_EXISTS(vorbisfile ov_open "" HAVE_LIBVORBISFILE)
280             IF(DYNLOAD OR HAVE_LIBVORBISFILE)
281                 SET(HAS_VORBISFILE 1)
282                 IF(HAVE_LIBVORBISFILE)
283                     SET(VORBISFILE_LIBRARIES "vorbisfile")
284                 ENDIF(HAVE_LIBVORBISFILE)
285             ENDIF(DYNLOAD OR HAVE_LIBVORBISFILE)
286         ENDIF(HAVE_VORBIS_VORBISFILE_H)
287     ELSE(NOT VORBISFILE_FOUND)
288         SET(HAS_VORBISFILE 1)
289         LINK_DIRECTORIES(${VORBISFILE_LIBRARY_DIRS})
290         SET_SOURCE_FILES_PROPERTIES(src/codec_vorbisfile.cpp PROPERTIES
291                                     COMPILE_FLAGS "${VORBISFILE_CFLAGS}")
292     ENDIF(NOT VORBISFILE_FOUND)
293     IF(NOT HAS_VORBISFILE)
294         PKG_CHECK_MODULES(VORBISIDEC vorbisidec)
295         IF(NOT VORBISIDEC_FOUND)
296             CHECK_INCLUDE_FILE(tremor/ivorbisfile.h HAVE_TREMOR_IVORBISFILE_H)
297             IF(HAVE_TREMOR_IVORBISFILE_H)
298                 CHECK_SHARED_LIBRARY_EXISTS(vorbisidec ov_open "" HAVE_LIBVORBISIDEC)
299                 IF(DYNLOAD OR HAVE_LIBVORBISIDEC)
300                     SET(HAS_VORBISFILE 1)
301                     IF(HAVE_LIBVORBISIDEC)
302                         SET(VORBISFILE_LIBRARIES "vorbisidec")
303                     ENDIF(HAVE_LIBVORBISIDEC)
304                     SET_SOURCE_FILES_PROPERTIES(src/codec_vorbisfile.cpp PROPERTIES
305                                                 COMPILE_FLAGS "-DHAS_VORBISIDEC")
306                 ENDIF(DYNLOAD OR HAVE_LIBVORBISIDEC)
307             ENDIF(HAVE_TREMOR_IVORBISFILE_H)
308         ELSE(NOT VORBISIDEC_FOUND)
309             SET(HAS_VORBISFILE 1)
310             LINK_DIRECTORIES(${VORBISIDEC_LIBRARY_DIRS})
311             SET_SOURCE_FILES_PROPERTIES(src/codec_vorbisfile.cpp PROPERTIES
312                                         COMPILE_FLAGS "${VORBISIDEC_CFLAGS} -DHAS_VORBISIDEC")
313         ENDIF(NOT VORBISIDEC_FOUND)
314     ENDIF(NOT HAS_VORBISFILE)
315     IF(HAS_VORBISFILE)
316         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_vorbisfile.cpp)
317     ENDIF(HAS_VORBISFILE)
318 ELSE(VORBIS)
319     SET(VORBISFILE_LIBRARIES "")
320 ENDIF(VORBIS)
322 # FLAC support
323 IF(FLAC)
324     #PKG_CHECK_MODULES(LIBFLAC flac)
325     #IF(NOT LIBFLAC_FOUND)
326         CHECK_INCLUDE_FILE(FLAC/all.h HAVE_FLAC_ALL_H)
327         IF(HAVE_FLAC_ALL_H)
328             CHECK_SHARED_LIBRARY_EXISTS(FLAC FLAC__stream_decoder_new "" HAVE_LIBFLAC)
329             IF(DYNLOAD OR HAVE_LIBFLAC)
330                 SET(HAS_FLAC 1)
331                 IF(HAVE_LIBFLAC)
332                     SET(LIBFLAC_LIBRARIES "FLAC")
333                 ENDIF(HAVE_LIBFLAC)
334             ENDIF(DYNLOAD OR HAVE_LIBFLAC)
335         ENDIF(HAVE_FLAC_ALL_H)
336     #ELSE(NOT LIBFLAC_FOUND)
337     #    SET(HAS_FLAC 1)
338     #    INCLUDE_DIRECTORIES(${LIBFLAC_INCLUDE_DIRS})
339     #    LINK_DIRECTORIES(${LIBFLAC_LIBRARY_DIRS})
340     #ENDIF(NOT LIBFLAC_FOUND)
341     IF(HAS_FLAC)
342         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_flac.cpp)
343     ENDIF(HAS_FLAC)
344 ELSE(FLAC)
345     SET(LIBFLAC_LIBRARIES "")
346 ENDIF(FLAC)
348 # MPG123 support
349 IF(MPG123)
350     PKG_CHECK_MODULES(MPG123 libmpg123)
351     IF(NOT MPG123_FOUND)
352         CHECK_INCLUDE_FILE(mpg123.h HAVE_MPG123_H)
353         IF(HAVE_MPG123_H)
354             CHECK_SHARED_LIBRARY_EXISTS(mpg123 mpg123_init "" HAVE_LIBMPG123)
355             IF(DYNLOAD OR HAVE_LIBMPG123)
356                 SET(HAS_MPG123 1)
357                 IF(HAVE_LIBMPG123)
358                     SET(MPG123_LIBRARIES "mpg123")
359                 ENDIF(HAVE_LIBMPG123)
360             ENDIF(DYNLOAD OR HAVE_LIBMPG123)
361         ENDIF(HAVE_MPG123_H)
362     ELSE(NOT MPG123_FOUND)
363         SET(HAS_MPG123 1)
364         LINK_DIRECTORIES(${MPG123_LIBRARY_DIRS})
365         SET_SOURCE_FILES_PROPERTIES(src/codec_mpg123.cpp PROPERTIES
366                                     COMPILE_FLAGS "${MPG123_CFLAGS}")
367     ENDIF(NOT MPG123_FOUND)
368     IF(HAS_MPG123)
369         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_mpg123.cpp)
370     ENDIF(HAS_MPG123)
371 ELSE(MPG123)
372     SET(MPG123_LIBRARIES "")
373 ENDIF(MPG123)
375 # DUMB support
376 IF(DUMB)
377     CHECK_INCLUDE_FILE(dumb.h HAVE_DUMB_H)
378     IF(HAVE_DUMB_H)
379         IF(HAS_LIBM)
380             CHECK_LIBRARY_EXISTS("dumb;m" dumbfile_open_ex "" HAVE_LIBDUMB)
381         ELSE(HAS_LIBM)
382             CHECK_LIBRARY_EXISTS(dumb dumbfile_open_ex "" HAVE_LIBDUMB)
383         ENDIF(HAS_LIBM)
384         IF(DYNLOAD OR HAVE_LIBDUMB)
385             SET(HAS_DUMB 1)
386             IF(HAVE_LIBDUMB)
387                 SET(DUMB_LIBRARIES dumb)
388             ENDIF(HAVE_LIBDUMB)
389         ENDIF(DYNLOAD OR HAVE_LIBDUMB)
390     ENDIF(HAVE_DUMB_H)
391     IF(HAS_DUMB)
392         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_dumb.cpp)
393     ENDIF(HAS_DUMB)
394 ELSE(DUMB)
395     SET(DUMB_LIBRARIES "")
396 ENDIF(DUMB)
398 # ModPlug support
399 IF(MODPLUG)
400     PKG_CHECK_MODULES(MODPLUG libmodplug)
401     IF(NOT MODPLUG_FOUND)
402         CHECK_INCLUDE_FILE(modplug.h HAVE_MODPLUG_H)
403         IF(HAVE_MODPLUG_H)
404             CHECK_SHARED_LIBRARY_EXISTS(modplug ModPlug_Load "" HAVE_LIBMODPLUG)
405             IF(DYNLOAD OR HAVE_LIBMODPLUG)
406                 SET(HAS_MODPLUG 1)
407                 IF(HAVE_LIBMODPLUG)
408                     SET(MODPLUG_LIBRARIES "modplug")
409                 ENDIF(HAVE_LIBMODPLUG)
410             ENDIF(DYNLOAD OR HAVE_LIBMODPLUG)
411         ENDIF(HAVE_MODPLUG_H)
412     ELSE(NOT MODPLUG_FOUND)
413         SET(HAS_MODPLUG 1)
414         LINK_DIRECTORIES(${MODPLUG_LIBRARY_DIRS})
415         SET_SOURCE_FILES_PROPERTIES(src/codec_modplug.cpp PROPERTIES
416                                     COMPILE_FLAGS "${MODPLUG_CFLAGS}")
417     ENDIF(NOT MODPLUG_FOUND)
418     IF(HAS_MODPLUG)
419         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_modplug.cpp)
420     ENDIF(HAS_MODPLUG)
421 ELSE(MODPLUG)
422     SET(MODPLUG_LIBRARIES "")
423 ENDIF(MODPLUG)
425 # FluidSynth support
426 IF(FLUIDSYNTH)
427     PKG_CHECK_MODULES(FLUIDSYNTH fluidsynth>=1.1.1)
428     IF(NOT FLUIDSYNTH_FOUND)
429         CHECK_INCLUDE_FILE(fluidsynth.h HAVE_FLUIDSYNTH_H)
430         IF(HAVE_FLUIDSYNTH_H)
431             CHECK_SHARED_LIBRARY_EXISTS(fluidsynth new_fluid_synth "" HAVE_LIBFLUIDSYNTH)
432             IF(DYNLOAD OR HAVE_LIBFLUIDSYNTH)
433                 SET(HAS_FLUIDSYNTH 1)
434                 IF(HAVE_LIBFLUIDSYNTH)
435                     SET(FLUIDSYNTH_LIBRARIES "fluidsynth")
436                 ENDIF(HAVE_LIBFLUIDSYNTH)
437             ENDIF(DYNLOAD OR HAVE_LIBFLUIDSYNTH)
438         ENDIF(HAVE_FLUIDSYNTH_H)
439     ELSE(NOT FLUIDSYNTH_FOUND)
440         SET(HAS_FLUIDSYNTH 1)
441         LINK_DIRECTORIES(${FLUIDSYNTH_LIBRARY_DIRS})
442         SET_SOURCE_FILES_PROPERTIES(src/codec_fluidsynth.cpp PROPERTIES
443                                     COMPILE_FLAGS "${FLUIDSYNTH_CFLAGS}")
444     ENDIF(NOT FLUIDSYNTH_FOUND)
445     IF(HAS_FLUIDSYNTH)
446         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_fluidsynth.cpp)
447     ENDIF(HAS_FLUIDSYNTH)
448 ELSE(FLUIDSYNTH)
449     SET(FLUIDSYNTH_LIBRARIES "")
450 ENDIF(FLUIDSYNTH)
453 IF(NOT DYNLOAD)
454     SET(EXTRA_LIBS ${SNDFILE_LIBRARIES} ${VORBISFILE_LIBRARIES} ${LIBFLAC_LIBRARIES} ${MPG123_LIBRARIES} ${DUMB_LIBRARIES} ${MODPLUG_LIBRARIES} ${FLUIDSYNTH_LIBRARIES} ${EXTRA_LIBS})
455 ELSE(NOT DYNLOAD)
456     ADD_DEFINITIONS(-DDYNLOAD=1)
457 ENDIF(NOT DYNLOAD)
459 # For alure.pc.in
460 SET(prefix ${CMAKE_INSTALL_PREFIX})
461 SET(exec_prefix "\${prefix}")
462 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
463 SET(bindir "\${exec_prefix}/bin")
464 SET(includedir "\${prefix}/include")
465 SET(PKG_CONFIG_REQUIRES openal)
466 SET(PACKAGE_VERSION "${LIB_VERSION}")
468 # End configuration
469 CONFIGURE_FILE(
470     "${ALURE_SOURCE_DIR}/config.h.in"
471     "${ALURE_BINARY_DIR}/config.h")
472 IF(BUILD_SHARED)
473     CONFIGURE_FILE(
474         "${ALURE_SOURCE_DIR}/alure.pc.in"
475         "${ALURE_BINARY_DIR}/alure.pc"
476         @ONLY)
477 ENDIF(BUILD_SHARED)
478 IF(BUILD_STATIC)
479     CONFIGURE_FILE(
480         "${ALURE_SOURCE_DIR}/alure-static.pc.in"
481         "${ALURE_BINARY_DIR}/alure-static.pc"
482         @ONLY)
483 ENDIF(BUILD_STATIC)
485 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
488 IF(BUILD_SHARED)
489     #build a shared library
490     ADD_LIBRARY(${LIBNAME} SHARED ${ALURE_OBJS})
491     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL ALURE_BUILD_LIBRARY
492                                                 VERSION ${LIB_VERSION}.0
493                                                 SOVERSION ${LIB_MAJOR_VERSION})
494     IF(WIN32)
495         SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
496     ELSE(WIN32)
497         SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES LINK_FLAGS "-Wl,--version-script=${ALURE_SOURCE_DIR}/libalure.map")
498     ENDIF(WIN32)
499     TARGET_LINK_LIBRARIES(${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
501     INSTALL(TARGETS ${LIBNAME}
502             RUNTIME DESTINATION bin
503             LIBRARY DESTINATION lib${LIB_SUFFIX}
504             ARCHIVE DESTINATION lib${LIB_SUFFIX}
506 ENDIF(BUILD_SHARED)
507 IF(BUILD_STATIC)
508     #build a static library
509     ADD_LIBRARY(${LIBNAME}-static STATIC ${ALURE_OBJS})
510     SET_TARGET_PROPERTIES(${LIBNAME}-static PROPERTIES DEFINE_SYMBOL ALURE_BUILD_LIBRARY
511                                                        COMPILE_FLAGS ${STATIC_CFLAGS}
512                                                        VERSION ${LIB_VERSION}.0)
513     INSTALL(TARGETS ${LIBNAME}-static
514             RUNTIME DESTINATION bin
515             LIBRARY DESTINATION lib${LIB_SUFFIX}
516             ARCHIVE DESTINATION lib${LIB_SUFFIX}
518 ENDIF(BUILD_STATIC)
521 IF(HAVE_DDK_NTDDCDRM_H)
522     SET_SOURCE_FILES_PROPERTIES(examples/alurecdplay.c PROPERTIES
523                                 COMPILE_FLAGS "-DHAVE_DDK_NTDDCDRM_H")
524 ENDIF(HAVE_DDK_NTDDCDRM_H)
525 ADD_EXECUTABLE(alureplay examples/alureplay.c)
526 ADD_EXECUTABLE(alurecdplay examples/alurecdplay.c)
527 ADD_EXECUTABLE(alurestream examples/alurestream.c)
528 IF(BUILD_SHARED)
529     TARGET_LINK_LIBRARIES(alureplay ${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
530     TARGET_LINK_LIBRARIES(alurecdplay ${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
531     TARGET_LINK_LIBRARIES(alurestream ${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
532 ELSE(BUILD_SHARED)
533     SET_TARGET_PROPERTIES(alureplay PROPERTIES COMPILE_FLAGS -DALURE_STATIC_LIBRARY)
534     SET_TARGET_PROPERTIES(alurecdplay PROPERTIES COMPILE_FLAGS -DALURE_STATIC_LIBRARY)
535     SET_TARGET_PROPERTIES(alurestream PROPERTIES COMPILE_FLAGS -DALURE_STATIC_LIBRARY)
536     TARGET_LINK_LIBRARIES(alureplay ${LIBNAME}-static ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
537     TARGET_LINK_LIBRARIES(alurecdplay ${LIBNAME}-static ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
538     TARGET_LINK_LIBRARIES(alurestream ${LIBNAME}-static ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
539 ENDIF(BUILD_SHARED)
542 FIND_PROGRAM(NATDOCS_BIN NaturalDocs)
543 IF(NATDOCS_BIN)
544     ADD_CUSTOM_TARGET(docs
545                       "${NATDOCS_BIN}" -i "${ALURE_SOURCE_DIR}/src" -o HTML "${ALURE_SOURCE_DIR}/docs/html" -p "${ALURE_SOURCE_DIR}/docs/naturaldocs" -s Default CustomStyle
546                       COMMENT "Building NaturalDocs documentation..." VERBATIM)
547 ELSE(NATDOCS_BIN)
548     MESSAGE(STATUS "\nNaturalDocs not found; building documentation is disabled")
549 ENDIF(NATDOCS_BIN)
552 #add an install target here
553 IF(APPLE)
554     SET(INCPATH OpenAL)
555 ELSE(APPLE)
556     SET(INCPATH AL)
557 ENDIF(APPLE)
559 INSTALL(DIRECTORY "${ALURE_SOURCE_DIR}/docs/html"
560         DESTINATION share/doc/alure
562 INSTALL(FILES include/AL/alure.h
563         DESTINATION "include/${INCPATH}"
565 IF(BUILD_SHARED)
566     INSTALL(FILES "${ALURE_BINARY_DIR}/alure.pc"
567             DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
568     )
569 ENDIF(BUILD_SHARED)
570 IF(BUILD_STATIC)
571     INSTALL(FILES "${ALURE_BINARY_DIR}/alure-static.pc"
572             DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
573     )
574 ENDIF(BUILD_STATIC)
577 MESSAGE(STATUS "\n********************** Configured options **********************")
578 IF(BUILD_SHARED AND BUILD_STATIC)
579     MESSAGE(STATUS "Building shared, static library")
580 ELSEIF(BUILD_SHARED)
581     MESSAGE(STATUS "Building shared library")
582 ELSE(BUILD_SHARED AND BUILD_STATIC)
583     MESSAGE(STATUS "Building static library")
584 ENDIF(BUILD_SHARED AND BUILD_STATIC)
585 MESSAGE(STATUS "")
586 IF(HAS_SNDFILE)
587     MESSAGE(STATUS "SndFile support: enabled")
588 ELSE(HAS_SNDFILE)
589     MESSAGE(STATUS "SndFile support: disabled")
590 ENDIF(HAS_SNDFILE)
591 IF(HAS_VORBISFILE)
592     MESSAGE(STATUS "VorbisFile support: enabled")
593 ELSE(HAS_VORBISFILE)
594     MESSAGE(STATUS "VorbisFile support: disabled")
595 ENDIF(HAS_VORBISFILE)
596 IF(HAS_FLAC)
597     MESSAGE(STATUS "FLAC support: enabled")
598 ELSE(HAS_FLAC)
599     MESSAGE(STATUS "FLAC support: disabled")
600 ENDIF(HAS_FLAC)
601 IF(HAS_MPG123)
602     MESSAGE(STATUS "MPG123 support: enabled")
603 ELSE(HAS_MPG123)
604     MESSAGE(STATUS "MPG123 support: disabled")
605 ENDIF(HAS_MPG123)
606 IF(HAS_DUMB)
607     MESSAGE(STATUS "DUMB support: enabled")
608 ELSE(HAS_DUMB)
609     MESSAGE(STATUS "DUMB support: disabled")
610 ENDIF(HAS_DUMB)
611 IF(HAS_MODPLUG)
612     MESSAGE(STATUS "ModPlug support: enabled")
613 ELSE(HAS_MODPLUG)
614     MESSAGE(STATUS "ModPlug support: disabled")
615 ENDIF(HAS_MODPLUG)
616 IF(HAS_FLUIDSYNTH)
617     MESSAGE(STATUS "FluidSynth support: enabled")
618 ELSE(HAS_FLUIDSYNTH)
619     MESSAGE(STATUS "FluidSynth support: disabled")
620 ENDIF(HAS_FLUIDSYNTH)
621 MESSAGE(STATUS "")