Skip to content

Commit fe8e477

Browse files
Add a SYSTEM_DOCTEST CMake option
This option is off by default, maintaining the previous behavior. When enabled (along with FASTFLOAT_TEST), it bypasses the FetchContent machinery for doctest so that a system-wide installation of the doctest header can be easily used. In this case, the header doctest/doctest.h should be available on the compiler’s include path. This option is especially useful for Linux distributions and others that need to run the tests in fully offline build environments. Fixes #83.
1 parent bfda588 commit fe8e477

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tests/CMakeLists.txt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
44

55
include(FetchContent)
66

7-
FetchContent_Declare(doctest
8-
GIT_REPOSITORY https://github.com/onqtam/doctest.git
9-
GIT_TAG 2.4.6)
7+
option(SYSTEM_DOCTEST "Use system copy of doctest" OFF)
8+
9+
if (NOT SYSTEM_DOCTEST)
10+
FetchContent_Declare(doctest
11+
GIT_REPOSITORY https://github.com/onqtam/doctest.git
12+
GIT_TAG 2.4.6)
13+
endif()
1014
FetchContent_Declare(supplemental_test_files
1115
GIT_REPOSITORY https://github.com/fastfloat/supplemental_test_files.git
1216
GIT_TAG origin/main)
@@ -16,10 +20,12 @@ FetchContent_Declare(supplemental_test_files
1620
# FetchContent_MakeAvailable() was only introduced in 3.14
1721
# https://cmake.org/cmake/help/v3.14/release/3.14.html#modules
1822
# FetchContent_MakeAvailable(doctest)
19-
FetchContent_GetProperties(doctest)
20-
if(NOT doctest_POPULATED)
21-
FetchContent_Populate(doctest)
22-
add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR})
23+
if (NOT SYSTEM_DOCTEST)
24+
FetchContent_GetProperties(doctest)
25+
if(NOT doctest_POPULATED)
26+
FetchContent_Populate(doctest)
27+
add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR})
28+
endif()
2329
endif()
2430
FetchContent_GetProperties(supplemental_test_files)
2531
if(NOT supplemental_test_files_POPULATED)
@@ -40,7 +46,10 @@ function(fast_float_add_cpp_test TEST_NAME)
4046
target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++)
4147
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion)
4248
endif()
43-
target_link_libraries(${TEST_NAME} PUBLIC fast_float doctest supplemental-data)
49+
target_link_libraries(${TEST_NAME} PUBLIC fast_float supplemental-data)
50+
if (NOT SYSTEM_DOCTEST)
51+
target_link_libraries(${TEST_NAME} PUBLIC doctest)
52+
endif()
4453
endfunction(fast_float_add_cpp_test)
4554

4655

@@ -65,4 +74,4 @@ if (FASTFLOAT_EXHAUSTIVE)
6574
fast_float_add_cpp_test(random64)
6675
endif(FASTFLOAT_EXHAUSTIVE)
6776

68-
add_subdirectory(build_tests)
77+
add_subdirectory(build_tests)

0 commit comments

Comments
 (0)