From f015a9444d8e23400a26188e4d5b2ff72302db82 Mon Sep 17 00:00:00 2001 From: Marius Kittler Date: Sun, 22 Jan 2023 23:07:15 +0100 Subject: [PATCH] Support version 3 of Catch2 --- CMakeLists.txt | 5 +++++ tests/basic.cc | 6 +++++- tests/typed.cc | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0052036..7224c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,10 @@ use_package( # find catch2 (required by tests) use_package(TARGET_NAME Catch2::Catch2 PACKAGE_NAME Catch2 LIBRARIES_VARIABLE "TEST_LIBRARIES") +if (Catch2_VERSION VERSION_GREATER_EQUAL 3) + list(APPEND CATCH2_DEFINITIONS CATCH2_SPLIT_HEADERS) + list(APPEND TEST_LIBRARIES Catch2::Catch2WithMain) +endif () # find threading library (required by examples) use_package(TARGET_NAME Threads::Threads PACKAGE_NAME Threads LIBRARIES_VARIABLE "TEST_LIBRARIES") @@ -100,6 +104,7 @@ include(TestUtilities) list(APPEND TEST_LIBRARIES ${META_TARGET_NAME}) foreach (TEST ${TESTS}) configure_test_target(TEST_NAME "${TEST}_tests" SRC_FILES "tests/${TEST}.cc" LIBRARIES "${TEST_LIBRARIES}") + target_compile_definitions("${META_TARGET_NAME}_${TEST}_tests" PRIVATE "${CATCH2_DEFINITIONS}") endforeach () foreach (EXAMPLE ${EXAMPLES}) configure_test_target(TEST_NAME "${EXAMPLE}_example" SRC_FILES "examples/${EXAMPLE}.cc" LIBRARIES "${TEST_LIBRARIES}") diff --git a/tests/basic.cc b/tests/basic.cc index 487861f..fae4524 100644 --- a/tests/basic.cc +++ b/tests/basic.cc @@ -1,7 +1,11 @@ #include "../lmdb-safe.hh" -#define CATCH_CONFIG_MAIN +#define CATCH_CONFIG_MAIN // for catch2 < 3 +#ifdef CATCH2_SPLIT_HEADERS +#include +#else #include +#endif #include diff --git a/tests/typed.cc b/tests/typed.cc index d6cde1a..3fe5b40 100644 --- a/tests/typed.cc +++ b/tests/typed.cc @@ -1,8 +1,12 @@ #include "../lmdb-boost-serialization.hh" #include "../lmdb-typed.hh" -#define CATCH_CONFIG_MAIN +#define CATCH_CONFIG_MAIN // for catch2 < 3 +#ifdef CATCH2_SPLIT_HEADERS +#include +#else #include +#endif #include