From 85b4d7c8d6e45ba32c65b1b75c6e48377c50506c Mon Sep 17 00:00:00 2001 From: "David P. Sicilia" Date: Sat, 1 Dec 2018 20:37:06 -0500 Subject: [PATCH] CMake: include(CTest) only when building tests. This is needed in order to support usage of this library as a subdirectory in a parent project. In that situation, prior to this change, the inclusion of CTest would unconditionally enable BUILD_TESTING which would then bleed into other parts of the project. Also added some comments explaining how this logic works. --- CMakeLists.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dc01f87..7fda48a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.1) project(spdlog VERSION 1.3.0 LANGUAGES CXX) -include(CTest) include(CMakeDependentOption) include(GNUInstallDirs) @@ -54,10 +53,22 @@ endif() option(SPDLOG_BUILD_EXAMPLES "Build examples" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_BUILD_BENCH "Build benchmarks" ${SPDLOG_MASTER_PROJECT}) +# Logic for enabling tests: If the user does not explicitly +# specify the value of the SPDLOG_BUILD_TESTING variable then the +# logic is simpler to reason about: that is, testing will be +# built if and only if BUILD_TESTING is ON and we are a Master +# Project. On the other hand, if the user overrides the value of +# SPDLOG_BUILD_TESTING then it can get a bit more tricky due to +# caching. + cmake_dependent_option(SPDLOG_BUILD_TESTING "Build spdlog tests" ${SPDLOG_MASTER_PROJECT} "BUILD_TESTING" OFF ) +if(SPDLOG_BUILD_TESTING) + # Include CTest conditionally since it will enable BUILD_TESTING. + include(CTest) +endif() target_include_directories( spdlog