From c11c9f05868ac6367851102a71b4158e1d6bdf55 Mon Sep 17 00:00:00 2001 From: Dmitriy Purgin Date: Thu, 29 Jun 2023 16:02:10 +0200 Subject: [PATCH 1/2] Do not enable testing if included as subproject --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38d31d8..c6dde34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.12) +IF (DEFINED PROJECT_NAME) + SET(SCALR_SUBPROJECT ON) +ENDIF() + FILE(READ "${CMAKE_CURRENT_SOURCE_DIR}/include/scalr/version.hpp" version) STRING(REGEX MATCH "VERSION_MAJOR ([0-9]*)" _ ${version}) @@ -44,7 +48,7 @@ SET_TARGET_PROPERTIES( INSTALL(DIRECTORY include/scalr TYPE INCLUDE) # Testing -IF(BUILD_TESTING) +IF(BUILD_TESTING AND NOT SCALR_SUBPROJECT) ENABLE_TESTING() ADD_SUBDIRECTORY(tests) ENDIF() From 8febdcc047f3a9692629da6e748301420cb17e15 Mon Sep 17 00:00:00 2001 From: Dmitriy Purgin Date: Thu, 29 Jun 2023 16:12:35 +0200 Subject: [PATCH 2/2] Fetch Catch2 from GitHub if not installed --- tests/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 900b678..cd71aca 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,14 @@ -find_package(Catch2 3 REQUIRED) +find_package(Catch2 3 QUIET) + +if (NOT Catch2_FOUND) + include(FetchContent) + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.3.2) + FetchContent_MakeAvailable(Catch2) +endif() + include(Catch) add_executable(