Skip to content

Commit

Permalink
Test switching to FetchContent and using Catch2 V3
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Foster committed Feb 27, 2024
1 parent 2fa47b2 commit 92af930
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
13 changes: 7 additions & 6 deletions cmake/idi/functions/framework/idi_init.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

macro(idi_init)
include(CTest)
include(FetchContent)

idi_cmake_hook(pre-init)

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions cmake/idi/functions/idi_component_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions cmake/idi/functions/idi_demo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/base/tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
*/
// NOLINTBEGIN
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
#include <catch2/generators/catch_generators_all.hpp>

#include "@PROJECT_NAME@/public/idi_version.h"
#include "@PROJECT_NAME@/public/__build_info.out.h"
#include "@PROJECT_NAME@/version.hpp"

#include <catch2/catch.hpp>

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);
Expand Down
12 changes: 7 additions & 5 deletions src/base/tests/test_public.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/
// NOLINTBEGIN
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
#include <catch2/generators/catch_generators_all.hpp>

#include "@PROJECT_NAME@/public/idi_version.h"
#include "@PROJECT_NAME@/public/version.h"
Expand All @@ -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<bool>(@__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
4 changes: 3 additions & 1 deletion src/main/tests/dll_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_all.hpp>
#include <catch2/generators/catch_generators_all.hpp>

TEST_CASE("Version numbers are correctly set and returned.", "[base]") {
SECTION("Public API calls.") {
Expand Down

0 comments on commit 92af930

Please sign in to comment.