Disable installation step when Catch is used as a subproject

This is because otherwise the installations paths provided via
GNUInstallDirs become messed up and parts of the installation
package will end up in the wrong place.

Also it doesn't make much sense to force dependees to also install
our header alongside them.

Closes #1373
This commit is contained in:
Martin Hořeňovský 2018-08-31 11:40:55 +02:00
parent 90663b2e75
commit 0646e0283c
1 changed files with 93 additions and 88 deletions

View File

@ -91,102 +91,107 @@ target_include_directories(Catch2
# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project # provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
add_library(Catch2::Catch2 ALIAS Catch2) add_library(Catch2::Catch2 ALIAS Catch2)
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") # Only perform the installation steps when Catch is not being used as
# a subproject via `add_subdirectory`, or the destinations will break,
# see https://github.com/catchorg/Catch2/issues/1373
if (NOT_SUBPROJECT)
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
include(CMakePackageConfigHelpers) configure_package_config_file(
configure_package_config_file( ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake INSTALL_DESTINATION
INSTALL_DESTINATION ${CATCH_CMAKE_CONFIG_DESTINATION}
${CATCH_CMAKE_CONFIG_DESTINATION} )
)
# create and install an export set for catch target as Catch2::Catch # create and install an export set for catch target as Catch2::Catch
install( install(
TARGETS TARGETS
Catch2 Catch2
EXPORT EXPORT
Catch2Targets Catch2Targets
DESTINATION DESTINATION
${CMAKE_INSTALL_LIBDIR} ${CMAKE_INSTALL_LIBDIR}
) )
install( install(
EXPORT EXPORT
Catch2Targets Catch2Targets
NAMESPACE NAMESPACE
Catch2:: Catch2::
DESTINATION DESTINATION
${CATCH_CMAKE_CONFIG_DESTINATION} ${CATCH_CMAKE_CONFIG_DESTINATION}
) )
write_basic_package_version_file( write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
COMPATIBILITY COMPATIBILITY
SameMajorVersion SameMajorVersion
) )
install( install(
DIRECTORY DIRECTORY
"single_include/" "single_include/"
DESTINATION DESTINATION
"${CMAKE_INSTALL_INCLUDEDIR}" "${CMAKE_INSTALL_INCLUDEDIR}"
) )
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
DESTINATION
${CATCH_CMAKE_CONFIG_DESTINATION}
)
# Install documentation install(
if(CATCH_INSTALL_DOCS) FILES
install( "${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
docs/ DESTINATION
DESTINATION ${CATCH_CMAKE_CONFIG_DESTINATION}
"${CMAKE_INSTALL_DOCDIR}" )
)
endif()
if(CATCH_INSTALL_HELPERS) # Install documentation
# Install CMake scripts if(CATCH_INSTALL_DOCS)
install( install(
FILES DIRECTORY
"contrib/ParseAndAddCatchTests.cmake" docs/
"contrib/Catch.cmake" DESTINATION
"contrib/CatchAddTests.cmake" "${CMAKE_INSTALL_DOCDIR}"
DESTINATION )
${CATCH_CMAKE_CONFIG_DESTINATION} endif()
)
# Install debugger helpers if(CATCH_INSTALL_HELPERS)
install( # Install CMake scripts
FILES install(
"contrib/gdbinit" FILES
"contrib/lldbinit" "contrib/ParseAndAddCatchTests.cmake"
DESTINATION "contrib/Catch.cmake"
${CMAKE_INSTALL_DATAROOTDIR}/Catch2 "contrib/CatchAddTests.cmake"
) DESTINATION
endif() ${CATCH_CMAKE_CONFIG_DESTINATION}
)
## Provide some pkg-config integration # Install debugger helpers
set(PKGCONFIG_INSTALL_DIR install(
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" FILES
CACHE PATH "Path where catch2.pc is installed" "contrib/gdbinit"
) "contrib/lldbinit"
configure_file( DESTINATION
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in ${CMAKE_INSTALL_DATAROOTDIR}/Catch2
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc )
@ONLY endif()
)
install( ## Provide some pkg-config integration
FILES set(PKGCONFIG_INSTALL_DIR
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc" "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
DESTINATION CACHE PATH "Path where catch2.pc is installed"
${PKGCONFIG_INSTALL_DIR} )
) configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
@ONLY
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
DESTINATION
${PKGCONFIG_INSTALL_DIR}
)
endif(NOT_SUBPROJECT)