Skip to content

Commit

Permalink
Export flac properly when use with add_subdirectory (#285)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martinRenou authored May 30, 2022
1 parent 95064f9 commit 39e6e57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ if(WITH_OGG)
set_target_properties(test_bitwise test_framing PROPERTIES FOLDER Tests)
endif()
else()
find_package(Ogg REQUIRED)
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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion flac-config.cmake.in
Original file line number Diff line number Diff line change
@@ -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")

Expand Down

0 comments on commit 39e6e57

Please sign in to comment.