Debian Codegraph @

addons/acodec/CMakeLists.txt

raw
1 include_directories(../audio)
2
3 option(WANT_FLAC "Enable FLAC support" on)
4 if(WIN32)
5 option(FLAC_STATIC "Set this if linking with a static FLAC library" off)
6 endif()
7 option(WANT_VORBIS "Enable Ogg Vorbis support using libvorbis" on)
8 option(WANT_TREMOR "Enable Ogg Vorbis support using Tremor" off)
9 option(WANT_OPUS "Enable Opus support using libopus" on)
10 option(WANT_DUMB "Enable mod audio support using DUMB" on)
11 option(WANT_OPENMPT "Enable mod audio support using OpenMPT" on)
12 option(WANT_ACODEC_DYNAMIC_LOAD "Enable DLL loading in acodec (Windows)" off)
13 option(WANT_MP3 "Enable MP3 support" on)
14
15 #-----------------------------------------------------------------------------#
16
17 set(ACODEC_INCLUDE_FILES
18 allegro5/allegro_acodec.h
19 )
20
21 set_our_header_properties(${ACODEC_INCLUDE_FILES})
22
23 set(ACODEC_SOURCES
24 acodec.c
25 wav.c
26 helper.c
27 voc.c # built-in enhanced port of A4 loader
28 )
29 set(ACODEC_LIBRARIES)
30
31 # For dynamic loading, we want to make sure that CMake has found an import
32 # library and not a static library. We assume that the name of the DLL to load
33 # is the same as the import library, bar the extension.
34 #
35 # With MSVC, static libraries and import libraries share the same extension.
36 # Luckily the MSVC static libraries for FLAC and Vorbis are named with a
37 # _static suffix.
38 # With MinGW, static libraries end with .a, and import libraries end with
39 # .dll.a so we can tell them apart. (The regex for this is a bodge.)
40 set(WIN32_STATIC_LIB_REGEX "_static[.]|[^l][.]a")
41
42 function(get_dll_name implib dllname_var)
43 if(MINGW)
44 # Guess the name of dlltool from gcc.
45 string(REGEX REPLACE "gcc.*" dlltool DLLTOOL ${CMAKE_C_COMPILER})
46 execute_process(
47 COMMAND ${DLLTOOL} -I ${implib}
48 OUTPUT_VARIABLE dllname
49 OUTPUT_STRIP_TRAILING_WHITESPACE
50 )
51 elseif(MSVC)
52 # Not sure this is the best way.
53 execute_process(
54 COMMAND lib /LIST ${implib}
55 OUTPUT_VARIABLE output
56 )
57 if(output STREQUAL "")
58 message("WARNING: Failed to execute lib /list")
59 else()
60 string(REGEX MATCH "[^\n]+[.]dll" dllname "${output}")
61 endif()
62 endif()
63 if(NOT dllname)
64 # Guess from the basename.
65 get_filename_component(basename "${implib}" NAME_WE)
66 set(dllname "${basename}.dll")
67 endif()
68 message(STATUS "DLL name for ${implib}: ${dllname}")
69 set(${dllname_var} ${dllname} PARENT_SCOPE)
70 endfunction(get_dll_name)
71
72 set(ACODEC_CONFIGURATION_SUMMARY "")
73
74 function(acodec_summary msg yesno)
75 if(${yesno})
76 set(yesno "yes")
77 else()
78 # No's are more important, so shout them.
79 set(yesno "NO")
80 endif()
81 set(ACODEC_CONFIGURATION_SUMMARY "${ACODEC_CONFIGURATION_SUMMARY}${msg}: ${yesno}\n" PARENT_SCOPE)
82 endfunction()
83
84 #
85 # FLAC
86 #
87
88 if(WANT_FLAC)
89 find_package(FLAC)
90 if(FLAC_FOUND)
91 if(FLAC_LIBRARY MATCHES "${WIN32_STATIC_LIB_REGEX}")
92 set(FLAC_STATIC 1)
93 endif()
94 if(FLAC_STATIC)
95 set(FLAC__NO_DLL "-DFLAC__NO_DLL")
96 endif()
97 set(CMAKE_REQUIRED_INCLUDES ${FLAC_INCLUDE_DIR})
98 if(MSVC)
99 set(CMAKE_REQUIRED_LIBRARIES ${FLAC_LIBRARIES})
100 else()
101 # FLAC requires libm on Android, doesn't seem to hurt elsewhere either.
102 set(CMAKE_REQUIRED_LIBRARIES ${FLAC_LIBRARIES} m)
103 endif()
104 set(CMAKE_REQUIRED_DEFINITIONS ${FLAC__NO_DLL})
105 run_c_compile_test("
106 #include <FLAC/stream_decoder.h>
107 int main(void)
108 {
109 (void)FLAC__stream_decoder_new();
110 return 0;
111 }"
112 FLAC_COMPILES)
113 set(CMAKE_REQUIRED_INCLUDES)
114 set(CMAKE_REQUIRED_LIBRARIES)
115 set(CMAKE_REQUIRED_DEFINITIONS)
116 if(FLAC_COMPILES)
117 set(SUPPORT_FLAC 1)
118 endif(FLAC_COMPILES)
119 endif(FLAC_FOUND)
120 if(NOT SUPPORT_FLAC)
121 message("WARNING: libFLAC not found or compile test failed, disabling support.")
122 endif(NOT SUPPORT_FLAC)
123 endif(WANT_FLAC)
124
125 if(SUPPORT_FLAC)
126 include_directories(SYSTEM ${FLAC_INCLUDE_DIR})
127 set(ALLEGRO_CFG_ACODEC_FLAC 1)
128 list(APPEND ACODEC_SOURCES flac.c)
129
130 list(APPEND ACODEC_INCLUDE_DIRECTORIES ${FLAC_INCLUDE_DIR})
131
132 if(WIN32)
133 if(WANT_ACODEC_DYNAMIC_LOAD)
134 if(FLAC_STATIC)
135 message("WARNING: Dynamic loading will be disabled for FLAC as"
136 " static library was found: ${FLAC_LIBRARY}")
137 else()
138 get_dll_name(${FLAC_LIBRARY} ALLEGRO_CFG_ACODEC_FLAC_DLL)
139 endif()
140 endif()
141 endif(WIN32)
142
143 if(NOT ALLEGRO_CFG_ACODEC_FLAC_DLL)
144 list(APPEND ACODEC_LIBRARIES ${FLAC_LIBRARIES})
145 endif()
146 endif(SUPPORT_FLAC)
147
148 acodec_summary(" - FLAC" SUPPORT_FLAC)
149
150 #
151 # MOD audio
152 #
153
154 if(WANT_DUMB)
155 find_package(DUMB)
156 if(DUMB_FOUND)
157 set(CMAKE_REQUIRED_INCLUDES ${DUMB_INCLUDE_DIR})
158 set(CMAKE_REQUIRED_LIBRARIES ${DUMB_LIBRARIES})
159 run_c_compile_test("
160 #define _FILE_OFFSET_BITS 64
161 #include <dumb.h>
162 #if (DUMB_MAJOR_VERSION) == 1
163 #error libdumb 1.0 not supported, get >= 2.0 or 0.9.3
164 #endif
165 int main(void)
166 {
167 dumb_register_stdfiles();
168 return 0;
169 }"
170 DUMB_COMPILES)
171 set(CMAKE_REQUIRED_INCLUDES)
172 set(CMAKE_REQUIRED_LIBRARIES)
173 if(DUMB_COMPILES)
174 set(SUPPORT_DUMB 1)
175 endif(DUMB_COMPILES)
176 endif(DUMB_FOUND)
177 if(NOT SUPPORT_DUMB)
178 message("WARNING: libdumb >= 2.0 or <= 0.9.3 not found or compile "
179 "test failed, disabling support. See "
180 "<https://github.com/kode54/dumb> for 2.0 or "
181 "<http://dumb.sourceforge.net/> for 0.9.3.")
182 endif(NOT SUPPORT_DUMB)
183 endif(WANT_DUMB)
184
185 if(SUPPORT_DUMB)
186 include_directories(SYSTEM ${DUMB_INCLUDE_DIR})
187 set(ALLEGRO_CFG_ACODEC_DUMB 1)
188 list(APPEND ACODEC_SOURCES dumb.c)
189
190 list(APPEND ACODEC_INCLUDE_DIRECTORIES ${DUMB_INCLUDE_DIR})
191
192 if(WIN32 AND WANT_ACODEC_DYNAMIC_LOAD)
193 if(DUMB_LIBRARY MATCHES "${WIN32_STATIC_LIB_REGEX}")
194 message("WARNING: Dynamic loading will be disabled for DUMB"
195 " as static library was found: ${DUMB_LIBRARY}")
196 else()
197 get_dll_name(${DUMB_LIBRARY} ALLEGRO_CFG_ACODEC_DUMB_DLL)
198 endif()
199 endif()
200
201 if(NOT ALLEGRO_CFG_ACODEC_DUMB_DLL)
202 list(APPEND ACODEC_LIBRARIES ${DUMB_LIBRARIES})
203 endif()
204 endif()
205
206 acodec_summary(" - DUMB" SUPPORT_DUMB)
207
208 if(WANT_OPENMPT)
209 find_package(OpenMPT)
210
211 option(OPENMPT_ZLIB "Enable if OpenMPT static library needs zlib linked in." off)
212 option(OPENMPT_VORBIS "Enable if OpenMPT static library needs Ogg/Vorbis linked in." off)
213 if(OPENMPT_FOUND)
214 set(CMAKE_REQUIRED_INCLUDES ${OPENMPT_INCLUDE_DIR})
215 set(CMAKE_REQUIRED_LIBRARIES ${OPENMPT_LIBRARIES})
216
217 set(OPENMPT_TEST_SOURCE "
218 #include <libopenmpt/libopenmpt.h>
219 #include <libopenmpt/libopenmpt_stream_callbacks_file.h>
220 int main(void)
221 {
222 openmpt_module *mod = openmpt_module_create(
223 openmpt_stream_get_file_callbacks(), NULL, NULL, NULL, NULL);
224 openmpt_module_read_interleaved_stereo(mod, 44100, 1, NULL);
225 return 0;
226 }")
227
228 run_cxx_compile_test(
229 "${OPENMPT_TEST_SOURCE}"
230 OPENMPT_COMPILES)
231 set(CMAKE_REQUIRED_INCLUDES)
232 set(CMAKE_REQUIRED_LIBRARIES)
233 if(OPENMPT_COMPILES)
234 set(SUPPORT_OPENMPT 1)
235 set(ALL_OPENMPT_LIBRARIES ${OPENMPT_LIBRARIES})
236 else()
237 if(OPENMPT_ZLIB)
238 find_package(ZLIB)
239 endif()
240
241 if(OPENMPT_VORBIS)
242 find_package(Vorbis)
243 endif()
244
245 # Try compiling with the extra dependencies.
246 set(OPENMPT_STATIC_LIBRARIES ${OPENMPT_LIBRARIES})
247 if(OPENMPT_ZLIB AND ZLIB_FOUND)
248 list(APPEND OPENMPT_STATIC_LIBRARIES "${ZLIB_LIBRARIES}")
249 endif()
250
251 if(OPENMPT_VORBIS AND VORBIS_FOUND)
252 list(APPEND OPENMPT_STATIC_LIBRARIES "${VORBIS_LIBRARIES}")
253 endif()
254
255 set(CMAKE_REQUIRED_LIBRARIES ${OPENMPT_STATIC_LIBRARIES})
256 set(CMAKE_REQUIRED_INCLUDES ${OPENMPT_INCLUDE_DIR})
257 run_cxx_compile_test("${OPENMPT_TEST_SOURCE}" OPENMPT_COMPILES_WITH_EXTRA_DEPS)
258 set(CMAKE_REQUIRED_INCLUDES)
259 set(CMAKE_REQUIRED_LIBRARIES)
260 if(OPENMPT_COMPILES_WITH_EXTRA_DEPS)
261 set(SUPPORT_OPENMPT 1)
262 set(ALL_OPENMPT_LIBRARIES ${OPENMPT_STATIC_LIBRARIES})
263 endif()
264 endif()
265 endif()
266 endif()
267
268 if(SUPPORT_OPENMPT)
269 include_directories(SYSTEM ${OPENMPT_INCLUDE_DIR})
270 set(ALLEGRO_CFG_ACODEC_OPENMPT 1)
271 list(APPEND ACODEC_SOURCES openmpt.c)
272 list(APPEND ACODEC_INCLUDE_DIRECTORIES ${OPENMPT_INCLUDE_DIR})
273 list(APPEND ACODEC_LIBRARIES ${ALL_OPENMPT_LIBRARIES})
274 endif()
275
276 acodec_summary(" - OpenMPT" SUPPORT_OPENMPT)
277
278 if(SUPPORT_OPENMPT OR SUPPORT_DUMB)
279 list(APPEND ACODEC_SOURCES modaudio.c)
280 endif(SUPPORT_OPENMPT OR SUPPORT_DUMB)
281
282 #
283 # Vorbis/Tremor
284 #
285
286 if(WANT_TREMOR)
287 find_package(Tremor)
288 if(TREMOR_FOUND)
289 set(CMAKE_REQUIRED_INCLUDES ${TREMOR_INCLUDE_DIR})
290 set(CMAKE_REQUIRED_LIBRARIES ${TREMOR_LIBRARIES})
291 run_c_compile_test("
292 #include <tremor/ivorbisfile.h>
293 int main(void)
294 {
295 OggVorbis_File f;
296 ov_info(&f, -1);
297 return 0;
298 }"
299 TREMOR_COMPILES)
300 set(CMAKE_REQUIRED_INCLUDES)
301 set(CMAKE_REQUIRED_LIBRARIES)
302 if(TREMOR_COMPILES OR IPHONE OR ALLEGRO_RASPBERRYPI)
303 set(SUPPORT_VORBIS 1)
304 endif(TREMOR_COMPILES OR IPHONE OR ALLEGRO_RASPBERRYPI)
305 endif(TREMOR_FOUND)
306 if(NOT SUPPORT_VORBIS)
307 message("WARNING: Tremor not found although WANT_TREMOR was specified.")
308 else(NOT SUPPORT_VORBIS)
309 # mimic regular libogg/libvorbis
310 set(OGG_INCLUDE_DIR ${TREMOR_INCLUDE_DIR})
311 set(VORBIS_INCLUDE_DIR ${TREMOR_INCLUDE_DIR})
312 set(VORBIS_LIBRARIES ${TREMOR_LIBRARIES})
313 set(ALLEGRO_CFG_ACODEC_TREMOR 1)
314 endif(NOT SUPPORT_VORBIS)
315 elseif(WANT_VORBIS)
316 find_package(Vorbis)
317 if(VORBIS_FOUND)
318 set(CMAKE_REQUIRED_INCLUDES ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
319 if(MSVC)
320 set(CMAKE_REQUIRED_LIBRARIES "${VORBIS_LIBRARIES}")
321 else()
322 # libm is required when linking statically.
323 set(CMAKE_REQUIRED_LIBRARIES "${VORBIS_LIBRARIES};m")
324 endif()
325 run_c_compile_test("
326 #include <vorbis/vorbisfile.h>
327 int main(void)
328 {
329 OggVorbis_File f;
330 ov_callbacks callback;
331 vorbis_info *v = 0;
332 (void)v;
333 ov_info(&f, -1);
334 callback = OV_CALLBACKS_NOCLOSE;
335 return 0;
336 }"
337 VORBIS_COMPILES)
338 set(CMAKE_REQUIRED_INCLUDES)
339 set(CMAKE_REQUIRED_LIBRARIES)
340 if(VORBIS_COMPILES)
341 set(SUPPORT_VORBIS 1)
342 endif()
343 endif(VORBIS_FOUND)
344 if(NOT SUPPORT_VORBIS)
345 message("WARNING: libvorbis not found or compile test failed, disabling support.")
346 endif(NOT SUPPORT_VORBIS)
347 endif()
348
349 if(SUPPORT_VORBIS)
350 include_directories(SYSTEM ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
351 set(ALLEGRO_CFG_ACODEC_VORBIS 1)
352 list(APPEND ACODEC_SOURCES ogg.c)
353
354 list(APPEND ACODEC_INCLUDE_DIRECTORIES ${OGG_INCLUDE_DIR} ${VORBIS_INCLUDE_DIR})
355
356 if(WIN32 AND WANT_ACODEC_DYNAMIC_LOAD AND NOT WANT_TREMOR)
357 if(VORBISFILE_LIBRARY MATCHES "${WIN32_STATIC_LIB_REGEX}")
358 message("WARNING: Dynamic loading will be disabled for Vorbis"
359 " as static library was found: ${VORBISFILE_LIBRARY}")
360 else()
361 get_dll_name(${VORBISFILE_LIBRARY} ALLEGRO_CFG_ACODEC_VORBISFILE_DLL)
362 endif()
363 endif()
364
365 if(NOT ALLEGRO_CFG_ACODEC_VORBISFILE_DLL)
366 list(APPEND ACODEC_LIBRARIES ${VORBIS_LIBRARIES})
367 endif()
368 endif(SUPPORT_VORBIS)
369
370 acodec_summary(" - Ogg/Vorbis" SUPPORT_VORBIS)
371
372 #
373 # Opus
374 #
375
376 if(WANT_OPUS)
377 find_package(Opus)
378 if(OPUS_FOUND)
379 set(CMAKE_REQUIRED_INCLUDES ${OGG_INCLUDE_DIR} ${OPUS_INCLUDE_DIR})
380 if(MSVC)
381 set(CMAKE_REQUIRED_LIBRARIES "${OPUS_LIBRARIES}")
382 else()
383 # libm is required when linking statically.
384 set(CMAKE_REQUIRED_LIBRARIES "${OPUS_LIBRARIES};m")
385 endif()
386 run_c_compile_test("
387 #include <opus/opusfile.h>
388 int main(void)
389 {
390 OggOpusFile *f;
391 OpusHead *v = 0;
392 (void)v;
393 op_free(f);
394 return 0;
395 }"
396 OPUS_COMPILES)
397 set(CMAKE_REQUIRED_INCLUDES)
398 set(CMAKE_REQUIRED_LIBRARIES)
399 if(OPUS_COMPILES)
400 set(SUPPORT_OPUS 1)
401 endif()
402 endif(OPUS_FOUND)
403 if(NOT SUPPORT_OPUS)
404 message("WARNING: libopus not found or compile test failed, disabling support.")
405 endif(NOT SUPPORT_OPUS)
406 endif()
407
408 if(SUPPORT_OPUS)
409 include_directories(SYSTEM ${OGG_INCLUDE_DIR} ${OPUS_INCLUDE_DIR})
410 set(ALLEGRO_CFG_ACODEC_OPUS 1)
411 list(APPEND ACODEC_SOURCES opus.c)
412
413 list(APPEND ACODEC_INCLUDE_DIRECTORIES ${OGG_INCLUDE_DIR} ${OPUS_INCLUDE_DIR})
414
415 if(WIN32 AND WANT_ACODEC_DYNAMIC_LOAD)
416 if(OPUSFILE_LIBRARY MATCHES "${WIN32_STATIC_LIB_REGEX}")
417 message("WARNING: Dynamic loading will be disabled for Opus"
418 " as static library was found: ${OPUSFILE_LIBRARY}")
419 else()
420 get_dll_name(${OPUSFILE_LIBRARY} ALLEGRO_CFG_ACODEC_OPUSFILE_DLL)
421 endif()
422 endif()
423
424 if(NOT ALLEGRO_CFG_ACODEC_OPUSFILE_DLL)
425 list(APPEND ACODEC_LIBRARIES ${OPUS_LIBRARIES})
426 endif()
427 endif(SUPPORT_OPUS)
428
429 acodec_summary(" - Opus" SUPPORT_OPUS)
430
431 #
432 # MP3
433 #
434 if(WANT_MP3)
435 find_package(MiniMP3)
436 if(MINIMP3_FOUND)
437 include_directories(SYSTEM ${MINIMP3_INCLUDE_DIRS})
438 set(ALLEGRO_CFG_ACODEC_MP3 1)
439 list(APPEND ACODEC_SOURCES mp3.c)
440 endif(MINIMP3_FOUND)
441 if(NOT MINIMP3_FOUND)
442 message("WARNING: minimp3 was not found")
443 endif(NOT MINIMP3_FOUND)
444 endif()
445
446 acodec_summary(" - MP3" MINIMP3_FOUND)
447
448
449 configure_file(
450 allegro5/internal/aintern_acodec_cfg.h.cmake
451 ${PROJECT_BINARY_DIR}/include/allegro5/internal/aintern_acodec_cfg.h
452 )
453
454 add_our_addon_library(allegro_acodec
455 AllegroAcodec-${ALLEGRO_SOVERSION}
456 "${ACODEC_SOURCES};${ACODEC_INCLUDE_FILES}"
457 "-DALLEGRO_ACODEC_SRC ${FLAC__NO_DLL}"
458 "${AUDIO_LINK_WITH};${ACODEC_LIBRARIES}"
459 )
460
461 if(SUPPORT_OPENMPT AND SHARED AND NOT WANT_MONOLITH)
462 set_target_properties(allegro_acodec PROPERTIES LINKER_LANGUAGE CXX)
463 endif()
464
465 install_our_headers(${ACODEC_INCLUDE_FILES})
466
467 add_addon(acodec)
468
469 set(ACODEC_CONFIGURATION_SUMMARY "${ACODEC_CONFIGURATION_SUMMARY}" PARENT_SCOPE)
470
471
472 #-----------------------------------------------------------------------------#
473 # vim: set ts=8 sts=4 sw=4 et: