Don't apply global settings when configuring as a subproject.

This commit is contained in:
James Touton 2020-07-18 19:42:48 -07:00 committed by Martin Hořeňovský
parent de3a208e16
commit 6859c683e0

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5)
# detect if Catch is being bundled, # detect if Catch is being bundled,
# disable testsuite in that case # disable testsuite in that case
if(NOT DEFINED PROJECT_NAME) if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON) set(NOT_SUBPROJECT ON)
endif() endif()
# Catch2's build breaks if done in-tree. You probably should not build # Catch2's build breaks if done in-tree. You probably should not build
@ -20,8 +20,6 @@ project(Catch2 LANGUAGES CXX VERSION 2.13.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
include(CTest)
option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF) option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
option(CATCH_BUILD_TESTING "Build SelfTest project" ON) option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
@ -33,8 +31,6 @@ option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON) option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# define some folders # define some folders
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest) set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
@ -45,12 +41,16 @@ if(USE_WMAIN)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
endif() endif()
if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT) if(NOT_SUBPROJECT)
find_package(PythonInterp) include(CTest)
if (NOT PYTHONINTERP_FOUND) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
message(FATAL_ERROR "Python not found, but required for tests") if(BUILD_TESTING AND CATCH_BUILD_TESTING)
find_package(PythonInterp)
if (NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Python not found, but required for tests")
endif()
add_subdirectory(projects)
endif() endif()
add_subdirectory(projects)
endif() endif()
if(CATCH_BUILD_EXAMPLES) if(CATCH_BUILD_EXAMPLES)
@ -107,6 +107,7 @@ add_library(Catch2::Catch2 ALIAS Catch2)
# a subproject via `add_subdirectory`, or the destinations will break, # a subproject via `add_subdirectory`, or the destinations will break,
# see https://github.com/catchorg/Catch2/issues/1373 # see https://github.com/catchorg/Catch2/issues/1373
if (NOT_SUBPROJECT) if (NOT_SUBPROJECT)
include(CMakePackageConfigHelpers)
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
configure_package_config_file( configure_package_config_file(