Skip to content

Commit

Permalink
Separate Catch2Config from targets
Browse files Browse the repository at this point in the history
This lets us add the installed helper scripts to the cmake module
path, letting CMake users just include them after requiring Catch2
package.
  • Loading branch information
horenmar committed Jun 24, 2018
1 parent 3743295 commit 1af60ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CMake/Catch2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@PACKAGE_INIT@


# Avoid repeatedly including the targets
if(NOT TARGET Catch2::Catch2)
# Provide path for scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake)
endif()
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,29 @@ add_library(Catch2::Catch2 ALIAS Catch2)

set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")

include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
INSTALL_DESTINATION
${CATCH_CMAKE_CONFIG_DESTINATION}
)


# create and install an export set for catch target as Catch2::Catch
install(
TARGETS
Catch2
EXPORT
Catch2Config
DESTINATION ${CMAKE_INSTALL_LIBDIR}
Catch2Targets
DESTINATION
${CMAKE_INSTALL_LIBDIR}
)


install(
EXPORT
Catch2Config
Catch2Targets
NAMESPACE
Catch2::
DESTINATION
Expand All @@ -117,6 +128,7 @@ install(

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
DESTINATION
${CATCH_CMAKE_CONFIG_DESTINATION}
Expand Down

0 comments on commit 1af60ef

Please sign in to comment.