From 584d22dece052cdd89f4fbc8032b4890e06e3c76 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 20 Oct 2023 10:58:31 +0200 Subject: [PATCH 1/3] feat: enable sccache --- .nix/flake.nix | 1 + CMakeLists.txt | 1 + cmake/sccache.cmake | 6 ++++++ 3 files changed, 8 insertions(+) create mode 100644 cmake/sccache.cmake diff --git a/.nix/flake.nix b/.nix/flake.nix index 16172ef..8ea9b96 100644 --- a/.nix/flake.nix +++ b/.nix/flake.nix @@ -15,6 +15,7 @@ # building gcc cmake + sccache # pre-commit pre-commit diff --git a/CMakeLists.txt b/CMakeLists.txt index dec0741..494be3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ project( list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(ExportCompileCommands) +include(sccache) configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" "${PROJECT_BINARY_DIR}/include/version.h") diff --git a/cmake/sccache.cmake b/cmake/sccache.cmake new file mode 100644 index 0000000..52adea6 --- /dev/null +++ b/cmake/sccache.cmake @@ -0,0 +1,6 @@ +find_program(SCCACHE_FOUND sccache) + +if(SCCACHE_FOUND) + set(CMAKE_C_COMPILER_LAUNCHER sccache) + set(CMAKE_CXX_COMPILER_LAUNCHER sccache) +endif() From 75d3fc3547557b6e71f2be43f9f73f071afc6bcc Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 20 Oct 2023 10:58:41 +0200 Subject: [PATCH 2/3] feat: enable Ninja --- .nix/flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/.nix/flake.nix b/.nix/flake.nix index 8ea9b96..ee64884 100644 --- a/.nix/flake.nix +++ b/.nix/flake.nix @@ -15,6 +15,7 @@ # building gcc cmake + ninja sccache # pre-commit From a286c514f5ecdf8ed8658673e2c147570e2a760d Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Fri, 20 Oct 2023 10:59:30 +0200 Subject: [PATCH 3/3] test: add dummy tests --- CMakeLists.txt | 10 ++++++++++ tests/CMakeLists.txt | 14 ++++++++++++++ tests/dummy.cpp | 4 ++++ 3 files changed, 28 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/dummy.cpp 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); }