remove dependency to FetchContent

This commit is contained in:
Niels Lohmann 2020-05-01 15:14:37 +02:00
parent dbf1a1f413
commit 7ade3a0efb
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 18 additions and 24 deletions

View file

@ -3,22 +3,16 @@ option(JSON_Valgrind "Execute test suite with Valgrind" OFF)
option(JSON_NoExceptions "Build test suite without exceptions" OFF) option(JSON_NoExceptions "Build test suite without exceptions" OFF)
option(JSON_Coverage "Build test suite with coverage information" OFF) option(JSON_Coverage "Build test suite with coverage information" OFF)
if (${CMAKE_VERSION} VERSION_LESS "3.11.0") # target to download test data
message(FATAL_ERROR "The test suite needs at least CMake 3.11. This is CMake ${CMAKE_VERSION}.") add_custom_target(download_test_data
endif() COMMAND test -d json_test_data || git clone https://github.com/nlohmann/json_test_data.git --quiet --depth 1
COMMENT "Downloading test data from https://github.com/nlohmann/json_test_data"
include(FetchContent) WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
FetchContent_Declare(nlohmann_json_test_data
GIT_REPOSITORY https://github.com/nlohmann/json_test_data.git
GIT_SHALLOW TRUE
) )
FetchContent_GetProperties(nlohmann_json_test_data) # test fixture to download test data
if(NOT nlohmann_json_test_data_POPULATED) add_test(NAME "download_test_data" COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target download_test_data)
message(STATUS "Download test data") set_tests_properties(download_test_data PROPERTIES FIXTURES_SETUP TEST_DATA)
FetchContent_Populate(nlohmann_json_test_data)
message(STATUS "Download test data - done")
endif()
configure_file(src/test_data.hpp.in include/test_data.hpp) configure_file(src/test_data.hpp.in include/test_data.hpp)
@ -186,13 +180,13 @@ foreach(file ${files})
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} COMMAND ${testcase} ${DOCTEST_TEST_FILTER}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
) )
set_tests_properties("${testcase}_default" PROPERTIES LABELS "default") set_tests_properties("${testcase}_default" PROPERTIES LABELS "default" FIXTURES_REQUIRED TEST_DATA)
add_test(NAME "${testcase}_all" add_test(NAME "${testcase}_all"
COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip COMMAND ${testcase} ${DOCTEST_TEST_FILTER} --no-skip
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
) )
set_tests_properties("${testcase}_all" PROPERTIES LABELS "all") set_tests_properties("${testcase}_all" PROPERTIES LABELS "all" FIXTURES_REQUIRED TEST_DATA)
if(JSON_Valgrind) if(JSON_Valgrind)
add_test(NAME "${testcase}_valgrind" add_test(NAME "${testcase}_valgrind"

View file

@ -1 +1 @@
#define TEST_DATA_DIRECTORY "${nlohmann_json_test_data_SOURCE_DIR}" #define TEST_DATA_DIRECTORY "${CMAKE_BINARY_DIR}/json_test_data"