From 92af9306ad989e657a2e37bccf8e0b7723038cb1 Mon Sep 17 00:00:00 2001 From: Cliff Foster Date: Mon, 26 Feb 2024 16:58:04 -0800 Subject: [PATCH] Test switching to FetchContent and using Catch2 V3 --- cmake/idi/functions/framework/idi_init.cmake | 13 +++++++------ cmake/idi/functions/idi_component_test.cmake | 6 ++++-- cmake/idi/functions/idi_demo.cmake | 6 ++++-- src/base/tests/test.cpp | 6 ++++-- src/base/tests/test_public.cpp | 12 +++++++----- src/main/tests/dll_test.cpp | 4 +++- 6 files changed, 29 insertions(+), 18 deletions(-) diff --git a/cmake/idi/functions/framework/idi_init.cmake b/cmake/idi/functions/framework/idi_init.cmake index 05446c7..19dfff8 100644 --- a/cmake/idi/functions/framework/idi_init.cmake +++ b/cmake/idi/functions/framework/idi_init.cmake @@ -8,6 +8,7 @@ macro(idi_init) include(CTest) + include(FetchContent) idi_cmake_hook(pre-init) @@ -122,21 +123,21 @@ macro(idi_init) # Define a nice short hand for 3rd party external library folders set(IDICMAKE_EXTERNAL_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}/lib") + FetchContent_Declare(Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.5.2 + ) + FetchContent_MakeAvailable(Catch2) + # Add the main source folder. idi_cmake_hook(pre-source) add_subdirectory("src") idi_cmake_hook(post-source) - # Catch is included by default as a submodule - if(NOT TARGET Catch2) - add_subdirectory(lib/Catch2) - endif() - if(IDICMAKE_BUILD_DEMOS) add_subdirectory("demo") endif() - include("${CMAKE_CURRENT_LIST_DIR}/lib/libraries.cmake") idi_cmake_hook(post-configure) diff --git a/cmake/idi/functions/idi_component_test.cmake b/cmake/idi/functions/idi_component_test.cmake index dd22ffe..7d2c6b3 100644 --- a/cmake/idi/functions/idi_component_test.cmake +++ b/cmake/idi/functions/idi_component_test.cmake @@ -14,8 +14,10 @@ function(__idi_component_test component_name test_file) add_executable("${CURRENT_LIBRARY_TEST}" ${test_file}) idi_target_compile_settings("${CURRENT_LIBRARY_TEST}") - target_include_directories("${CURRENT_LIBRARY_TEST}" SYSTEM PRIVATE - "${IDICMAKE_EXTERNAL_LIB_DIR}/Catch2/single_include") + # target_include_directories("${CURRENT_LIBRARY_TEST}" SYSTEM PRIVATE + # "${IDICMAKE_EXTERNAL_LIB_DIR}/Catch2/single_include") + + target_link_libraries("${CURRENT_LIBRARY_TEST}" PRIVATE Catch2::Catch2WithMain) set(ADD_MODE "ADDITIONAL_SOURCES") set(ADD_CORE true) diff --git a/cmake/idi/functions/idi_demo.cmake b/cmake/idi/functions/idi_demo.cmake index 5293842..437f26a 100644 --- a/cmake/idi/functions/idi_demo.cmake +++ b/cmake/idi/functions/idi_demo.cmake @@ -12,8 +12,10 @@ function(__idi_demo demo_name demo_file) add_executable("${CURRENT_DEMO}" ${demo_file}) idi_target_compile_settings("${CURRENT_DEMO}") - target_include_directories("${CURRENT_DEMO}" SYSTEM PRIVATE - "${IDICMAKE_EXTERNAL_LIB_DIR}/Catch2/single_include") + # target_include_directories("${CURRENT_DEMO}" SYSTEM PRIVATE + # "${IDICMAKE_EXTERNAL_LIB_DIR}/Catch2/single_include") + + target_link_libraries("${CURRENT_DEMO}" PRIVATE Catch2::Catch2WithMain) set(ADD_MODE "ADDITIONAL_SOURCES") set(ADD_CORE true) diff --git a/src/base/tests/test.cpp b/src/base/tests/test.cpp index 91663a4..6e6f129 100644 --- a/src/base/tests/test.cpp +++ b/src/base/tests/test.cpp @@ -6,12 +6,14 @@ */ // NOLINTBEGIN #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file +#include +#include +#include + #include "@PROJECT_NAME@/public/idi_version.h" #include "@PROJECT_NAME@/public/__build_info.out.h" #include "@PROJECT_NAME@/version.hpp" -#include - TEST_CASE("Version numbers are correctly set and returned.", "[base]") { SECTION("Internal API calls.") { REQUIRE(@__idi_namespace@::base::get_version_major() == @__idi_c_caps_namespace@_VERSION_MAJOR); diff --git a/src/base/tests/test_public.cpp b/src/base/tests/test_public.cpp index 5f70c60..ef9427a 100644 --- a/src/base/tests/test_public.cpp +++ b/src/base/tests/test_public.cpp @@ -6,7 +6,9 @@ */ // NOLINTBEGIN #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file -#include +#include +#include +#include #include "@PROJECT_NAME@/public/idi_version.h" #include "@PROJECT_NAME@/public/version.h" @@ -22,11 +24,11 @@ TEST_CASE("Version numbers are correctly set and returned.", "[base]") { TEST_CASE("Git information are correctly set and returned.", "[base]") { SECTION("Internal API calls.") { - REQUIRE_THAT( @__idi_c_namespace@_get_git_hash_short(), Catch::Equals(@__idi_c_caps_namespace@_VERSION_GIT_HASH_SHORT) ); - REQUIRE_THAT( @__idi_c_namespace@_get_git_hash_long(), Catch::Equals(@__idi_c_caps_namespace@_VERSION_GIT_HASH_FULL) ); - REQUIRE_THAT( @__idi_c_namespace@_get_git_branch(), Catch::Equals(@__idi_c_caps_namespace@_VERSION_GIT_BRANCH) ); + REQUIRE_THAT( @__idi_c_namespace@_get_git_hash_short(), Catch::Matchers::Equals(@__idi_c_caps_namespace@_VERSION_GIT_HASH_SHORT) ); + REQUIRE_THAT( @__idi_c_namespace@_get_git_hash_long(), Catch::Matchers::Equals(@__idi_c_caps_namespace@_VERSION_GIT_HASH_FULL) ); + REQUIRE_THAT( @__idi_c_namespace@_get_git_branch(), Catch::Matchers::Equals(@__idi_c_caps_namespace@_VERSION_GIT_BRANCH) ); REQUIRE( @__idi_c_namespace@_get_git_is_dirty() == static_cast(@__idi_c_caps_namespace@_VERSION_GIT_DIRTY) ); - REQUIRE_THAT( @__idi_c_namespace@_get_build_timestamp(), Catch::Equals(@__idi_c_caps_namespace@_BUILD_TIMESTAMP) ); + REQUIRE_THAT( @__idi_c_namespace@_get_build_timestamp(), Catch::Matchers::Equals(@__idi_c_caps_namespace@_BUILD_TIMESTAMP) ); } } // NOLINTEND diff --git a/src/main/tests/dll_test.cpp b/src/main/tests/dll_test.cpp index 5dd6171..4ab7cc0 100644 --- a/src/main/tests/dll_test.cpp +++ b/src/main/tests/dll_test.cpp @@ -7,7 +7,9 @@ #define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file #include "@PROJECT_NAME@/public/version.h" -#include +#include +#include +#include TEST_CASE("Version numbers are correctly set and returned.", "[base]") { SECTION("Public API calls.") {