Merge cmake/download_test_data.cmake into cmake/test.cmake

This commit is contained in:
Florian Albrechtskirchinger 2022-09-22 21:34:23 +02:00
parent 601b5913ed
commit e129682807
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
4 changed files with 34 additions and 20 deletions

View File

@ -1,19 +0,0 @@
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data)
set(JSON_TEST_DATA_VERSION 3.1.0)
# if variable is set, use test data from given directory rather than downloading them
if(JSON_TestDataDirectory)
message(STATUS "Using test data in ${JSON_TestDataDirectory}.")
add_custom_target(download_test_data)
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\n")
else()
find_package(Git)
# target to download test data
add_custom_target(download_test_data
COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL}.git --quiet --depth 1
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# create a header with the path to the downloaded test data
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"\n")
endif()

View File

@ -62,3 +62,12 @@ endif()
if (JSON_SystemInclude)
set(NLOHMANN_JSON_SYSTEM_INCLUDE "SYSTEM")
endif()
if(JSON_TestDataDirectory)
set(JSON_TEST_DATA_DIRECTORY "${JSON_TestDataDirectory}" CACHE INTERNAL "")
elseif(DEFINED ENV{JSON_TEST_DATA_DIRECTORY})
set(JSON_TEST_DATA_DIRECTORY "$ENV{JSON_TEST_DATA_DIRECTORY}" CACHE INTERNAL "")
endif()
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data CACHE INTERNAL "")
set(JSON_TEST_DATA_VERSION 3.1.0 CACHE INTERNAL "")

View File

@ -51,7 +51,17 @@ json_feature(JSON_BuildTests "Build tests?")
if(JSON_BuildTests)
json_feature(JSON_32bitTest "Build the 32bit unit test?" VALUES AUTO ONLY)
json_feature(JSON_FastTests "Skip expensive/slow tests?")
if(JSON_TEST_DATA_DIRECTORY)
message(" Test data: ${JSON_TEST_DATA_DIRECTORY}")
else()
message(" Test data: ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})")
endif()
json_feature(JSON_Valgrind "Execute test suite with Valgrind?")
if(JSON_Valgrind)
message(" Valgrind command: ${CMAKE_MEMORYCHECK_COMMAND}" ${CMAKE_MEMORYCHECK_COMMAND_OPTIONS})
endif()
set(test_cxx_standards "")
foreach(cxx_standard ${JSON_TEST_CXX_STANDARDS_FEATURE_INFO})

View File

@ -4,7 +4,21 @@ set(_json_test_cmake_list_file ${CMAKE_CURRENT_LIST_FILE})
# download test data
#############################################################################
include(download_test_data)
# if variable is set, use test data from given directory rather than downloading them
if(JSON_TEST_DATA_DIRECTORY)
add_custom_target(download_test_data)
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TEST_DATA_DIRECTORY}\"\n")
else()
find_package(Git REQUIRED)
# target to download test data
add_custom_target(download_test_data
COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL}.git --quiet --depth 1
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
# create a header with the path to the downloaded test data
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/json_test_data\"\n")
endif()
# test fixture to download test data
add_test(NAME "download_test_data" COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}