From 5b11bcdb33c5c8c97cd98c0deee8ec9fa94c71ed Mon Sep 17 00:00:00 2001 From: Gianfranco Costamagna Date: Mon, 25 Aug 2025 08:21:00 +0200 Subject: [PATCH] Make sure tests can be run offline and by adding new cmake switch Signed-off-by: Gianfranco Costamagna --- cmake/download_test_data.cmake | 7 ++++++- tests/CMakeLists.txt | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmake/download_test_data.cmake b/cmake/download_test_data.cmake index 6f63a08ac6..67216d7ac5 100644 --- a/cmake/download_test_data.cmake +++ b/cmake/download_test_data.cmake @@ -1,7 +1,11 @@ set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data) set(JSON_TEST_DATA_VERSION 3.1.0) -include(ExternalProject) +set(JSON_TEST_DATA_DIR /usr/share/json_test_data) + +if(EXISTS ${JSON_TEST_DATA_DIR}) + set(JSON_TestDataDirectory ${JSON_TEST_DATA_DIR}) +endif() # if variable is set, use test data from given directory rather than downloading them if(JSON_TestDataDirectory) @@ -9,6 +13,7 @@ if(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() + include(ExternalProject) # 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}/test_files\"\n") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b1dc5df104..715c198d9b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -192,6 +192,9 @@ if (JSON_Install) endif() add_subdirectory(cmake_add_subdirectory) -add_subdirectory(cmake_fetch_content) -add_subdirectory(cmake_fetch_content2) +if (NOT JSON_No_Internet) + add_subdirectory(cmake_fetch_content) + add_subdirectory(cmake_fetch_content2) +endif() + add_subdirectory(cmake_target_include_directories)