From 435446b9d9efd13f4f60640ca3f1528fa8026fca Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 30 Aug 2023 10:02:18 +0200 Subject: [PATCH] Backport AUTO option for Catch2 --- CMakeLists.txt | 4 +++- tests/CMakeLists.txt | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 577fac281..ad2b06415 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,7 +142,9 @@ endif() #--- enable unit testing capabilities ------------------------------------------ include(CTest) -option(USE_EXTERNAL_CATCH2 "Link against an external Catch2 v3 static library, otherwise build it locally" ON) + +set(USE_EXTERNAL_CATCH2 AUTO CACHE STRING "Link against an external Catch2 v3 static library, otherwise build it locally") +set_property(CACHE USE_EXTERNAL_CATCH2 PROPERTY STRINGS AUTO ON OFF) #--- enable CPack -------------------------------------------------------------- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 234323219..3b1b876db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -110,9 +110,20 @@ endif() CREATE_PODIO_TEST(ostream_operator.cpp "") CREATE_PODIO_TEST(write_ascii.cpp "") -if(USE_EXTERNAL_CATCH2) - find_package(Catch2 3 REQUIRED) +if(CMAKE_CXX_STANDARD GREATER_EQUAL 20) + set(CATCH2_MIN_VERSION 3.4) else() + set(CATCH2_MIN_VERSION 3.1) +endif() +if(USE_EXTERNAL_CATCH2) + if (USE_EXTERNAL_CATCH2 STREQUAL AUTO) + find_package(Catch2 ${CATCH2_MIN_VERSION}) + else() + find_package(Catch2 ${CATCH2_MIN_VERSION} REQUIRED) + endif() +endif() + +if(NOT Catch2_FOUND) message(STATUS "Fetching local copy of Catch2 library for unit-tests...") # Build Catch2 with the default flags, to avoid generating warnings when we # build it @@ -122,7 +133,7 @@ else() FetchContent_Declare( Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.0.1 + GIT_TAG v3.4.0 ) FetchContent_MakeAvailable(Catch2) set(CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras ${CMAKE_MODULE_PATH})