90d5c26df603847727b44f27ccb55021fb6dc214
[platform/upstream/alure.git] / CMakeLists.txt
1 # CMakeLists.txt for ALURE
2 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
3
4 IF(COMMAND CMAKE_POLICY)
5     CMAKE_POLICY(SET CMP0003 NEW)
6 ENDIF(COMMAND CMAKE_POLICY)
7
8 SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
9
10 INCLUDE(CheckCCompilerFlag)
11 INCLUDE(CheckCSourceCompiles)
12 INCLUDE(CheckFunctionExists)
13 INCLUDE(CheckIncludeFile)
14 INCLUDE(CheckIncludeFiles)
15 INCLUDE(CheckLibraryExists)
16 INCLUDE(CheckSharedFunctionExists)
17 INCLUDE(FindPkgConfig)
18 INCLUDE(UsePkgConfig)
19 INCLUDE(CheckFileOffsetBits)
20
21 PROJECT(ALURE)
22
23 IF(WIN32)
24     SET(LIBNAME ALURE32)
25 ELSE(WIN32)
26     SET(LIBNAME alure)
27 ENDIF(WIN32)
28
29 SET(LIB_MAJOR_VERSION "1")
30 SET(LIB_MINOR_VERSION "2")
31 SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}")
32
33
34 INCLUDE_DIRECTORIES(include "${ALURE_BINARY_DIR}")
35
36
37 OPTION(BUILD_SHARED "Build the shared version of the library" ON)
38 OPTION(BUILD_STATIC "Build the static version of the library" ON)
39
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)
43
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)
54
55
56 CHECK_LIBRARY_EXISTS(stdc++ memset "" HAS_STDCXX)
57 IF(HAS_STDCXX)
58     SET(EXTRA_LIBS stdc++ ${EXTRA_LIBS})
59 ENDIF(HAS_STDCXX)
60
61 CHECK_LIBRARY_EXISTS(m pow "" HAS_LIBM)
62 IF(HAS_LIBM)
63     SET(EXTRA_LIBS m ${EXTRA_LIBS})
64 ENDIF(HAS_LIBM)
65
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)
71
72 CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO)
73 IF(NOT HAVE_FSEEKO)
74     CHECK_FUNCTION_EXISTS(_fseeki64 HAVE__FSEEKI64)
75 ENDIF(NOT HAVE_FSEEKO)
76
77 SET(STATIC_CFLAGS "${STATIC_CFLAGS} -DALURE_STATIC_LIBRARY")
78
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)
85
86         # Force -fPIC for the static lib, because it causes problems when the
87         # static version is linked to a dynamic lib
88         SET(STATIC_CFLAGS "${STATIC_CFLAGS} -fPIC")
89     ENDIF(NOT WIN32)
90
91     CHECK_C_COMPILER_FLAG(-Wextra HAVE_WEXTRA)
92     IF(HAVE_WEXTRA)
93         ADD_DEFINITIONS(-Wextra)
94     ENDIF(HAVE_WEXTRA)
95     ADD_DEFINITIONS(-Wall)
96
97     CHECK_C_COMPILER_FLAG(-funswitch-loops HAVE_FUNSWITCH_LOOPS)
98     IF(HAVE_FUNSWITCH_LOOPS)
99         ADD_DEFINITIONS(-funswitch-loops)
100     ENDIF(HAVE_FUNSWITCH_LOOPS)
101 ENDIF(MSVC)
102
103 # Set visibility/export options if available
104 SET(EXPORT_DECL "")
105 IF(WIN32)
106     SET(EXPORT_DECL "__declspec(dllexport)")
107 ELSE(WIN32)
108     CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_SWITCH)
109     CHECK_C_SOURCE_COMPILES("int foo() __attribute__((visibility(\"protected\")));
110                              int main() {return 0;}" HAVE_GCC_VISIBILITY)
111     IF(HAVE_VISIBILITY_SWITCH AND HAVE_GCC_VISIBILITY)
112         ADD_DEFINITIONS(-fvisibility=hidden)
113         SET(EXPORT_DECL "__attribute__((visibility(\"protected\")))")
114     ENDIF(HAVE_VISIBILITY_SWITCH AND HAVE_GCC_VISIBILITY)
115 ENDIF(WIN32)
116
117
118 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H -D_WIN32_WINNT=0x0500)
119 IF(HAVE_WINDOWS_H)
120     CHECK_INCLUDE_FILE(ddk/ntddcdrm.h HAVE_DDK_NTDDCDRM_H)
121 ELSE(HAVE_WINDOWS_H)
122     CHECK_C_COMPILER_FLAG(-pthread HAVE_PTHREAD)
123     IF(HAVE_PTHREAD)
124         ADD_DEFINITIONS(-pthread)
125         SET(EXTRA_LIBS ${EXTRA_LIBS} -pthread)
126     ENDIF(HAVE_PTHREAD)
127
128     # We need pthreads outside of Windows
129     CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
130     IF(NOT HAVE_PTHREAD_H)
131         MESSAGE(FATAL_ERROR "PThreads is required for non-Windows builds!")
132     ENDIF()
133     # Some systems need pthread_np.h to get recursive mutexes
134     CHECK_INCLUDE_FILES("pthread.h;pthread_np.h" HAVE_PTHREAD_NP_H)
135
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)
139     CHECK_FUNCTION_EXISTS(pthread_create HAS_PTHREAD_CREATE)
140     IF(NOT HAS_PTHREAD_CREATE)
141         CHECK_SHARED_FUNCTION_EXISTS(pthread_create "pthread.h" pthread "" HAVE_LIBPTHREAD)
142         IF(NOT HAVE_LIBPTHREAD)
143             MESSAGE(FATAL_ERROR "pthread_create not found on non-Windows target!")
144         ENDIF(NOT HAVE_LIBPTHREAD)
145         SET(EXTRA_LIBS pthread ${EXTRA_LIBS})
146     ENDIF(NOT HAS_PTHREAD_CREATE)
147
148     CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
149     IF(NOT HAVE_NANOSLEEP)
150         MESSAGE(FATAL_ERROR "No sleep function found!")
151     ENDIF(NOT HAVE_NANOSLEEP)
152 ENDIF(HAVE_WINDOWS_H)
153
154 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
155 CHECK_INCLUDE_FILE(sys/wait.h HAVE_SYS_WAIT_H)
156 CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H)
157 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
158
159 IF(HAVE_DLFCN_H)
160     CHECK_SHARED_FUNCTION_EXISTS(dlopen "dlfcn.h" dl "" HAVE_LIBDL)
161     IF(HAVE_LIBDL)
162         SET(EXTRA_LIBS dl ${EXTRA_LIBS})
163     ENDIF(HAVE_LIBDL)
164 ENDIF(HAVE_DLFCN_H)
165
166 OPTION(DYNLOAD    "Dynamically load support libs at run-time" ON)
167 OPTION(SNDFILE    "SoundFile support (for various formats)" ON)
168 OPTION(VORBIS     "VorbisFile support (for Ogg Vorbis)"  ON)
169 OPTION(FLAC       "FLAC support (for FLAC and Ogg FLAC)" OFF)
170 OPTION(MPG123     "MPG123 support (for MP1/MP2/MP3)" OFF)
171 OPTION(DUMB       "DUMB support (for IT/XM/S3M/MOD)" OFF)
172 OPTION(MODPLUG    "ModPlug support (for IT/XM/S3M/MOD)" OFF)
173 OPTION(FLUIDSYNTH "FluidSynth support (for MID)" OFF)
174
175 IF(WIN32)
176     ADD_DEFINITIONS(-D_WIN32)
177 ELSE(WIN32)
178     IF(NOT HAVE_DLFCN_H OR NOT HAVE_LIBDL)
179         SET(DYNLOAD OFF)
180     ENDIF(NOT HAVE_DLFCN_H OR NOT HAVE_LIBDL)
181     PKG_CHECK_MODULES(OPENAL openal)
182 ENDIF(WIN32)
183
184 IF(NOT OPENAL_FOUND)
185     FIND_PACKAGE(OpenAL)
186     IF(NOT OPENAL_FOUND)
187         MESSAGE(FATAL_ERROR "OpenAL not found!\nPlease try setting the OPENALDIR environment variable and try again.")
188     ENDIF(NOT OPENAL_FOUND)
189
190     MESSAGE(STATUS "OpenAL include: ${OPENAL_INCLUDE_DIR}")
191     MESSAGE(STATUS "OpenAL lib: ${OPENAL_LIBRARY}")
192
193     INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR})
194     SET(OPENAL_LIBRARIES ${OPENAL_LIBRARY})
195 ELSE(NOT OPENAL_FOUND)
196     INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIRS})
197     LINK_DIRECTORIES(${OPENAL_LIBRARY_DIRS})
198 ENDIF(NOT OPENAL_FOUND)
199
200 # Base source files
201 SET(ALURE_OBJS  src/alure.cpp
202                 src/buffer.cpp
203                 src/istream.cpp
204                 src/stream.cpp
205                 src/streamdec.cpp
206                 src/streamplay.cpp
207                 src/codec_wav.cpp
208                 src/codec_aiff.cpp
209 )
210
211 # SndFile support
212 IF(SNDFILE)
213     PKG_CHECK_MODULES(SNDFILE sndfile)
214     IF(SNDFILE_FOUND)
215         SET(HAS_SNDFILE 1)
216         LINK_DIRECTORIES(${SNDFILE_LIBRARY_DIRS})
217         SET_SOURCE_FILES_PROPERTIES(src/codec_sndfile.cpp PROPERTIES
218                                     COMPILE_FLAGS "${SNDFILE_CFLAGS}")
219     ELSE(SNDFILE_FOUND)
220         FIND_PACKAGE(SndFile)
221         IF(SNDFILE_FOUND)
222             SET(HAS_SNDFILE 1)
223             INCLUDE_DIRECTORIES(${SNDFILE_INCLUDE_DIRS})
224         ENDIF(SNDFILE_FOUND)
225     ENDIF(SNDFILE_FOUND)
226     IF(HAS_SNDFILE)
227         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_sndfile.cpp)
228     ENDIF(HAS_SNDFILE)
229 ELSE(SNDFILE)
230     SET(SNDFILE_LIBRARIES "")
231 ENDIF(SNDFILE)
232
233 # Vorbis support
234 IF(VORBIS)
235     PKG_CHECK_MODULES(VORBISFILE vorbisfile)
236     IF(VORBISFILE_FOUND)
237         SET(HAS_VORBISFILE 1)
238         LINK_DIRECTORIES(${VORBISFILE_LIBRARY_DIRS})
239         SET_SOURCE_FILES_PROPERTIES(src/codec_vorbisfile.cpp PROPERTIES
240                                     COMPILE_FLAGS "${VORBISFILE_CFLAGS}")
241     ELSE(VORBISFILE_FOUND)
242         FIND_PACKAGE(OggVorbis)
243         IF(OGGVORBIS_FOUND)
244             SET(HAS_VORBISFILE 1)
245             INCLUDE_DIRECTORIES(${OGGVORBIS_INCLUDE_DIRS})
246             SET(VORBISFILE_LIBRARIES ${OGGVORBIS_LIBRARIES})
247         ENDIF(OGGVORBIS_FOUND)
248     ENDIF(VORBISFILE_FOUND)
249     IF(NOT HAS_VORBISFILE)
250         PKG_CHECK_MODULES(VORBISIDEC vorbisidec)
251         IF(NOT VORBISIDEC_FOUND)
252             CHECK_INCLUDE_FILE(tremor/ivorbisfile.h HAVE_TREMOR_IVORBISFILE_H)
253             IF(HAVE_TREMOR_IVORBISFILE_H)
254                 CHECK_SHARED_FUNCTION_EXISTS(ov_open "tremor/ivorbisfile.h" vorbisidec "" HAVE_LIBVORBISIDEC)
255                 IF(DYNLOAD OR HAVE_LIBVORBISIDEC)
256                     SET(HAS_VORBISFILE 1)
257                     IF(HAVE_LIBVORBISIDEC)
258                         SET(VORBISFILE_LIBRARIES "vorbisidec")
259                     ENDIF(HAVE_LIBVORBISIDEC)
260                     SET_SOURCE_FILES_PROPERTIES(src/codec_vorbisfile.cpp PROPERTIES
261                                                 COMPILE_FLAGS "-DHAS_VORBISIDEC")
262                 ENDIF(DYNLOAD OR HAVE_LIBVORBISIDEC)
263             ENDIF(HAVE_TREMOR_IVORBISFILE_H)
264         ELSE(NOT VORBISIDEC_FOUND)
265             SET(HAS_VORBISFILE 1)
266             LINK_DIRECTORIES(${VORBISIDEC_LIBRARY_DIRS})
267             SET_SOURCE_FILES_PROPERTIES(src/codec_vorbisfile.cpp PROPERTIES
268                                         COMPILE_FLAGS "${VORBISIDEC_CFLAGS} -DHAS_VORBISIDEC")
269         ENDIF(NOT VORBISIDEC_FOUND)
270     ENDIF(NOT HAS_VORBISFILE)
271     IF(HAS_VORBISFILE)
272         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_vorbisfile.cpp)
273     ENDIF(HAS_VORBISFILE)
274 ELSE(VORBIS)
275     SET(VORBISFILE_LIBRARIES "")
276 ENDIF(VORBIS)
277
278 # FLAC support
279 IF(FLAC)
280     FIND_PACKAGE(FLAC)
281     IF(FLAC_FOUND)
282         INCLUDE_DIRECTORIES(${FLAC_INCLUDE_DIR})
283         SET(HAS_FLAC 1)
284     ENDIF(FLAC_FOUND)
285     IF(HAS_FLAC)
286         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_flac.cpp)
287     ENDIF(HAS_FLAC)
288 ELSE(FLAC)
289     SET(LIBFLAC_LIBRARIES "")
290 ENDIF(FLAC)
291
292 # MPG123 support
293 IF(MPG123)
294     PKG_CHECK_MODULES(MPG123 libmpg123)
295     IF(NOT MPG123_FOUND)
296         CHECK_INCLUDE_FILE(mpg123.h HAVE_MPG123_H)
297         IF(HAVE_MPG123_H)
298             CHECK_SHARED_FUNCTION_EXISTS(mpg123_init "mpg123.h" mpg123 "" HAVE_LIBMPG123)
299             IF(DYNLOAD OR HAVE_LIBMPG123)
300                 SET(HAS_MPG123 1)
301                 IF(HAVE_LIBMPG123)
302                     SET(MPG123_LIBRARIES "mpg123")
303                 ENDIF(HAVE_LIBMPG123)
304             ENDIF(DYNLOAD OR HAVE_LIBMPG123)
305         ENDIF(HAVE_MPG123_H)
306     ELSE(NOT MPG123_FOUND)
307         SET(HAS_MPG123 1)
308         LINK_DIRECTORIES(${MPG123_LIBRARY_DIRS})
309         SET_SOURCE_FILES_PROPERTIES(src/codec_mpg123.cpp PROPERTIES
310                                     COMPILE_FLAGS "${MPG123_CFLAGS}")
311     ENDIF(NOT MPG123_FOUND)
312     IF(HAS_MPG123)
313         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_mpg123.cpp)
314     ENDIF(HAS_MPG123)
315 ELSE(MPG123)
316     SET(MPG123_LIBRARIES "")
317 ENDIF(MPG123)
318
319 # DUMB support
320 IF(DUMB)
321     CHECK_INCLUDE_FILE(dumb.h HAVE_DUMB_H)
322     IF(HAVE_DUMB_H)
323         IF(HAS_LIBM)
324             CHECK_LIBRARY_EXISTS("dumb;m" dumbfile_open_ex "" HAVE_LIBDUMB)
325         ELSE(HAS_LIBM)
326             CHECK_LIBRARY_EXISTS(dumb dumbfile_open_ex "" HAVE_LIBDUMB)
327         ENDIF(HAS_LIBM)
328         IF(DYNLOAD OR HAVE_LIBDUMB)
329             SET(HAS_DUMB 1)
330             IF(HAVE_LIBDUMB)
331                 SET(DUMB_LIBRARIES dumb)
332             ENDIF(HAVE_LIBDUMB)
333         ENDIF(DYNLOAD OR HAVE_LIBDUMB)
334     ENDIF(HAVE_DUMB_H)
335     IF(HAS_DUMB)
336         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_dumb.cpp)
337     ENDIF(HAS_DUMB)
338 ELSE(DUMB)
339     SET(DUMB_LIBRARIES "")
340 ENDIF(DUMB)
341
342 # ModPlug support
343 IF(MODPLUG)
344     CHECK_INCLUDE_FILE(libmodplug/modplug.h HAVE_LIBMODPLUG_MODPLUG_H)
345     IF(HAVE_LIBMODPLUG_MODPLUG_H)
346         CHECK_SHARED_FUNCTION_EXISTS(ModPlug_Load "libmodplug/modplug.h" modplug "" HAVE_LIBMODPLUG)
347         IF(DYNLOAD OR HAVE_LIBMODPLUG)
348             SET(HAS_MODPLUG 1)
349             IF(HAVE_LIBMODPLUG)
350                 SET(MODPLUG_LIBRARIES "modplug")
351             ENDIF(HAVE_LIBMODPLUG)
352         ENDIF(DYNLOAD OR HAVE_LIBMODPLUG)
353     ENDIF(HAVE_LIBMODPLUG_MODPLUG_H)
354     IF(HAS_MODPLUG)
355         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_modplug.cpp)
356     ENDIF(HAS_MODPLUG)
357 ELSE(MODPLUG)
358     SET(MODPLUG_LIBRARIES "")
359 ENDIF(MODPLUG)
360
361 # FluidSynth support
362 IF(FLUIDSYNTH)
363     PKG_CHECK_MODULES(FLUIDSYNTH fluidsynth>=1.1.1)
364     IF(NOT FLUIDSYNTH_FOUND)
365         CHECK_INCLUDE_FILE(fluidsynth.h HAVE_FLUIDSYNTH_H)
366         IF(HAVE_FLUIDSYNTH_H)
367             CHECK_SHARED_FUNCTION_EXISTS(new_fluid_synth "fluidsynth.h" fluidsynth "" HAVE_LIBFLUIDSYNTH)
368             IF(DYNLOAD OR HAVE_LIBFLUIDSYNTH)
369                 SET(HAS_FLUIDSYNTH 1)
370                 IF(HAVE_LIBFLUIDSYNTH)
371                     SET(FLUIDSYNTH_LIBRARIES "fluidsynth")
372                 ENDIF(HAVE_LIBFLUIDSYNTH)
373             ENDIF(DYNLOAD OR HAVE_LIBFLUIDSYNTH)
374         ENDIF(HAVE_FLUIDSYNTH_H)
375     ELSE(NOT FLUIDSYNTH_FOUND)
376         SET(HAS_FLUIDSYNTH 1)
377         LINK_DIRECTORIES(${FLUIDSYNTH_LIBRARY_DIRS})
378         SET_SOURCE_FILES_PROPERTIES(src/codec_fluidsynth.cpp PROPERTIES
379                                     COMPILE_FLAGS "${FLUIDSYNTH_CFLAGS}")
380     ENDIF(NOT FLUIDSYNTH_FOUND)
381     IF(HAS_FLUIDSYNTH)
382         SET(ALURE_OBJS ${ALURE_OBJS} src/codec_fluidsynth.cpp)
383     ENDIF(HAS_FLUIDSYNTH)
384 ELSE(FLUIDSYNTH)
385     SET(FLUIDSYNTH_LIBRARIES "")
386 ENDIF(FLUIDSYNTH)
387
388
389 IF(NOT DYNLOAD)
390     SET(EXTRA_LIBS ${SNDFILE_LIBRARIES} ${VORBISFILE_LIBRARIES} ${LIBFLAC_LIBRARIES} ${MPG123_LIBRARIES} ${DUMB_LIBRARIES} ${MODPLUG_LIBRARIES} ${FLUIDSYNTH_LIBRARIES} ${EXTRA_LIBS})
391 ELSE(NOT DYNLOAD)
392     ADD_DEFINITIONS(-DDYNLOAD=1)
393 ENDIF(NOT DYNLOAD)
394
395 # For alure.pc.in
396 SET(prefix ${CMAKE_INSTALL_PREFIX})
397 SET(exec_prefix "\${prefix}")
398 SET(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
399 SET(bindir "\${exec_prefix}/bin")
400 SET(includedir "\${prefix}/include")
401 SET(PKG_CONFIG_REQUIRES openal)
402 SET(PACKAGE_VERSION "${LIB_VERSION}")
403
404 # End configuration
405 CONFIGURE_FILE(
406     "${ALURE_SOURCE_DIR}/config.h.in"
407     "${ALURE_BINARY_DIR}/config.h")
408 IF(BUILD_SHARED)
409     CONFIGURE_FILE(
410         "${ALURE_SOURCE_DIR}/alure.pc.in"
411         "${ALURE_BINARY_DIR}/alure.pc"
412         @ONLY)
413 ENDIF(BUILD_SHARED)
414 IF(BUILD_STATIC)
415     CONFIGURE_FILE(
416         "${ALURE_SOURCE_DIR}/alure-static.pc.in"
417         "${ALURE_BINARY_DIR}/alure-static.pc"
418         @ONLY)
419 ENDIF(BUILD_STATIC)
420
421 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
422
423
424 IF(BUILD_SHARED)
425     #build a shared library
426     ADD_LIBRARY(${LIBNAME} SHARED ${ALURE_OBJS})
427     SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES DEFINE_SYMBOL ALURE_BUILD_LIBRARY
428                                                 VERSION ${LIB_VERSION}.0
429                                                 SOVERSION ${LIB_MAJOR_VERSION})
430     IF(WIN32)
431         SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
432     ELSEIF(NOT APPLE)
433         SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES LINK_FLAGS "-Wl,--version-script=${ALURE_SOURCE_DIR}/libalure.map")
434     ENDIF(WIN32)
435     TARGET_LINK_LIBRARIES(${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
436
437     INSTALL(TARGETS ${LIBNAME}
438             RUNTIME DESTINATION bin
439             LIBRARY DESTINATION lib${LIB_SUFFIX}
440             ARCHIVE DESTINATION lib${LIB_SUFFIX}
441 )
442 ENDIF(BUILD_SHARED)
443 IF(BUILD_STATIC)
444     #build a static library
445     ADD_LIBRARY(${LIBNAME}-static STATIC ${ALURE_OBJS})
446     SET_TARGET_PROPERTIES(${LIBNAME}-static PROPERTIES DEFINE_SYMBOL ALURE_BUILD_LIBRARY
447                                                        COMPILE_FLAGS ${STATIC_CFLAGS}
448                                                        VERSION ${LIB_VERSION}.0)
449     INSTALL(TARGETS ${LIBNAME}-static
450             RUNTIME DESTINATION bin
451             LIBRARY DESTINATION lib${LIB_SUFFIX}
452             ARCHIVE DESTINATION lib${LIB_SUFFIX}
453 )
454 ENDIF(BUILD_STATIC)
455
456
457 OPTION(BUILD_EXAMPLES   "Build example programs"   ON)
458 OPTION(INSTALL_EXAMPLES "Install example programs" ON)
459
460 IF(BUILD_EXAMPLES)
461     IF(HAVE_DDK_NTDDCDRM_H)
462         SET_SOURCE_FILES_PROPERTIES(examples/alurecdplay.c PROPERTIES
463                                     COMPILE_FLAGS "-DHAVE_DDK_NTDDCDRM_H")
464     ENDIF(HAVE_DDK_NTDDCDRM_H)
465     ADD_EXECUTABLE(alureplay examples/alureplay.c)
466     ADD_EXECUTABLE(alurecdplay examples/alurecdplay.c)
467     ADD_EXECUTABLE(alurestream examples/alurestream.c)
468     IF(BUILD_SHARED)
469         TARGET_LINK_LIBRARIES(alureplay ${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
470         TARGET_LINK_LIBRARIES(alurecdplay ${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
471         TARGET_LINK_LIBRARIES(alurestream ${LIBNAME} ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
472     ELSE(BUILD_SHARED)
473         SET_TARGET_PROPERTIES(alureplay PROPERTIES COMPILE_FLAGS -DALURE_STATIC_LIBRARY)
474         SET_TARGET_PROPERTIES(alurecdplay PROPERTIES COMPILE_FLAGS -DALURE_STATIC_LIBRARY)
475         SET_TARGET_PROPERTIES(alurestream PROPERTIES COMPILE_FLAGS -DALURE_STATIC_LIBRARY)
476         TARGET_LINK_LIBRARIES(alureplay ${LIBNAME}-static ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
477         TARGET_LINK_LIBRARIES(alurecdplay ${LIBNAME}-static ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
478         TARGET_LINK_LIBRARIES(alurestream ${LIBNAME}-static ${OPENAL_LIBRARIES} ${EXTRA_LIBS})
479     ENDIF(BUILD_SHARED)
480 ENDIF(BUILD_EXAMPLES)
481
482
483 FIND_PROGRAM(NATDOCS_BIN NaturalDocs)
484 IF(NATDOCS_BIN)
485     ADD_CUSTOM_TARGET(docs
486                       "${NATDOCS_BIN}" -i "${ALURE_SOURCE_DIR}/src" -o HTML "${ALURE_SOURCE_DIR}/docs/html" -p "${ALURE_SOURCE_DIR}/docs/naturaldocs" -s Default CustomStyle
487                       COMMENT "Building NaturalDocs documentation..." VERBATIM)
488 ELSE(NATDOCS_BIN)
489     MESSAGE(STATUS "\nNaturalDocs not found; building documentation is disabled")
490 ENDIF(NATDOCS_BIN)
491
492
493 #add an install target here
494 IF(APPLE)
495     SET(INCPATH OpenAL)
496 ELSE(APPLE)
497     SET(INCPATH AL)
498 ENDIF(APPLE)
499
500 INSTALL(DIRECTORY "${ALURE_SOURCE_DIR}/docs/html"
501         DESTINATION share/doc/alure
502 )
503 INSTALL(FILES include/AL/alure.h
504         DESTINATION "include/${INCPATH}"
505 )
506 IF(BUILD_SHARED)
507     INSTALL(FILES "${ALURE_BINARY_DIR}/alure.pc"
508             DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
509     )
510 ENDIF(BUILD_SHARED)
511 IF(BUILD_STATIC)
512     INSTALL(FILES "${ALURE_BINARY_DIR}/alure-static.pc"
513             DESTINATION "lib${LIB_SUFFIX}/pkgconfig"
514     )
515 ENDIF(BUILD_STATIC)
516 IF(BUILD_EXAMPLES AND INSTALL_EXAMPLES)
517     INSTALL(TARGETS alureplay alurestream alurecdplay
518             RUNTIME DESTINATION bin)
519 ENDIF(BUILD_EXAMPLES AND INSTALL_EXAMPLES)
520
521
522 MESSAGE(STATUS "\n********************** Configured options **********************")
523 IF(BUILD_SHARED AND BUILD_STATIC)
524     MESSAGE(STATUS "Building shared, static library")
525 ELSEIF(BUILD_SHARED)
526     MESSAGE(STATUS "Building shared library")
527 ELSE(BUILD_SHARED AND BUILD_STATIC)
528     MESSAGE(STATUS "Building static library")
529 ENDIF(BUILD_SHARED AND BUILD_STATIC)
530 IF(BUILD_EXAMPLES AND INSTALL_EXAMPLES)
531     MESSAGE(STATUS "Building and installing examples")
532 ELSEIF(BUILD_EXAMPLES)
533     MESSAGE(STATUS "Building (not installing) examples")
534 ELSE(BUILD_EXAMPLES AND INSTALL_EXAMPLES)
535     MESSAGE(STATUS "Not building examples")
536 ENDIF(BUILD_EXAMPLES AND INSTALL_EXAMPLES)
537 MESSAGE(STATUS "")
538 IF(HAS_SNDFILE)
539     MESSAGE(STATUS "SndFile support: enabled")
540 ELSE(HAS_SNDFILE)
541     MESSAGE(STATUS "SndFile support: disabled")
542 ENDIF(HAS_SNDFILE)
543 IF(HAS_VORBISFILE)
544     MESSAGE(STATUS "VorbisFile support: enabled")
545 ELSE(HAS_VORBISFILE)
546     MESSAGE(STATUS "VorbisFile support: disabled")
547 ENDIF(HAS_VORBISFILE)
548 IF(HAS_FLAC)
549     MESSAGE(STATUS "FLAC support: enabled")
550 ELSE(HAS_FLAC)
551     MESSAGE(STATUS "FLAC support: disabled")
552 ENDIF(HAS_FLAC)
553 IF(HAS_MPG123)
554     MESSAGE(STATUS "MPG123 support: enabled")
555 ELSE(HAS_MPG123)
556     MESSAGE(STATUS "MPG123 support: disabled")
557 ENDIF(HAS_MPG123)
558 IF(HAS_DUMB)
559     MESSAGE(STATUS "DUMB support: enabled")
560 ELSE(HAS_DUMB)
561     MESSAGE(STATUS "DUMB support: disabled")
562 ENDIF(HAS_DUMB)
563 IF(HAS_MODPLUG)
564     MESSAGE(STATUS "ModPlug support: enabled")
565 ELSE(HAS_MODPLUG)
566     MESSAGE(STATUS "ModPlug support: disabled")
567 ENDIF(HAS_MODPLUG)
568 IF(HAS_FLUIDSYNTH)
569     MESSAGE(STATUS "FluidSynth support: enabled")
570 ELSE(HAS_FLUIDSYNTH)
571     MESSAGE(STATUS "FluidSynth support: disabled")
572 ENDIF(HAS_FLUIDSYNTH)
573 MESSAGE(STATUS "")