Skip to content
Snippets Groups Projects
Commit 66cbb3e9 authored by Oskar Lappi's avatar Oskar Lappi
Browse files

FetchContent only used as a backup now

parent a896f630
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,16 @@ set(CMAKE_CXX_STANDARD 20)
add_library(bimap INTERFACE)
target_include_directories(bimap INTERFACE include)
include(cmake/fetch_catch2.cmake)
enable_testing()
add_subdirectory(samples)
add_subdirectory(test)
option(DOWNLOAD_DEPS "Download unsatisfied dependencies using FetchContent" ON)
option(BUILD_TESTS "Build tests" ON)
if (BUILD_TESTS)
if (DOWNLOAD_DEPS)
include(cmake/fetch_catch2.cmake)
endif()
enable_testing()
add_subdirectory(test)
endif()
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG devel
GIT_PROGRESS TRUE
OVERRIDE_FIND_PACKAGE
)
find_package(Catch2)
if (NOT Catch2_FOUND)
message("Could not find Catch2 locally, downloading")
set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG devel
GIT_PROGRESS TRUE
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(catch2)
#set(Catch2_DIR
FetchContent_MakeAvailable(Catch2)
endif()
find_package(Catch2)
......@@ -3,27 +3,23 @@ macro(find_catch2_and_define_test_target)
set(TestInterface_EXISTS 1)
endif()
if(NOT Catch2_FOUND)
message("Loading Catch2 and defining test targets for ${CMAKE_CURRENT_LIST_DIR}")
find_package(Catch2 REQUIRED)
if(NOT TestInterface_EXISTS)
add_library(TestInterface INTERFACE)
find_package(Catch2 REQUIRED)
if(Catch2_FOUND)
message(" found Catch2, version: ${Catch2_VERSION}")
if(NOT TARGET Catch2::Catch2WithMain)
message(SEND_ERROR
"Tests depend on Catch2::Catch2WithMain, but Catch2 was built without "
"it. To fix this, build Catch2 with CATCH_BUILD_STATIC_LIBRARY=ON\n"
"(see: https://github.com/catchorg/Catch2/releases/tag/v2.13.5)")
endif()
if(Catch2_FOUND)
message(" found Catch2, version: ${Catch2_VERSION}")
if(NOT TARGET Catch2::Catch2WithMain)
message(SEND_ERROR
"Tests depend on Catch2::Catch2WithMain, but Catch2 was built without "
"it. To fix this, build Catch2 with CATCH_BUILD_STATIC_LIBRARY=ON\n"
"(see: https://github.com/catchorg/Catch2/releases/tag/v2.13.5)")
endif()
endif()
if(NOT TestInterface_EXISTS)
target_link_libraries(TestInterface INTERFACE ${PROJECT_NAME} Catch2::Catch2WithMain)
if(NOT ${Catch2_VERSION} VERSION_GREATER_EQUAL "3")
target_compile_definitions(TestInterface INTERFACE TESTS_CATCH2_USE_OLD_HEADER=1)
endif()
endif()
if(NOT TestInterface_EXISTS)
add_library(TestInterface INTERFACE)
target_link_libraries(TestInterface INTERFACE ${PROJECT_NAME} Catch2::Catch2WithMain)
if(NOT ${Catch2_VERSION} VERSION_GREATER_EQUAL "3")
target_compile_definitions(TestInterface INTERFACE TESTS_CATCH2_USE_OLD_HEADER=1)
endif()
endif()
endmacro()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment