From a0359980f042418b993f7c632562f4d680872e62 Mon Sep 17 00:00:00 2001 From: David Seifert Date: Thu, 18 Jan 2018 00:01:27 +0100 Subject: [PATCH] Use CTest to control test suite via BUILD_TESTING --- CMakeLists.txt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 05360548..c8721e05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ cmake_minimum_required(VERSION 3.0) +# detect if Catch is being bundled, +# disable testsuite in that case +if(NOT DEFINED PROJECT_NAME) + set(NOT_SUBPROJECT ON) +endif() + project(CatchSelfTest) include(GNUInstallDirs) @@ -287,7 +293,19 @@ SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES}) # Projects consuming Catch via ExternalProject_Add might want to use install step # without building all of our selftests. -if (NOT NO_SELFTEST) + +if(DEFINED NO_SELFTEST) + message(DEPRECATION "*** CMake option NO_SELFTEST is deprecated; use BUILD_TESTING instead") + if (NO_SELFTEST) + set(BUILD_TESTING OFF CACHE BOOL "Disable Catch2 internal testsuite" FORCE) + else() + set(BUILD_TESTING ON CACHE BOOL "Disable Catch2 internal testsuite" FORCE) + endif() +endif() + +include(CTest) + +if (BUILD_TESTING AND NOT_SUBPROJECT) add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS}) target_include_directories(SelfTest PRIVATE ${HEADER_DIR})