Move test data download into CMake script

Avoid using shell commands to check if the test directory exists by
using a CMake script.
This commit is contained in:
Florian Albrechtskirchinger 2022-09-24 14:35:07 +02:00
parent 3c77b378e6
commit 875cc362e0
No known key found for this signature in database
GPG Key ID: 19618CE9B2D4BE6D
2 changed files with 21 additions and 1 deletions

View File

@ -12,7 +12,11 @@ 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} --quiet --depth 1
COMMAND ${CMAKE_COMMAND}
-DGIT_EXECUTABLE=${GIT_EXECUTABLE}
-DJSON_TEST_DATA_VERSION=${JSON_TEST_DATA_VERSION}
-DJSON_TEST_DATA_URL=${JSON_TEST_DATA_URL}
-P ${PROJECT_SOURCE_DIR}/cmake/scripts/clone_test_data.cmake
COMMENT "Downloading test data from ${JSON_TEST_DATA_URL} (v${JSON_TEST_DATA_VERSION})"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)

View File

@ -0,0 +1,16 @@
# clone test data
get_filename_component(test_data_dir json_test_data ABSOLUTE)
if(NOT EXISTS ${test_data_dir})
execute_process(COMMAND ${GIT_EXECUTABLE} clone
-q -c advice.detachedHead=false -b v${JSON_TEST_DATA_VERSION} --depth 1
-- ${JSON_TEST_DATA_URL} ${test_data_dir}
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_output
ERROR_VARIABLE git_output)
if(NOT git_result EQUAL 0)
message(FATAL_ERROR "git failed:\n${git_output}")
endif()
endif()