1 # CMakeLists.txt for libsndfile
3 cmake_minimum_required (VERSION 3.0.0)
7 # We may need these programs so detect them now.
8 find_program (AUTOGEN autogen)
9 find_program (AUTOHEADER autoheader)
10 find_program (GREP grep)
11 find_program (SED sed)
14 include (CMake/file.cmake)
16 # Duplicate the autoconf/autoheader functionality.
18 # Get the version number from configure.ac.
20 COMMAND ${GREP} ^AC_INIT configure.ac
21 COMMAND ${SED} "s/.*libsndfile[^0-9]*//;s/\\].*//"
22 OUTPUT_VARIABLE LIB_VERSION
25 string (STRIP ${LIB_VERSION} LIB_VERSION)
26 string (REGEX REPLACE "\\..*" "" LIB_VERSION_MAJOR ${LIB_VERSION})
28 message (STATUS "libsndfile version : ${LIB_VERSION}")
30 # Generate config.h.in if it does not already exist.
31 if (NOT (EXISTS "${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in"))
33 message (FATAL_ERROR "Need autoheader (part of GNU autoconf) to proceed.")
36 message (STATUS "Running autoheader to create src/config.h.in")
37 execute_process (COMMAND ${AUTOHEADER} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
39 assert_line_count_non_zero ("${CMAKE_SOURCE_DIR}/src/config.h.in")
41 message (STATUS "Post processing src/config.h.in")
43 COMMAND ${SED} -E "s/undef([ \\t]+)([a-zA-Z0-8_]+)/define\\1\\2\\1@\\2@/" src/config.h.in
44 COMMAND ${SED} "s/.*_FILE_OFFSET_BITS.*//"
45 OUTPUT_FILE ${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in
46 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
50 COMMAND ${GREP} -c undef ${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in
51 OUTPUT_VARIABLE undef_count
54 if (${undef_count} GREATER 0)
55 message (FATAL_ERROR "CMake processing of CMakeFIles/config.h.in has failed.")
59 assert_line_count_non_zero ("${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in")
61 # Use autogen to generate files if they don't already exist.
62 include (CMake/autogen.cmake)
63 lsf_autogen (src test_endswap)
64 lsf_autogen (tests pcm_test)
65 lsf_autogen (tests utils)
66 lsf_autogen (tests floating_point_test)
67 lsf_autogen (tests header_test)
68 lsf_autogen (tests pipe_test)
69 lsf_autogen (tests write_read_test)
70 lsf_autogen (tests scale_clip_test)
71 lsf_autogen (tests rdwr_test)
72 lsf_autogen (tests benchmark)
75 set (CMAKE_C_COMPILER $ENV{CC})
79 set (CMAKE_CXX_COMPILER $ENV{CXX})
82 message (STATUS "System : ${CMAKE_SYSTEM_NAME}")
83 message (STATUS "Processor : ${CMAKE_SYSTEM_PROCESSOR}")
84 message (STATUS "C compiler : ${CMAKE_C_COMPILER_ID}")
85 message (STATUS "C++ compiler : ${CMAKE_CXX_COMPILER_ID}")
87 #-------------------------------------------------------------------------------
89 set (PACKAGE \"libsndfile\")
90 set (PACKAGE_NAME \"libsndfile\")
91 set (VERSION \"${LIB_VERSION}\")
92 set (PACKAGE_VERSION \"${LIB_VERSION}\")
94 set (BASEPATH "${CMAKE_SOURCE_DIR}")
96 include (CMake/build.cmake)
97 include (CMake/external_libs.cmake)
98 include (CMake/libsndfile.cmake)
100 if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
101 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -std=gnu99 -Wall -Wextra" CACHE STRING "" FORCE)
102 set (CMAKE_CXX__FLAGS "${CMAKE_C_FLAGS} -O3 -std=gnu99 -Wall -Wextra" CACHE STRING "" FORCE)
104 set (COMPILER_IS_GCC 1)
105 set (_POSIX_SOURCE 1)
107 if (${Werror} MATCHES "on")
108 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror" CACHE STRING "" FORCE)
112 if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
113 # Untested. Probably does not work. Patches accepted.
115 set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4996" CACHE STRING "" FORCE)
116 add_definitions ("/wd4244 /wd4996")
120 # Need to actually detect this.
121 set (CPU_CLIPS_POSITIVE 0)
122 set (CPU_CLIPS_NEGATIVE 0)
124 set (ENABLE_EXPERIMENTAL_CODE 0)
126 find_external_xiph_libs (HAVE_EXTERNAL_XIPH_LIBS EXTERNAL_XIPH_CFLAGS EXTERNAL_XIPH_LIBS)
128 #-------------------------------------------------------------------------------
129 # Project definitions follow.
131 configure_file (${CMAKE_SOURCE_DIR}/src/sndfile.h.in ${CMAKE_SOURCE_DIR}/src/sndfile.h)
132 configure_file (${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in ${CMAKE_SOURCE_DIR}/src/config.h)
134 include_directories (src)
136 set (libsndfile_sources
137 src/ALAC/ALACBitUtilities.c
140 src/ALAC/alac_decoder.c
141 src/ALAC/alac_encoder.c
144 src/ALAC/matrix_dec.c
145 src/ALAC/matrix_enc.c
157 src/GSM610/gsm_create.c
158 src/GSM610/gsm_decode.c
159 src/GSM610/gsm_destroy.c
160 src/GSM610/gsm_encode.c
161 src/GSM610/gsm_option.c
162 src/GSM610/long_term.c
164 src/GSM610/preprocess.c
166 src/GSM610/short_term.c
231 add_library (sndfile SHARED
232 ${libsndfile_sources}
235 target_link_libraries (sndfile LINK_PRIVATE ${EXTERNAL_XIPH_LIBS} LINK_PUBLIC m)
237 set_target_properties (sndfile
239 VERSION ${LIB_VERSION}
240 SOVERSION ${LIB_VERSION_MAJOR}
241 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src
244 #-------------------------------------------------------------------------------
247 lsf_build_program (sndfile-cmp)
248 lsf_build_program (sndfile-concat)
249 lsf_build_program (sndfile-convert)
250 lsf_build_program (sndfile-deinterleave)
251 lsf_build_program (sndfile-info)
252 lsf_build_program (sndfile-interleave)
253 lsf_build_program (sndfile-metadata-get)
254 lsf_build_program (sndfile-metadata-set)
255 lsf_build_program (sndfile-salvage)
256 lsf_build_program_extra (sndfile-play asound)
258 #-------------------------------------------------------------------------------
261 configure_file (${CMAKE_SOURCE_DIR}/tests/test_wrapper.sh.in ${CMAKE_SOURCE_DIR}/tests/test_wrapper.sh)
262 configure_file (${CMAKE_SOURCE_DIR}/tests/pedantic-header-test.sh.in ${CMAKE_SOURCE_DIR}/tests/pedantic-header-test.sh)
264 add_custom_target (check
265 COMMAND src/test_main && bash tests/test_wrapper.sh
266 DEPENDS src/test_main tests/test_wrapper.sh
269 # Tests from the src/ directory.
270 set (src_test_sources
278 src/test_audio_detect.c
279 src/test_broadcast_var.c
281 src/test_conversions.c
285 src/test_ima_oki_adpcm.c
286 src/test_log_printf.c
287 src/test_strncpy_crlf.c
290 lsf_build_src_test_c (test_main "${src_test_sources}")
292 # Tests from the tests/ directory.
294 lsf_build_test_c (aiff_rw_test "")
295 lsf_build_test_c (alaw_test "")
296 lsf_build_test_c (benchmark "")
297 lsf_build_test_c (channel_test "")
298 lsf_build_test_c (checksum_test "")
299 lsf_build_test_c (chunk_test "")
300 lsf_build_test_c (command_test "")
301 lsf_build_test_c (compression_size_test "")
302 lsf_build_test_cc (cpp_test "")
303 lsf_build_test_c (dither_test "")
304 lsf_build_test_c (dwvw_test "")
305 lsf_build_test_c (error_test "")
306 lsf_build_test_c (external_libs_test "")
307 lsf_build_test_c (fix_this "")
308 lsf_build_test_c (floating_point_test "tests/dft_cmp.c")
309 lsf_build_test_c (format_check_test "")
310 lsf_build_test_c (headerless_test "")
311 lsf_build_test_c (header_test "")
312 lsf_build_test_c (largefile_test "")
313 lsf_build_test_c (locale_test "")
314 lsf_build_test_c (lossy_comp_test "")
315 lsf_build_test_c (long_read_write_test "")
316 lsf_build_test_c (misc_test "")
317 lsf_build_test_c (multi_file_test "")
318 lsf_build_test_c (ogg_test "")
319 lsf_build_test_c (pcm_test "")
320 lsf_build_test_c (peak_chunk_test "")
321 lsf_build_test_c (pipe_test "")
322 lsf_build_test_c (raw_test "")
323 lsf_build_test_c (rdwr_test "")
324 lsf_build_test_c (scale_clip_test "")
325 lsf_build_test_c (sfversion "")
326 lsf_build_test_c (stdin_test "")
327 lsf_build_test_c (stdio_test "")
328 lsf_build_test_c (stdout_test "")
329 lsf_build_test_c (string_test "")
330 lsf_build_test_c (ulaw_test "")
331 lsf_build_test_c (virtual_io_test "")
332 lsf_build_test_c (win32_ordinal_test "")
333 lsf_build_test_c (win32_test "")
334 lsf_build_test_c (write_read_test "tests/generate.c")