Skip to content

Commit d4c7790

Browse files
author
Gianfranco Costamagna
committed
Make sure tests can be run offline and by adding new cmake switch
1 parent 22db828 commit d4c7790

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cmake/download_test_data.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
set(JSON_TEST_DATA_URL https://github.com/nlohmann/json_test_data)
22
set(JSON_TEST_DATA_VERSION 3.1.0)
33

4-
include(ExternalProject)
4+
set(JSON_TEST_DATA_DIR /usr/share/json_test_data-${JSON_TEST_DATA_VERSION})
5+
6+
if(EXISTS ${JSON_TEST_DATA_DIR})
7+
set(JSON_TestDataDirectory ${JSON_TEST_DATA_DIR})
8+
endif()
59

610
# if variable is set, use test data from given directory rather than downloading them
711
if(JSON_TestDataDirectory)
812
message(STATUS "Using test data in ${JSON_TestDataDirectory}.")
913
add_custom_target(download_test_data)
1014
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${JSON_TestDataDirectory}\"\n")
1115
else()
16+
include(ExternalProject)
1217
# create a header with the path to the downloaded test data
1318
file(WRITE ${CMAKE_BINARY_DIR}/include/test_data.hpp "#define TEST_DATA_DIRECTORY \"${CMAKE_BINARY_DIR}/test_files\"\n")
1419

tests/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ if (JSON_Install)
192192
endif()
193193

194194
add_subdirectory(cmake_add_subdirectory)
195-
add_subdirectory(cmake_fetch_content)
196-
add_subdirectory(cmake_fetch_content2)
195+
if (NOT JSON_No_Internet)
196+
add_subdirectory(cmake_fetch_content)
197+
add_subdirectory(cmake_fetch_content2)
198+
endif()
199+
197200
add_subdirectory(cmake_target_include_directories)

0 commit comments

Comments
 (0)