Refined test compilation

This commit is contained in:
tastytea 2019-01-02 09:01:32 +01:00
parent a09bd56a2f
commit dbb15bee87
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07

View File

@ -1,24 +1,27 @@
if(WITH_TESTS)
include(CTest)
file(GLOB sources_tests src/tests/test_*.cpp)
find_package(Catch2)
if(Catch2_FOUND)
set(MYCATCH, Catch2::Catch2)
else()
if(Catch2_FOUND) # Catch 2.x
include(Catch)
add_executable(all_tests src/tests/main.cpp ${sources_tests})
target_link_libraries(all_tests ${CMAKE_PROJECT_NAME} Catch2::Catch2)
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
catch_discover_tests(all_tests)
else() # Catch 1.x
if(EXISTS "/usr/include/catch.hpp")
message(STATUS "Catch 1.x found.")
set(MYCATCH, "")
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} src/tests/main.cpp ${src})
target_link_libraries(${bin} ${CMAKE_PROJECT_NAME})
target_include_directories(${bin} PRIVATE "/usr/include/catch2")
add_test(${bin} ${bin})
endforeach()
else()
message(FATAL_ERROR
"Neither Catch 2.x nor Catch 1.x could be found.")
endif()
endif()
include(CTest)
file(GLOB sources_tests src/tests/test_*.cpp)
foreach(src ${sources_tests})
get_filename_component(bin ${src} NAME_WE)
add_executable(${bin} src/tests/main.cpp ${src})
target_link_libraries(${bin} ${CMAKE_PROJECT_NAME} ${MYCATCH})
target_include_directories(${bin} PRIVATE "/usr/include/catch2")
add_test(${bin} ${bin})
endforeach()
endif()