mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 01:49:53 +00:00
CMake improvements
* Fix Ogg and Opus imported targets * Better SndFileConfig.cmake module with dependency checks * Fix config-file package installation directory * Prefer config-file package mode for Windows CI builds * Update README.md * Allow CMAKE_MSVC_RUNTIME_LIBRARY option to set MSVC ABI * Fix some bugs in FindFLAC.cmake (closes #505)
This commit is contained in:
parent
a7e9fb5f7c
commit
e6909192ce
@ -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
|
||||
$<$<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_EXTERNAL_XIPH_LIBS}>: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}
|
||||
)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
21
README.md
21
README.md
@ -137,6 +137,9 @@ You can pass additional options with `/D<parameter>=<value>` 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:
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 .
|
||||
|
@ -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
|
||||
$<$<BOOL:${WIN32}>:wsock32>
|
||||
INTERFACE_COMPILE_DEFINITIONS ${FLAC_DEFINITIONS}
|
||||
INTERFACE_LINK_LIBRARIES Ogg::ogg
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
@ -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}"
|
||||
)
|
||||
|
@ -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}"
|
||||
)
|
||||
|
@ -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 ()
|
||||
|
@ -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)
|
||||
|
30
cmake/SndFileConfig.cmake.in
Normal file
30
cmake/SndFileConfig.cmake.in
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user