This repository has been archived on 2021-03-22. You can view files and clone it, but cannot push or open issues or pull requests.
backend/tests/CMakeLists.txt

46 lines
1.3 KiB
CMake
Raw Normal View History

2020-06-29 03:01:30 +02:00
include(CTest)
2020-06-30 07:32:02 +02:00
file(GLOB sources_testlib ../src/*.cpp)
add_library(${PROJECT_NAME}_testlib SHARED ${sources_testlib})
target_include_directories(${PROJECT_NAME}_testlib
PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>")
target_link_libraries(${PROJECT_NAME}_testlib
2020-07-02 00:19:18 +02:00
PUBLIC
PkgConfig::cgicc
nlohmann_json
std::filesystem
PkgConfig::libgit2
CURL::libcurl)
2020-06-30 07:32:02 +02:00
2020-06-29 03:01:30 +02:00
file(GLOB sources_tests test_*.cpp)
find_package(Catch2 CONFIG)
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests main.cpp ${sources_tests})
target_link_libraries(all_tests
2020-06-30 07:32:02 +02:00
PRIVATE Catch2::Catch2 ${PROJECT_NAME}_testlib)
2020-06-29 03:01:30 +02:00
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
else() # Catch 1.x
if(EXISTS "/usr/include/catch.hpp")
message(STATUS "Catch 1.x found.")
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} main.cpp ${src})
2020-06-30 07:32:02 +02:00
target_link_libraries(${bin} PRIVATE ${PROJECT_NAME}_testlib)
2020-06-29 03:01:30 +02:00
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
endforeach()
else()
message(FATAL_ERROR
"Neither Catch 2.x nor Catch 1.x could be found.")
endif()
endif()
2020-06-29 08:44:05 +02:00
unset(sources_tests)