forked from tuxzz/libsndfile
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
1633 lines (1403 loc) · 41.6 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
cmake_minimum_required (VERSION 3.5..3.26)
# MSVC runtime library flags are selected by an abstraction, CMake >= 3.15
# This policy still need to be set even with cmake_minimum_required() command above.
if (POLICY CMP0091)
if ((DEFINED ENABLE_STATIC_RUNTIME) AND (DEFINED CMAKE_MSVC_RUNTIME_LIBRARY))
message (FATAL_ERROR "Both ENABLE_STATIC_RUNTIME and CMAKE_MSVC_RUNTIME_LIBRARY are set.")
return ()
endif ()
if (CMAKE_VERSION VERSION_LESS 3.18)
if (DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
cmake_policy (SET CMP0091 NEW)
else ()
cmake_policy (SET CMP0091 OLD)
endif ()
endif ()
endif ()
option (ENABLE_EXTERNAL_LIBS "Enable FLAC, Vorbis, and Opus codecs" ON)
if (ENABLE_EXTERNAL_LIBS)
list (APPEND VCPKG_MANIFEST_FEATURES "external-libs")
endif ()
option (ENABLE_MPEG "Enable MPEG codecs" ON)
if (ENABLE_MPEG)
list (APPEND VCPKG_MANIFEST_FEATURES "mpeg")
endif ()
option (ENABLE_EXPERIMENTAL "Enable experimental code" OFF)
if (ENABLE_EXPERIMENTAL)
list (APPEND VCPKG_MANIFEST_FEATURES "speex")
endif ()
option (BUILD_REGTEST "Build regtest" OFF)
if (BUILD_REGTEST)
list (APPEND VCPKG_MANIFEST_FEATURES "regtest")
endif ()
project(libsndfile VERSION 1.2.2)
#
# Variables
#
set (CMAKE_C_STANDARD 99)
set (CMAKE_C_STANDARD_REQUIRED TRUE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set (PACKAGE_NAME ${PROJECT_NAME})
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set (CPACK_PACKAGE_VERSION_STAGE "")
set (CPACK_PACKAGE_VERSION_FULL "${PROJECT_VERSION}${CPACK_PACKAGE_VERSION_STAGE}")
#
# System-wide includes
#
include (GNUInstallDirs)
include (FeatureSummary)
include (CMakeDependentOption)
include (CTest)
include (CheckCCompilerFlag)
#
# Options
#
option (BUILD_SHARED_LIBS "Build shared libraries" OFF)
if (BUILD_SHARED_LIBS AND BUILD_TESTING)
set (BUILD_TESTING OFF)
message ("Build testing required static libraries. To prevent build errors BUILD_TESTING disabled.")
endif ()
option (BUILD_PROGRAMS "Build programs" ON)
option (BUILD_EXAMPLES "Build examples" ON)
option (ENABLE_CPACK "Enable CPack support" ON)
option (ENABLE_BOW_DOCS "Enable black-on-white html docs" OFF)
if (MSVC AND (DEFINED ENABLE_STATIC_RUNTIME))
option (ENABLE_STATIC_RUNTIME "Enable static runtime" ${ENABLE_STATIC_RUNTIME})
elseif (MINGW)
option (ENABLE_STATIC_RUNTIME "Enable static runtime" OFF)
endif ()
option (ENABLE_PACKAGE_CONFIG "Generate and install package config file" ON)
option (INSTALL_PKGCONFIG_MODULE "Generate and install pkg-config module" ON)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if (CMAKE_VERSION VERSION_LESS 3.14)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlite")
endif ()
#
# Setup definitions
#
include(SndFileChecks)
if (ENABLE_EXTERNAL_LIBS AND NOT (Vorbis_FOUND OR FLAC_FOUND OR OPUS_FOUND))
set (ENABLE_EXTERNAL_LIBS OFF)
endif()
if(ENABLE_MPEG AND (NOT HAVE_MPEG_LIBS))
set (ENABLE_MPEG OFF)
endif()
if (BUILD_REGTEST AND (NOT SQLITE3_FOUND))
set (BUILD_REGTEST OFF)
endif()
cmake_dependent_option (BUILD_REGTEST "Build regtest" ON "SQLITE3_FOUND" OFF)
cmake_dependent_option (ENABLE_EXTERNAL_LIBS "Enable FLAC, Vorbis, and Opus codecs" ON "Vorbis_FOUND;FLAC_FOUND;OPUS_FOUND" OFF)
cmake_dependent_option (ENABLE_WAVPACK "Enable Wavpack codec" ON "WAVPACK_FOUND" OFF)
cmake_dependent_option (ENABLE_CPU_CLIP "Enable tricky cpu specific clipper" ON "CPU_CLIPS_POSITIVE;CPU_CLIPS_NEGATIVE" OFF)
if (NOT ENABLE_CPU_CLIP)
set (CPU_CLIPS_POSITIVE FALSE)
set (CPU_CLIPS_NEGATIVE FALSE)
endif ()
cmake_dependent_option (ENABLE_COMPATIBLE_LIBSNDFILE_NAME "Set DLL name to libsndfile-1.dll (canonical name), sndfile.dll otherwise" OFF "WIN32;BUILD_SHARED_LIBS" OFF)
cmake_dependent_option (INSTALL_MANPAGES "Install man pages for programs" ON "BUILD_PROGRAMS" OFF)
if (NOT MSVC)
if (CPU_IS_X86)
check_c_compiler_flag (-msse2 HAVE_MSSE2_COMPILER_FLAG)
if (HAVE_MSSE2_COMPILER_FLAG)
cmake_dependent_option (ENABLE_SSE2 "Add SSE2 compiler flag" ON "HAVE_MSSE2_COMPILER_FLAG" OFF)
endif ()
endif ()
endif ()
if (ENABLE_SSE2)
add_compile_options (-msse2)
endif ()
set (HAVE_EXTERNAL_XIPH_LIBS ${ENABLE_EXTERNAL_LIBS})
set (HAVE_WAVPACK ${ENABLE_WAVPACK})
set (HAVE_SQLITE3 ${BUILD_REGTEST})
set (HAVE_ALSA_ASOUNDLIB_H ${ALSA_FOUND})
set (HAVE_SNDIO_H ${SNDIO_FOUND})
set (ENABLE_EXPERIMENTAL_CODE ${ENABLE_EXPERIMENTAL})
set (HAVE_MPEG ${ENABLE_MPEG})
set (HAVE_SPEEX ${ENABLE_EXPERIMENTAL})
add_feature_info (BUILD_SHARED_LIBS BUILD_SHARED_LIBS "build shared libraries")
add_feature_info (ENABLE_EXTERNAL_LIBS ENABLE_EXTERNAL_LIBS "enable FLAC, Vorbis, and Opus codecs")
add_feature_info (ENABLE_MPEG ENABLE_MPEG "enable MPEG audio (including mp3) codecs")
add_feature_info (ENABLE_WAVPACK ENABLE_WAVPACK "enable Wavpack codec")
add_feature_info (ENABLE_EXPERIMENTAL ENABLE_EXPERIMENTAL "enable experimental code")
add_feature_info (BUILD_TESTING BUILD_TESTING "build tests")
add_feature_info (BUILD_REGTEST BUILD_REGTEST "build regtest")
add_feature_info (ENABLE_CPACK ENABLE_CPACK "enable CPack support")
add_feature_info (ENABLE_BOW_DOCS ENABLE_BOW_DOCS "enable black-on-white html docs")
add_feature_info (ENABLE_PACKAGE_CONFIG ENABLE_PACKAGE_CONFIG "generate and install package config file")
add_feature_info (INSTALL_PKGCONFIG_MODULE INSTALL_PKGCONFIG_MODULE "generate and install pkg-config module")
add_feature_info (INSTALL_MANPAGES INSTALL_MANPAGES "install man pages for programs")
if (WIN32 AND BUILD_SHARED_LIBS)
add_feature_info (ENABLE_COMPATIBLE_LIBSNDFILE_NAME ENABLE_COMPATIBLE_LIBSNDFILE_NAME "Set DLL name to libsndfile-1.dll (canonical name), sndfile.dll otherwise")
endif ()
if (HAVE_MSSE2_COMPILER_FLAG)
add_feature_info (ENABLE_SSE2 ENABLE_SSE2 "add SSE2 compiler flag")
endif ()
set_package_properties (Ogg PROPERTIES
TYPE RECOMMENDED
URL "www.xiph.org/ogg/"
DESCRIPTION "library for manipulating ogg bitstreams"
PURPOSE "Required to enable Vorbis, Speex, and Opus support"
)
set_package_properties (Vorbis PROPERTIES
TYPE RECOMMENDED
URL "www.vorbis.com/"
DESCRIPTION "open source lossy audio codec"
PURPOSE "Enables Vorbis support"
)
set_package_properties (FLAC PROPERTIES
TYPE RECOMMENDED
URL "www.xiph.org/flac/"
DESCRIPTION "Free Lossless Audio Codec Library"
PURPOSE "Enables FLAC support"
)
set_package_properties (mp3lame PROPERTIES
TYPE RECOMMENDED
URL "https://lame.sourceforge.io/"
DESCRIPTION "High quality MPEG Audio Layer III (MP3) encoder"
PURPOSE "Enables MPEG layer III (MP3) writing support"
)
set_package_properties (mpg123 PROPERTIES
TYPE RECOMMENDED
URL "https://www.mpg123.de/"
DESCRIPTION "MPEG Audio Layer I/II/III decoder"
PURPOSE "Enables MPEG Audio reading support"
)
set_package_properties(Opus PROPERTIES
TYPE RECOMMENDED
URL "www.opus-codec.org/"
DESCRIPTION "Standardized open source low-latency fullband codec"
PURPOSE "Enables experimental Opus support"
)
set_package_properties (Wavpack PROPERTIES
TYPE RECOMMENDED
URL "www.wavpack.com/"
DESCRIPTION "Hybrid Lossless Audio Compression"
PURPOSE "Enables Wavpack support"
)
set_package_properties(Speex PROPERTIES TYPE OPTIONAL
URL "www.speex.org/"
DESCRIPTION "an audio codec tuned for speech"
PURPOSE "Enables experimental Speex support"
)
set_package_properties (SQLite3 PROPERTIES
TYPE OPTIONAL
URL "www.sqlite.org/"
DESCRIPTION "light weight SQL database engine."
PURPOSE "Enables regtest"
)
if (BUILD_SHARED_LIBS)
set_package_properties (PythonInterp PROPERTIES
TYPE REQUIRED
URL "www.python.org/"
DESCRIPTION "Python is a widely used high-level programming language."
PURPOSE "Required to build shared libraries"
)
endif()
feature_summary (WHAT ALL)
#
# Setup configuration
#
configure_file (src/config.h.cmake src/config.h)
if (INSTALL_PKGCONFIG_MODULE)
set (prefix ${CMAKE_INSTALL_PREFIX})
set (exec_prefix "\$\{prefix\}")
set (libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set (includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set (VERSION ${PROJECT_VERSION})
if (ENABLE_EXTERNAL_LIBS)
set (EXTERNAL_XIPH_REQUIRE "flac ogg vorbis vorbisenc opus")
if (ENABLE_EXPERIMENTAL)
set (EXTERNAL_XIPH_REQUIRE "${EXTERNAL_XIPH_REQUIRE} speex")
endif ()
endif ()
if (ENABLE_MPEG)
set (EXTERNAL_MPEG_REQUIRE "libmpg123")
set (EXTERNAL_MPEG_LIBS "-lmp3lame")
endif ()
if (ENABLE_WAVPACK)
set (EXTERNAL_WAVPACK_REQUIRE "wavpack")
endif ()
configure_file (sndfile.pc.in sndfile.pc @ONLY)
endif ()
#
# libsndfile
#
# Public libsndfile headers
set (sndfile_HDRS
include/sndfile.h
include/sndfile.hh
)
#
# libsndfile static library
#
add_library (sndfile
src/sfconfig.h
src/sfendian.h
src/sf_unistd.h
src/common.h
src/common.c
src/file_io.c
src/command.c
src/pcm.c
src/ulaw.c
src/alaw.c
src/float32.c
src/double64.c
src/ima_adpcm.c
src/ms_adpcm.c
src/gsm610.c
src/dwvw.c
src/vox_adpcm.c
src/interleave.c
src/strings.c
src/dither.c
src/cart.c
src/broadcast.c
src/audio_detect.c
src/ima_oki_adpcm.c
src/ima_oki_adpcm.h
src/alac.c
src/chunk.c
src/ogg.h
src/ogg.c
src/chanmap.h
src/chanmap.c
src/id3.h
src/id3.c
$<$<BOOL:${WIN32}>:src/windows.c>
src/sndfile.c
src/aiff.c
src/au.c
src/avr.c
src/caf.c
src/dwd.c
src/flac.c
src/g72x.c
src/htk.c
src/ircam.c
src/macos.c
src/mat4.c
src/mat5.c
src/nist.c
src/paf.c
src/pvf.c
src/raw.c
src/rx2.c
src/sd2.c
src/sds.c
src/svx.c
src/txw.c
src/voc.c
src/wve.c
src/w64.c
src/wavlike.h
src/wavlike.c
src/wav.c
src/wavpack.c
src/xi.c
src/mpc2k.c
src/rf64.c
src/ogg_vorbis.c
src/ogg_speex.c
src/ogg_pcm.c
src/ogg_opus.c
src/ogg_vcomment.h
src/ogg_vcomment.c
src/nms_adpcm.c
src/mpeg.c
src/mpeg_decode.c
src/mpeg_l3_encode.c
src/GSM610/config.h
src/GSM610/gsm.h
src/GSM610/gsm610_priv.h
src/GSM610/add.c
src/GSM610/code.c
src/GSM610/decode.c
src/GSM610/gsm_create.c
src/GSM610/gsm_decode.c
src/GSM610/gsm_destroy.c
src/GSM610/gsm_encode.c
src/GSM610/gsm_option.c
src/GSM610/long_term.c
src/GSM610/lpc.c
src/GSM610/preprocess.c
src/GSM610/rpe.c
src/GSM610/short_term.c
src/GSM610/table.c
src/G72x/g72x.h
src/G72x/g72x_priv.h
src/G72x/g721.c
src/G72x/g723_16.c
src/G72x/g723_24.c
src/G72x/g723_40.c
src/G72x/g72x.c
src/ALAC/ALACAudioTypes.h
src/ALAC/ALACBitUtilities.h
src/ALAC/EndianPortable.h
src/ALAC/aglib.h
src/ALAC/dplib.h
src/ALAC/matrixlib.h
src/ALAC/alac_codec.h
src/ALAC/shift.h
src/ALAC/ALACBitUtilities.c
src/ALAC/ag_dec.c
src/ALAC/ag_enc.c
src/ALAC/dp_dec.c
src/ALAC/dp_enc.c
src/ALAC/matrix_dec.c
src/ALAC/matrix_enc.c
src/ALAC/alac_decoder.c
src/ALAC/alac_encoder.c
${sndfile_HDRS}
${CMAKE_CURRENT_BINARY_DIR}/src/config.h
)
add_library (SndFile::sndfile ALIAS sndfile)
target_include_directories (sndfile
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
src
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
)
target_link_libraries (sndfile
PRIVATE
$<$<BOOL:${LIBM_REQUIRED}>:m>
$<$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>:Ogg::ogg>
$<$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>:Vorbis::vorbisenc>
$<$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>:FLAC::FLAC>
$<$<AND:$<BOOL:${ENABLE_EXPERIMENTAL}>,$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>,$<BOOL:${HAVE_SPEEX}>>:Speex::Speex>
$<$<BOOL:${HAVE_EXTERNAL_XIPH_LIBS}>:Opus::opus>
$<$<BOOL:${HAVE_MPEG}>:MPG123::libmpg123>
$<$<BOOL:${HAVE_MPEG}>:mp3lame::mp3lame>
$<$<BOOL:${HAVE_WAVPACK}>:Wavpack::wavpack>
)
set_target_properties (sndfile PROPERTIES
PUBLIC_HEADER "${sndfile_HDRS}"
)
if (ENABLE_COMPATIBLE_LIBSNDFILE_NAME)
if (MINGW OR CYGWIN)
set_target_properties (sndfile PROPERTIES
RUNTIME_OUTPUT_NAME "sndfile-1"
)
else ()
set_target_properties (sndfile PROPERTIES
RUNTIME_OUTPUT_NAME "libsndfile-1"
)
endif ()
endif ()
if (BUILD_SHARED_LIBS)
#
# ABI version of library.
#
#
# Read libtool version from `configure.ac` and set libsndfile ABI version:
#
# SNDFILE_ABI_VERSION_MAJOR
# SNDFILE_ABI_VERSION_MINOR
# SNDFILE_ABI_VERSION_PATCH
# SNDFILE_ABI_VERSION
#
# and Mach-O current and compatibility versions:
#
# SNDFILE_MACHO_CURRENT_VERSION
# SNDFILE_MACHO_COMPATIBILITY_VERSION
#
include (SetupABIVersions)
setup_abi_versions()
if (WIN32)
set (VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
set (GEN_TOOL cmake)
set (WIN_RC_VERSION "${CPACK_PACKAGE_VERSION_MAJOR},${CPACK_PACKAGE_VERSION_MINOR},${CPACK_PACKAGE_VERSION_PATCH}")
set (CLEAN_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set (PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
configure_file (src/version-metadata.rc.in src/version-metadata.rc @ONLY)
target_sources (sndfile PRIVATE ${PROJECT_BINARY_DIR}/src/version-metadata.rc)
endif ()
set_target_properties (sndfile PROPERTIES
SOVERSION ${SNDFILE_ABI_VERSION_MAJOR}
VERSION ${SNDFILE_ABI_VERSION}
)
if (APPLE)
if (NOT (CMAKE_VERSION VERSION_LESS 3.17))
set_target_properties (sndfile PROPERTIES
MACHO_CURRENT_VERSION ${SNDFILE_MACHO_CURRENT_VERSION}
MACHO_COMPATIBILITY_VERSION ${SNDFILE_MACHO_COMPATIBILITY_VERSION}
)
else ()
message (FATAL_ERROR "Apple platform requires cmake >= 3.17 to build dylib.")
endif ()
endif ()
# Symbol files generation
if (WIN32)
set (SYMBOL_FILENAME "sndfile.def")
set (SYMBOL_OS "win32")
elseif ((CMAKE_SYSTEM_NAME MATCHES "Darwin") OR (CMAKE_SYSTEM_NAME MATCHES "Rhapsody"))
set (SYMBOL_FILENAME "Symbols.darwin")
set (SYMBOL_OS "darwin")
elseif (CMAKE_SYSTEM_NAME MATCHES "OS2")
set (SYMBOL_FILENAME "Symbols.os2")
set (SYMBOL_OS "os2")
elseif (UNIX)
set (SYMBOL_FILENAME "Symbols.gnu-binutils")
set (SYMBOL_OS "linux")
endif ()
if (DEFINED SYMBOL_OS)
add_custom_command (
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/src/create_symbols_file.py ${SYMBOL_OS} ${SNDFILE_ABI_VERSION} > ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}
COMMENT "Generating ${SYMBOL_FILENAME}..."
)
add_custom_target (GENFILES DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME})
if (SYMBOL_OS MATCHES "win32")
target_sources (sndfile
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}
)
elseif (SYMBOL_OS MATCHES "darwin")
add_dependencies (sndfile GENFILES)
if (CMAKE_VERSION VERSION_LESS 3.13)
set_property (TARGET sndfile APPEND_STRING PROPERTY
LINK_FLAGS "-Wl,-exported_symbols_list -Wl,${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}"
)
else ()
target_link_options (sndfile PRIVATE "LINKER:-exported_symbols_list,${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}")
endif()
elseif (SYMBOL_OS MATCHES "os")
add_dependencies (sndfile GENFILES)
if (CMAKE_VERSION VERSION_LESS 3.13)
set_property (TARGET sndfile APPEND_STRING PROPERTY
LINK_FLAGS "-Wl,-export-symbols ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}"
)
else ()
target_link_options (sndfile PRIVATE "LINKER:-export-symbols ${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}")
endif()
elseif (UNIX)
add_dependencies (sndfile GENFILES)
if (CMAKE_VERSION VERSION_LESS 3.13)
set_property (TARGET sndfile APPEND_STRING PROPERTY
LINK_FLAGS "-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}"
)
else ()
target_link_options (sndfile PRIVATE "LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/src/${SYMBOL_FILENAME}")
endif()
endif()
endif()
endif ()
#
# Programs
#
if (BUILD_PROGRAMS)
# sndfile-info
add_executable (sndfile-info
programs/sndfile-info.c
programs/common.c
programs/common.h
)
target_link_libraries (sndfile-info
PRIVATE
sndfile
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
# sndfile-play
add_executable (sndfile-play
$<$<NOT:$<BOOL:${BEOS}>>:programs/sndfile-play.c>
$<$<NOT:$<BOOL:${BEOS}>>:programs/common.c>
$<$<NOT:$<BOOL:${BEOS}>>:programs/sndfile-play.c>
$<$<BOOL:${BEOS}>:programs/sndfile-play-beos.cpp>
)
target_include_directories (sndfile-play
PRIVATE
src
${CMAKE_CURRENT_BINARY_DIR}/src
)
target_link_libraries (sndfile-play PRIVATE $<$<BOOL:${LIBM_REQUIRED}>:m>)
target_link_libraries (sndfile-play PRIVATE sndfile)
if (WIN32)
target_link_libraries(sndfile-play PRIVATE winmm)
# Maybe ALSA & Sndio are present in BeOS. They are not required
# so skip them anyway.
elseif ((NOT BEOS) AND ALSA_FOUND)
target_include_directories (sndfile-play PRIVATE ${ALSA_INCLUDE_DIRS})
target_link_libraries (sndfile-play PRIVATE ${ALSA_LIBRARIES})
elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_link_libraries (sndfile-play PRIVATE Sndio::Sndio)
endif ()
# sndfile-convert
add_executable (sndfile-convert
programs/sndfile-convert.c
programs/common.c
programs/common.h
)
target_link_libraries (sndfile-convert PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-cmp
add_executable (sndfile-cmp
programs/sndfile-cmp.c
programs/common.c
programs/common.h
)
target_include_directories (sndfile-cmp
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries (sndfile-cmp PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-metadata-set
add_executable (sndfile-metadata-set
programs/sndfile-metadata-set.c
programs/common.c
programs/common.h
)
target_include_directories (sndfile-metadata-set
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries (sndfile-metadata-set PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-metadata-get
add_executable (sndfile-metadata-get
programs/sndfile-metadata-get.c
programs/common.c
programs/common.h
)
target_include_directories (sndfile-metadata-get
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries (sndfile-metadata-get PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-interleave
add_executable (sndfile-interleave
programs/sndfile-interleave.c
programs/common.c
programs/common.h
)
target_link_libraries (sndfile-interleave PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-deinterleave
add_executable (sndfile-deinterleave
programs/sndfile-deinterleave.c
programs/common.c
programs/common.h
)
target_link_libraries (sndfile-deinterleave PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-concat
add_executable (sndfile-concat
programs/sndfile-concat.c
programs/common.c
programs/common.h
)
target_link_libraries (sndfile-concat PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
# sndfile-salvage
add_executable (sndfile-salvage
programs/sndfile-salvage.c
programs/common.c
programs/common.h
)
target_include_directories (sndfile-salvage
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries (sndfile-salvage PRIVATE sndfile $<$<BOOL:${LIBM_REQUIRED}>:m>)
set (SNDFILE_PROGRAM_TARGETS
sndfile-info
sndfile-play
sndfile-convert
sndfile-cmp
sndfile-metadata-set
sndfile-metadata-get
sndfile-interleave
sndfile-deinterleave
sndfile-concat
sndfile-salvage
)
set_target_properties(${SNDFILE_PROGRAM_TARGETS} PROPERTIES FOLDER Programs)
endif ()
#
# Examples
#
if (BUILD_EXAMPLES)
# sndfile-to-text
add_executable (sndfile-to-text examples/sndfile-to-text.c)
target_link_libraries (sndfile-to-text PRIVATE sndfile)
# sndfile-loopify
add_executable (sndfile-loopify examples/sndfile-loopify.c)
target_link_libraries (sndfile-loopify PRIVATE sndfile)
# make_sine
add_executable (make_sine examples/make_sine.c)
target_link_libraries (make_sine
PRIVATE
sndfile
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
# sfprocess
add_executable (sfprocess examples/sfprocess.c)
target_link_libraries (sfprocess
PRIVATE
sndfile
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
# list_formats
add_executable (list_formats examples/list_formats.c)
target_link_libraries (list_formats
PRIVATE
sndfile
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
# generate
add_executable (generate examples/generate.c)
target_link_libraries (generate PRIVATE sndfile)
# sndfilehandle
add_executable (sndfilehandle examples/sndfilehandle.cc)
target_link_libraries (sndfilehandle PUBLIC sndfile)
set (SNDFILE_EXAMPLE_TARGETS
sndfile-to-text
sndfile-loopify
make_sine
sfprocess
list_formats
generate
sndfilehandle
)
set_target_properties(${SNDFILE_EXAMPLE_TARGETS} PROPERTIES FOLDER Examples)
endif ()
#
# sndfile-regtest
#
if (BUILD_REGTEST)
add_executable (sndfile-regtest
regtest/sndfile-regtest.c
regtest/database.c
regtest/checksum.c
)
target_include_directories (sndfile-regtest
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries(sndfile-regtest
PRIVATE
sndfile
SQLite::SQLite3
$<$<BOOL:${LIBM_REQUIRED}>:m>
)
endif ()
#
# Installation
#
if (ENABLE_PACKAGE_CONFIG)
if (WIN32 AND (NOT MINGW) AND (NOT CYGWIN))
set (CMAKE_INSTALL_PACKAGEDIR cmake)
else ()
set (CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/SndFile)
endif()
install (TARGETS ${SNDFILE_PROGRAM_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install (TARGETS sndfile
EXPORT SndFileTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
export (EXPORT SndFileTargets NAMESPACE SndFile:: FILE ${PROJECT_BINARY_DIR}/SndFileTargets.cmake)
include (CMakePackageConfigHelpers)
if (ENABLE_EXTERNAL_LIBS)
set (SndFile_WITH_EXTERNAL_LIBS 1)
list (APPEND FIND_MODULES_INSTALL_LIST
${CMAKE_CURRENT_LIST_DIR}/cmake/FindFLAC.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindOgg.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindOpus.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindVorbis.cmake)
else ()
set (SndFile_WITH_EXTERNAL_LIBS 0)
endif ()
if(ENABLE_MPEG)
set (SndFile_WITH_MPEG 1)
list (APPEND FIND_MODULES_INSTALL_LIST
${CMAKE_CURRENT_LIST_DIR}/cmake/Findmpg123.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/Findmp3lame.cmake)
else ()
set (SndFile_WITH_MPEG 0)
endif ()
set (INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
configure_package_config_file(cmake/SndFileConfig.cmake.in SndFileConfig.cmake
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
INSTALL_PREFIX ${PROJECT_BINARY_DIR}
PATH_VARS INCLUDE_INSTALL_DIR
)
configure_package_config_file(cmake/SndFileConfig.cmake.in SndFileConfig2.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
PATH_VARS INCLUDE_INSTALL_DIR
)
write_basic_package_version_file (SndFileConfigVersion.cmake COMPATIBILITY SameMajorVersion)
install(EXPORT SndFileTargets
NAMESPACE SndFile::
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/SndFileConfig2.cmake
RENAME SndFileConfig.cmake
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/SndFileConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PACKAGEDIR}
)
if (NOT BUILD_SHARED_LIBS AND FIND_MODULES_INSTALL_LIST)
file(COPY ${FIND_MODULES_INSTALL_LIST} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
install(FILES ${FIND_MODULES_INSTALL_LIST} DESTINATION ${CMAKE_INSTALL_PACKAGEDIR})
endif ()
else ()
install (TARGETS sndfile ${sdnfile_PROGRAMS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif ()
if (INSTALL_MANPAGES)
set (man_MANS
man/sndfile-info.1
man/sndfile-play.1
man/sndfile-convert.1
man/sndfile-cmp.1
man/sndfile-metadata-get.1
man/sndfile-concat.1
man/sndfile-interleave.1
man/sndfile-salvage.1
)
install (FILES ${man_MANS} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install (FILES man/sndfile-metadata-get.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 RENAME sndfile-metadata-set.1)
install (FILES man/sndfile-interleave.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 RENAME sndfile-deinterleave.1)
endif ()
if (ENABLE_BOW_DOCS)
set (HTML_BGCOLOUR "white")
set (HTML_FGCOLOUR "black")
else ()
set (HTML_BGCOLOUR "black")
set (HTML_FGCOLOUR "white")
endif ()
set (dist_doc_DATA
docs/index.md
docs/libsndfile.jpg
docs/libsndfile.css
docs/print.css
docs/api.md
docs/command.md
docs/bugs.md
docs/formats.md
docs/sndfile_info.md
docs/new_file_type_howto.md
docs/win32.md
docs/FAQ.md
docs/lists.md
docs/embedded_files.md
docs/octave.md
docs/tutorial.md
)
install (FILES ${dist_doc_DATA} DESTINATION ${CMAKE_INSTALL_DOCDIR})
if (INSTALL_PKGCONFIG_MODULE)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/sndfile.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif ()
#
# Testing
#
if (BUILD_TESTING)
enable_testing ()
include (CMakeAutoGen)
# generate tests sources from autogen templates
lsf_autogen (tests benchmark c)
lsf_autogen (tests floating_point_test c)
lsf_autogen (tests header_test c)
lsf_autogen (tests pcm_test c)
lsf_autogen (tests pipe_test c)
lsf_autogen (tests rdwr_test c)
lsf_autogen (tests scale_clip_test c)
lsf_autogen (tests utils c h)
lsf_autogen (tests write_read_test c)
lsf_autogen (src test_endswap c)
# utils static library
add_library(test_utils STATIC tests/utils.c)
target_include_directories (test_utils
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries(test_utils PRIVATE sndfile)
### test_main
add_executable (test_main
src/test_main.c
src/test_main.h
src/test_conversions.c
src/test_float.c
src/test_endswap.c
src/test_audio_detect.c
src/test_log_printf.c
src/test_file_io.c
src/test_ima_oki_adpcm.c
src/test_strncpy_crlf.c
src/test_broadcast_var.c
src/test_cart_var.c
src/test_binheader_writef.c
src/test_nms_adpcm.c
)
target_include_directories (test_main
PUBLIC
src
${CMAKE_CURRENT_BINARY_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/tests
)
target_link_libraries (test_main PRIVATE sndfile)
if (MSVC)
target_compile_definitions (test_main PRIVATE _USE_MATH_DEFINES)
endif ()
add_test (test_main test_main)