diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b769b9..831a105 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,12 +15,24 @@ include(GNUInstallDirs) include(FetchContent) + +option(USE_SANITIZER "Sanitizers for debugging" ON) +option(DISABLE_WARNINGS "Disbale compilation warnings" OFF) +option(USE_PYTHON "Build python bindings" ON) +option(AARE_BUILD_TESTS "Build tests" OFF) + FetchContent_Declare(json GIT_REPOSITORY https://github.com/nlohmann/json GIT_TAG v3.11.3 ) FetchContent_MakeAvailable(json) +if(AARE_BUILD_TESTS) + add_subdirectory(tests) +endif() + + + find_package(fmt 6 REQUIRED) @@ -33,9 +45,7 @@ else() endif() set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -option(USE_SANITIZER "Sanitizers for debugging" ON) -option(DISABLE_WARNINGS "Disbale compilation warnings" OFF) -option(USE_PYTHON "Build python bindings" ON) + set(OPTIONAL_FLAGS "") @@ -71,6 +81,7 @@ target_link_libraries(aare INTERFACE common core file_io) add_subdirectory(examples) target_link_libraries(example PUBLIC aare) + if(USE_PYTHON) find_package (Python 3.11 COMPONENTS Interpreter Development) find_package(pybind11 2.11 REQUIRED) diff --git a/include/common/defs.hpp b/include/common/defs.hpp index 230452e..1d34db2 100644 --- a/include/common/defs.hpp +++ b/include/common/defs.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 22e2bf6..aedc033 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -3,3 +3,14 @@ add_library(common "${CMAKE_CURRENT_SOURCE_DIR}/defs.cpp") target_link_libraries(common PUBLIC fmt::fmt) +if(AARE_BUILD_TESTS) + set(TestSources + ${CMAKE_CURRENT_SOURCE_DIR}/defs.test.cpp + ) + target_sources(tests PRIVATE ${TestSources} ) + + #Work around to remove, this is not the way to do it =) + target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common) + target_link_libraries(tests PRIVATE common) + +endif() \ No newline at end of file diff --git a/src/common/defs.test.cpp b/src/common/defs.test.cpp new file mode 100644 index 0000000..4e5caf7 --- /dev/null +++ b/src/common/defs.test.cpp @@ -0,0 +1,8 @@ +#include +#include +#include "defs.hpp" +TEST_CASE("Enum to string conversion"){ + //By the way I don't think the enum string conversions should be in the defs.hpp file + //but let's use this to show a test + REQUIRE(toString(DetectorType::Jungfrau) == "Jungfrau"); +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..4a2d076 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,20 @@ +FetchContent_Declare( + Catch2 + GIT_SHALLOW TRUE + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.5.3 +) +FetchContent_MakeAvailable(Catch2) +list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras) + +add_executable(tests test.cpp) +target_link_libraries(tests PRIVATE Catch2::Catch2WithMain) + +set_target_properties(tests PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + OUTPUT_NAME run_tests +) + +include(CTest) +include(Catch) +catch_discover_tests(tests) \ No newline at end of file diff --git a/tests/test.cpp b/tests/test.cpp new file mode 100644 index 0000000..0191c08 --- /dev/null +++ b/tests/test.cpp @@ -0,0 +1 @@ +//Empty file to satisfy CMake when no other tests are added \ No newline at end of file