Skip to content

Commit

Permalink
Backport AUTO option for Catch2
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Aug 30, 2023
1 parent a48a838 commit 435446b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 --------------------------------------------------------------

Expand Down
17 changes: 14 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
Expand Down

0 comments on commit 435446b

Please sign in to comment.