Export flac properly when use with add_subdirectory (#285)

This allows for flac to be used in a larger CMake project
with add_subdirectory. It also allows for Ogg to be
build elsewhere in the larger project.
This commit is contained in:
martinRenou 2022-05-30 20:22:45 +02:00 committed by GitHub
parent 95064f9f08
commit 39e6e570d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -42,7 +42,11 @@ if(WITH_OGG)
set_target_properties(test_bitwise test_framing PROPERTIES FOLDER Tests)
endif()
else()
if(NOT TARGET Ogg::ogg)
find_package(Ogg REQUIRED)
else()
set(OGG_FOUND 1 CACHE INTERNAL "ogg has already been built")
endif()
set(OGG_PACKAGE "ogg")
endif()
endif()
@ -228,12 +232,18 @@ if(INSTALL_CMAKE_CONFIG_MODULE)
EXPORT targets
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
NAMESPACE FLAC::)
export(EXPORT targets NAMESPACE FLAC:: FILE FLACTargets.cmake)
configure_package_config_file(
flac-config.cmake.in flac-config.cmake
${PROJECT_SOURCE_DIR}/flac-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake")
write_basic_package_version_file(
flac-config-version.cmake COMPATIBILITY AnyNewerVersion)
${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake COMPATIBILITY AnyNewerVersion)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/flac-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/flac-config-version.cmake
DESTINATION "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake"
)
install(
FILES

View File

@ -1,7 +1,9 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(Ogg)
if(NOT TARGET Ogg::ogg)
find_dependency(Ogg)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/targets.cmake")