diff --git a/CMakeLists.txt b/CMakeLists.txt index a3d87585..b75d6cb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required (VERSION 3.1.3) +if (POLICY CMP0091) + cmake_policy(SET CMP0091 NEW) +endif () + project(sndfile VERSION 1.0.29) # @@ -304,7 +308,7 @@ target_link_libraries (sndfile $<$:Vorbis::VorbisEnc> $<$:FLAC::FLAC> $<$,$,$>:Speex::Speex> - $<$:Opus::Opus> + $<$:Opus::opus> ) set_target_properties (sndfile PROPERTIES PUBLIC_HEADER "${sndfile_HDRS}" @@ -600,15 +604,15 @@ endif () if (ENABLE_PACKAGE_CONFIG) - if (UNIX) - set (CMAKE_INSTALL_PACKAGEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/SndFile) - elseif(WIN32) - set (CMAKE_INSTALL_PACKAGEDIR cmake) + 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 ${SNDFILE_PROGRAM_TARGETS} - EXPORT SndFileConfig + EXPORT SndFileTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -617,14 +621,27 @@ if (ENABLE_PACKAGE_CONFIG) include (CMakePackageConfigHelpers) + if (ENABLE_EXTERNAL_LIBS) + set (SndFile_WITH_EXTERNAL_LIBS 1) + else () + set (SndFile_WITH_EXTERNAL_LIBS 0) + endif () + + set (INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) + configure_package_config_file(cmake/SndFileConfig.cmake.in SndFileConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_PACKAGEDIR} + PATH_VARS INCLUDE_INSTALL_DIR + ) write_basic_package_version_file (SndFileConfigVersion.cmake COMPATIBILITY SameMajorVersion) - install(EXPORT SndFileConfig + install(EXPORT SndFileTargets NAMESPACE SndFile:: DESTINATION ${CMAKE_INSTALL_PACKAGEDIR} ) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/SndFileConfigVersion.cmake + FILES + ${CMAKE_CURRENT_BINARY_DIR}/SndFileConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/SndFileConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_PACKAGEDIR} ) diff --git a/Makefile.am b/Makefile.am index dff2ad32..a2aff6cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,7 @@ cmake_files = cmake/ClipMode.cmake cmake/FindFLAC.cmake \ cmake/FindSpeex.cmake cmake/FindSQLite3.cmake cmake/FindVorbisEnc.cmake \ cmake/SndFileChecks.cmake cmake/TestInline.cmake \ cmake/TestLargeFiles.cmake cmake/TestInline.c.in \ - cmake/FindOpus.cmake + cmake/FindOpus.cmake cmake/SndFileConfig.cmake.in pkgconfig_DATA = sndfile.pc diff --git a/README.md b/README.md index f4284c97..c7522561 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,9 @@ You can pass additional options with `/D=` when you run This option is `ON` by default. * `ENABLE_STATIC_RUNTIME` - enable static runtime on Windows platform, `OFF` by default. + + **Note**: For MSVC compiler this option is depecated. Use `CMAKE_MSVC_RUNTIME_LIBRARY` + option instead (CMake >= 3.15). * `ENABLE_COMPATIBLE_LIBSNDFILE_NAME` - set DLL name to `libsndfile-1.dll` (canonical name) on Windows platform, `sndfile.dll` otherwise, `OFF` by default. Library name can be different depending on platform. The well known @@ -159,8 +162,16 @@ Deprecated options: ### Linking from CMake projects -When `libsndfile` built and installed with `ENABLE_PACKAGE_CONFIG` option set - to `ON`, you can find library from your `CMakeLists.txt` with this command: +First you need to add `FindOgg.cmake`, `FindVorbis.cmake`, `FindVorbisEnc.cmake`, + `FindFLAC.cmake` and `FindOpus.cmake` files to some directory inside your CMake + project (usually `cmake`) and add it to `CMAKE_MODULE_PATH`: + + project(SomeApplication) + + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +Now you can search `libsndfile` library from your `CMakeLists.txt` + with this command: find_package(SndFile) @@ -191,14 +202,14 @@ To link `libsndfile` library use: First advice - set `ENABLE_STATIC_RUNTIME` to ON. This will remove dependencies on runtime DLLs. -Second advice is about Ogg, Vorbis and FLAC support. Searching external +Second advice is about Ogg, Vorbis FLAC and Opus support. Searching external libraries under Windows is a little bit tricky. The best way is to use [Vcpkg](https://github.com/Microsoft/vcpkg). You need to install static libogg, libvorbis, libflac and libopus libraries: vcpkg install libogg:x64-windows-static libvorbis:x64-windows-static - libflac:x64-windows-static libogg:x86-windows-static - libvorbis:x86-windows-static libflac:x86-windows-static + libflac:x64-windows-static opus:x64-windows-static libogg:x86-windows-static + libvorbis:x86-windows-static libflac:x86-windows-static opus:x86-windows-static Then and add this parameter to cmake command line: diff --git a/appveyor.yml b/appveyor.yml index fcb992ac..8784fc00 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ before_build: - cd CMakeBuild - if %platform%==Win32 set CMAKE_GENERATOR=Visual Studio 15 2017 - if %platform%==x64 set CMAKE_GENERATOR=Visual Studio 15 2017 Win64 - - cmake .. -G"%CMAKE_GENERATOR%" -DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake + - cmake .. -G"%CMAKE_GENERATOR%" -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DCMAKE_TOOLCHAIN_FILE=C:/Tools/vcpkg/scripts/buildsystems/vcpkg.cmake build: project: c:\projects\libsndfile\CMakeBuild\sndfile.sln verbosity: minimal diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 30ad88ac..14a67510 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -55,7 +55,7 @@ jobs: - task: CMake@1 inputs: workingDirectory: 'build' - cmakeArgs: ' -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' + cmakeArgs: ' -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' - script: | cd build cmake --build . @@ -81,7 +81,7 @@ jobs: - task: CMake@1 inputs: workingDirectory: 'build' - cmakeArgs: ' -G "Visual Studio 14 2015" -A x64 -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' + cmakeArgs: ' -G "Visual Studio 14 2015" -A x64 -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' - script: | cd build cmake --build . @@ -107,7 +107,7 @@ jobs: - task: CMake@1 inputs: workingDirectory: 'build' - cmakeArgs: ' -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' + cmakeArgs: ' -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' - script: | cd build cmake --build . @@ -133,7 +133,7 @@ jobs: - task: CMake@1 inputs: workingDirectory: 'build' - cmakeArgs: ' -G "Visual Studio 15 2017" -A x64 -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' + cmakeArgs: ' -G "Visual Studio 15 2017" -A x64 -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON -DCMAKE_TOOLCHAIN_FILE=../vcpkg/scripts/buildsystems/vcpkg.cmake ..' - script: | cd build cmake --build . diff --git a/cmake/FindFLAC.cmake b/cmake/FindFLAC.cmake index 601e5665..7396481d 100644 --- a/cmake/FindFLAC.cmake +++ b/cmake/FindFLAC.cmake @@ -54,22 +54,12 @@ find_package_handle_standard_args (FLAC if (FLAC_FOUND) set (FLAC_INCLUDE_DIRS ${FLAC_INCLUDE_DIR}) set (FLAC_LIBRARIES ${FLAC_LIBRARY} ${OGG_LIBRARIES}) - if (WIN32) - set (FLAC_LIBRARIES ${FLAC_LIBRARIES} wsock32) - get_filename_component (FLAC_LIBRARY_FILENAME ${FLAC_LIBRARY} NAME_WE) - if (FLAC_LIBRARY_FILENAME MATCHES "libFLAC_static") - set (FLAC_DEFINITIONS -DFLAC__NO_DLL) - endif () - endif () if (NOT TARGET FLAC::FLAC) add_library(FLAC::FLAC UNKNOWN IMPORTED) set_target_properties(FLAC::FLAC PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${FLAC_INCLUDE_DIR}" IMPORTED_LOCATION "${FLAC_LIBRARY}" - INTERFACE_LINK_LIBRARIES - Ogg::Ogg - $<$:wsock32> - INTERFACE_COMPILE_DEFINITIONS ${FLAC_DEFINITIONS} + INTERFACE_LINK_LIBRARIES Ogg::ogg ) endif () endif () diff --git a/cmake/FindOgg.cmake b/cmake/FindOgg.cmake index 988f936d..9cf5ce43 100644 --- a/cmake/FindOgg.cmake +++ b/cmake/FindOgg.cmake @@ -49,9 +49,9 @@ if (OGG_FOUND) set (OGG_LIBRARIES ${OGG_LIBRARY}) set (OGG_INCLUDE_DIRS ${OGG_INCLUDE_DIR}) - if(NOT TARGET Ogg::Ogg) - add_library(Ogg::Ogg UNKNOWN IMPORTED) - set_target_properties(Ogg::Ogg PROPERTIES + if(NOT TARGET Ogg::ogg) + add_library(Ogg::ogg UNKNOWN IMPORTED) + set_target_properties(Ogg::ogg PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OGG_INCLUDE_DIRS}" IMPORTED_LOCATION "${OGG_LIBRARIES}" ) diff --git a/cmake/FindOpus.cmake b/cmake/FindOpus.cmake index 2b29d52d..a83686bd 100644 --- a/cmake/FindOpus.cmake +++ b/cmake/FindOpus.cmake @@ -55,9 +55,9 @@ if (OPUS_FOUND) set (OPUS_LIBRARIES ${OPUS_LIBRARY}) set (OPUS_INCLUDE_DIRS ${OPUS_INCLUDE_DIR}) - if (NOT TARGET Opus::Opus) - add_library (Opus::Opus UNKNOWN IMPORTED) - set_target_properties (Opus::Opus PROPERTIES + if (NOT TARGET Opus::opus) + add_library (Opus::opus UNKNOWN IMPORTED) + set_target_properties (Opus::opus PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${OPUS_INCLUDE_DIRS}" IMPORTED_LOCATION "${OPUS_LIBRARIES}" ) diff --git a/cmake/FindVorbis.cmake b/cmake/FindVorbis.cmake index d76c76d8..55bd862a 100644 --- a/cmake/FindVorbis.cmake +++ b/cmake/FindVorbis.cmake @@ -56,7 +56,7 @@ if (VORBIS_FOUND) set_target_properties (Vorbis::Vorbis PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${VORBIS_INCLUDE_DIR}" IMPORTED_LOCATION "${VORBIS_LIBRARY}" - INTERFACE_LINK_LIBRARIES Ogg::Ogg + INTERFACE_LINK_LIBRARIES Ogg::ogg ) endif () endif () diff --git a/cmake/SndFileChecks.cmake b/cmake/SndFileChecks.cmake index 89fc7d8f..37234b80 100644 --- a/cmake/SndFileChecks.cmake +++ b/cmake/SndFileChecks.cmake @@ -27,6 +27,7 @@ if (NOT WIN32) find_package (Sndio) endif () +find_package(Ogg 1.3) find_package (VorbisEnc) find_package (FLAC) find_package (Opus) diff --git a/cmake/SndFileConfig.cmake.in b/cmake/SndFileConfig.cmake.in new file mode 100644 index 00000000..97642880 --- /dev/null +++ b/cmake/SndFileConfig.cmake.in @@ -0,0 +1,30 @@ +set(SndFile_VERSION @PROJECT_VERSION@) +set(SndFile_VERSION_MAJOR @PROJECT_VERSION_MAJOR@) +set(SndFile_VERSION_MINOR @PROJECT_VERSION_MINOR@) +set(SndFile_VERSION_PATCH @PROJECT_VERSION_PATCH@) + +set (SndFile_WITH_EXTERNAL_LIBS @SndFile_WITH_EXTERNAL_LIBS@) + +@PACKAGE_INIT@ + +include (CMakeFindDependencyMacro) + +find_dependency (Ogg 1.3) +find_dependency (VorbisEnc) +find_dependency (FLAC) +find_dependency (Opus) + +include (${CMAKE_CURRENT_LIST_DIR}/SndFileTargets.cmake) + +set_and_check (SndFile_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@") +set (SNDFILE_INCLUDE_DIR ${SndFile_INCLUDE_DIR}) + +set (SndFile_LIBRARY SndFile::sndfile) +set (SNDFILE_LIBRARY SndFile::sndfile) +set (SndFile_LIBRARIES SndFile::sndfile) +set (SNDFILE_LIBRARIES SndFile::sndfile) + + +check_required_components(SndFile) + +set (SNDFILE_FOUND 1)