diff --git a/CMakeLists.txt b/CMakeLists.txt index 494be3f..6508d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,12 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(ExportCompileCommands) include(sccache) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + include(CTest) +endif() + +include(FetchContent) + configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" "${PROJECT_BINARY_DIR}/include/version.h") @@ -20,3 +26,7 @@ target_compile_features(hello PUBLIC cxx_std_20) target_include_directories(hello PRIVATE "${PROJECT_BINARY_DIR}/include" "${PROJECT_SOURCE_DIR}/include") + +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + add_subdirectory(tests) +endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..5b6fb53 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,14 @@ +FetchContent_Declare( + catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.4.0) +FetchContent_MakeAvailable(catch2) + +add_executable(dummy_tests dummy.cpp) + +target_compile_features(dummy_tests PRIVATE cxx_std_20) + +target_link_libraries(dummy_tests PRIVATE Catch2::Catch2WithMain) + +include(Catch) +catch_discover_tests(dummy_tests) diff --git a/tests/dummy.cpp b/tests/dummy.cpp new file mode 100644 index 0000000..cf61e0b --- /dev/null +++ b/tests/dummy.cpp @@ -0,0 +1,4 @@ +#include + +TEST_CASE("dummy", "dummy tests") { REQUIRE(1 + 1 == 2); } +TEST_CASE("dummy fails", "dummy tests") { REQUIRE_FALSE(1 + 1 != 2); }