Refactor CMake test data directory code
* Add a cache variable and set default from environment. * Add '.git' suffix to URL variable.
This commit is contained in:
parent
9fc6d2b012
commit
9ea2eb7027
@ -14,6 +14,7 @@ endif()
|
||||
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${JSON_BuildTests_INIT})
|
||||
set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUTO/ONLY).")
|
||||
cmake_dependent_option(JSON_FastTests "Skip expensive/slow tests." OFF "JSON_BuildTests" OFF)
|
||||
set(JSON_TestDataDirectory "$ENV{JSON_TEST_DATA_DIRECTORY}" CACHE FILEPATH "Test data directory for the unit tests (will be downloaded if not specified).")
|
||||
cmake_dependent_option(JSON_Valgrind "Execute test suite with Valgrind." OFF "JSON_BuildTests" OFF)
|
||||
|
||||
set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.")
|
||||
@ -63,11 +64,5 @@ 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 "")
|
||||
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data.git)
|
||||
set(JSON_TEST_DATA_VERSION 3.1.0)
|
||||
|
||||
@ -52,10 +52,10 @@ 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}")
|
||||
if(JSON_TestDataDirectory)
|
||||
message(" Test data directory: ${JSON_TestDataDirectory}")
|
||||
else()
|
||||
message(" Test data: ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})")
|
||||
message(" Test data source: ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})")
|
||||
endif()
|
||||
|
||||
json_feature(JSON_Valgrind "Execute test suite with Valgrind?")
|
||||
|
||||
@ -5,14 +5,14 @@ set(_json_test_cmake_list_file ${CMAKE_CURRENT_LIST_FILE})
|
||||
#############################################################################
|
||||
|
||||
# if variable is set, use test data from given directory rather than downloading them
|
||||
if(JSON_TEST_DATA_DIRECTORY)
|
||||
if(JSON_TestDataDirectory)
|
||||
add_custom_target(download_test_data)
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TEST_DATA_DIRECTORY}\"\n")
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\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
|
||||
COMMAND test -d json_test_data || ${GIT_EXECUTABLE} clone -c advice.detachedHead=false --branch v${JSON_TEST_DATA_VERSION} ${JSON_TEST_DATA_URL} --quiet --depth 1
|
||||
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user