From 938da48da0dcea292ff970ba38a512e295258425 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 16 Sep 2023 15:56:29 +0200 Subject: [PATCH] Skip configuration of tests unless `BUILD_TESTING` is set See https://github.com/Martchus/tagparser/issues/26 and https://cmake.org/cmake/help/latest/module/CTest.html --- cmake/modules/TestTarget.cmake | 3 +++ cmake/modules/TestUtilities.cmake | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cmake/modules/TestTarget.cmake b/cmake/modules/TestTarget.cmake index 3de7c9e..203259b 100644 --- a/cmake/modules/TestTarget.cmake +++ b/cmake/modules/TestTarget.cmake @@ -8,6 +8,9 @@ if (TEST_CONFIG_DONE) endif () include(TestUtilities) +if(NOT BUILD_TESTING) + return() +endif() # find and link against CppUnit if required (used by all my projects, so it is required by default) if (NOT META_NO_CPP_UNIT) diff --git a/cmake/modules/TestUtilities.cmake b/cmake/modules/TestUtilities.cmake index 50eb2bf..89410c1 100644 --- a/cmake/modules/TestUtilities.cmake +++ b/cmake/modules/TestUtilities.cmake @@ -6,6 +6,9 @@ if (DEFINED TESTING_UTILITIES_LOADED) endif () set(TESTING_UTILITIES_LOADED YES) +# ensure CTest is loaded (e.g. for BUILD_TESTING variable) +include(CTest) + set(EXCLUDE_TEST_TARGET_BY_DEFAULT ON) if (ENABLE_DEVEL_DEFAULTS) set(EXCLUDE_TEST_TARGET_BY_DEFAULT OFF)