Merge branch 'upstream' into tizen
[platform/upstream/libsndfile.git] / CMakeLists.txt
1 # CMakeLists.txt for libsndfile
2
3 cmake_minimum_required (VERSION 3.0.0)
4
5 project (libsndfile)
6
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)
12 find_program (WC wc)
13
14 include (CMake/file.cmake)
15
16 # Duplicate the autoconf/autoheader functionality.
17
18 # Get the version number from configure.ac.
19 execute_process (
20         COMMAND ${GREP} ^AC_INIT configure.ac
21         COMMAND ${SED} "s/.*libsndfile[^0-9]*//;s/\\].*//"
22         OUTPUT_VARIABLE LIB_VERSION
23         )
24
25 string (STRIP ${LIB_VERSION} LIB_VERSION)
26 string (REGEX REPLACE "\\..*" "" LIB_VERSION_MAJOR ${LIB_VERSION})
27
28 message (STATUS "libsndfile version : ${LIB_VERSION}")
29
30 # Generate config.h.in if it does not already exist.
31 if (NOT (EXISTS "${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in"))
32         if (NOT AUTOHEADER)
33                 message (FATAL_ERROR "Need autoheader (part of GNU autoconf) to proceed.")
34                 endif ()
35
36         message (STATUS "Running autoheader to create src/config.h.in")
37         execute_process (COMMAND ${AUTOHEADER} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
38
39         assert_line_count_non_zero ("${CMAKE_SOURCE_DIR}/src/config.h.in")
40
41         message (STATUS "Post processing src/config.h.in")
42         execute_process (
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}
47                 )
48
49         execute_process (
50                 COMMAND ${GREP} -c undef ${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in
51                 OUTPUT_VARIABLE undef_count
52                 )
53
54         if (${undef_count} GREATER 0)
55                 message (FATAL_ERROR "CMake processing of CMakeFIles/config.h.in has failed.")
56                 endif ()
57         endif ()
58
59 assert_line_count_non_zero ("${CMAKE_SOURCE_DIR}/CMakeFiles/config.h.in")
60
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)
73
74 if (DEFINED ENV{CC})
75         set (CMAKE_C_COMPILER $ENV{CC})
76         endif()
77
78 if (DEFINED ENV{CXX})
79         set (CMAKE_CXX_COMPILER $ENV{CXX})
80         endif()
81
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}")
86
87 #-------------------------------------------------------------------------------
88
89 set (PACKAGE \"libsndfile\")
90 set (PACKAGE_NAME \"libsndfile\")
91 set (VERSION \"${LIB_VERSION}\")
92 set (PACKAGE_VERSION \"${LIB_VERSION}\")
93
94 set (BASEPATH "${CMAKE_SOURCE_DIR}")
95
96 include (CMake/build.cmake)
97 include (CMake/external_libs.cmake)
98 include (CMake/libsndfile.cmake)
99
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)
103
104         set (COMPILER_IS_GCC 1)
105         set (_POSIX_SOURCE 1)
106
107         if (${Werror} MATCHES "on")
108                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror" CACHE STRING "" FORCE)
109                 endif ()
110         endif ()
111
112 if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
113         # Untested. Probably does not work. Patches accepted.
114
115         set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4996" CACHE STRING "" FORCE)
116         add_definitions ("/wd4244 /wd4996")
117         endif ()
118
119
120 # Need to actually detect this.
121 set (CPU_CLIPS_POSITIVE 0)
122 set (CPU_CLIPS_NEGATIVE 0)
123
124 set (ENABLE_EXPERIMENTAL_CODE 0)
125
126 find_external_xiph_libs (HAVE_EXTERNAL_XIPH_LIBS EXTERNAL_XIPH_CFLAGS EXTERNAL_XIPH_LIBS)
127
128 #-------------------------------------------------------------------------------
129 # Project definitions follow.
130
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)
133
134 include_directories (src)
135
136 set (libsndfile_sources
137         src/ALAC/ALACBitUtilities.c
138         src/ALAC/ag_dec.c
139         src/ALAC/ag_enc.c
140         src/ALAC/alac_decoder.c
141         src/ALAC/alac_encoder.c
142         src/ALAC/dp_dec.c
143         src/ALAC/dp_enc.c
144         src/ALAC/matrix_dec.c
145         src/ALAC/matrix_enc.c
146
147         src/G72x/g721.c
148         src/G72x/g723_16.c
149         src/G72x/g723_24.c
150         src/G72x/g723_40.c
151         src/G72x/g72x.c
152         src/G72x/g72x_test.c
153
154         src/GSM610/add.c
155         src/GSM610/code.c
156         src/GSM610/decode.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
163         src/GSM610/lpc.c
164         src/GSM610/preprocess.c
165         src/GSM610/rpe.c
166         src/GSM610/short_term.c
167         src/GSM610/table.c
168
169         src/aiff.c
170         src/alac.c
171         src/alaw.c
172         src/au.c
173         src/audio_detect.c
174         src/avr.c
175         src/broadcast.c
176         src/caf.c
177         src/cart.c
178         src/chanmap.c
179         src/chunk.c
180         src/command.c
181         src/common.c
182         src/dither.c
183         src/double64.c
184         src/dwd.c
185         src/dwvw.c
186         src/file_io.c
187         src/flac.c
188         src/float32.c
189         src/g72x.c
190         src/gsm610.c
191         src/htk.c
192         src/id3.c
193         src/ima_adpcm.c
194         src/ima_oki_adpcm.c
195         src/interleave.c
196         src/ircam.c
197         src/macos.c
198         src/mat4.c
199         src/mat5.c
200         src/mpc2k.c
201         src/ms_adpcm.c
202         src/nist.c
203         src/ogg.c
204         src/ogg_opus.c
205         src/ogg_pcm.c
206         src/ogg_speex.c
207         src/ogg_vorbis.c
208         src/paf.c
209         src/pcm.c
210         src/pvf.c
211         src/raw.c
212         src/rf64.c
213         src/rx2.c
214         src/sd2.c
215         src/sds.c
216         src/sndfile.c
217         src/strings.c
218         src/svx.c
219         src/txw.c
220         src/ulaw.c
221         src/voc.c
222         src/vox_adpcm.c
223         src/w64.c
224         src/wav.c
225         src/wavlike.c
226         src/windows.c
227         src/wve.c
228         src/xi.c
229         )
230
231 add_library (sndfile SHARED
232         ${libsndfile_sources}
233         )
234
235 target_link_libraries (sndfile LINK_PRIVATE ${EXTERNAL_XIPH_LIBS} LINK_PUBLIC m)
236
237 set_target_properties (sndfile
238         PROPERTIES
239         VERSION ${LIB_VERSION}
240         SOVERSION ${LIB_VERSION_MAJOR}
241         LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/src
242         )
243
244 #-------------------------------------------------------------------------------
245 # Programs.
246
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)
257
258 #-------------------------------------------------------------------------------
259 # Tests.
260
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)
263
264 add_custom_target (check
265         COMMAND src/test_main && bash tests/test_wrapper.sh
266         DEPENDS src/test_main tests/test_wrapper.sh
267         )
268
269 # Tests from the src/ directory.
270 set (src_test_sources
271         src/audio_detect.c
272         src/broadcast.c
273         src/cart.c
274         src/common.c
275         src/double64.c
276         src/file_io.c
277         src/float32.c
278         src/test_audio_detect.c
279         src/test_broadcast_var.c
280         src/test_cart_var.c
281         src/test_conversions.c
282         src/test_endswap.c
283         src/test_file_io.c
284         src/test_float.c
285         src/test_ima_oki_adpcm.c
286         src/test_log_printf.c
287         src/test_strncpy_crlf.c
288         )
289
290 lsf_build_src_test_c (test_main "${src_test_sources}")
291
292 # Tests from the tests/ directory.
293
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")