Skip to content

Commit e1c6be3

Browse files
authored
fix(build): add NBYTES_ENABLE_TESTING CMake option (#15)
To control whether to download test dependencies.
1 parent 1a62f8e commit e1c6be3

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

CMakeLists.txt

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ option(NBYTES_DEVELOPMENT_CHECKS "Enable development checks" OFF)
1212

1313
include(GNUInstallDirs)
1414
include(FetchContent)
15+
include(CTest)
16+
17+
option(NBYTES_ENABLE_TESTING "Enable testing" ${BUILD_TESTING})
1518

16-
FetchContent_Declare(
17-
googletest
18-
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
19-
)
20-
# For Windows: Prevent overriding the parent project's compiler/linker settings
21-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
22-
FetchContent_MakeAvailable(googletest)
2319

2420
add_subdirectory(src)
25-
enable_testing()
26-
add_subdirectory(tests)
21+
22+
if (NBYTES_ENABLE_TESTING)
23+
FetchContent_Declare(
24+
googletest
25+
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
26+
URL_HASH SHA256=edd885a1ab32b6999515a880f669efadb80b3f880215f315985fa3f6eca7c4d3
27+
FIND_PACKAGE_ARGS NAMES GTest
28+
)
29+
# For Windows: Prevent overriding the parent project's compiler/linker settings
30+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
31+
FetchContent_MakeAvailable(googletest)
32+
33+
add_subdirectory(tests)
34+
endif()
2735

2836
install(
2937
FILES include/nbytes.h

0 commit comments

Comments
 (0)