Skip to content

Commit 51eece6

Browse files
committed
CMake: Don't include googletest if not building the tests
1 parent 65d94d0 commit 51eece6

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

CMakeLists.txt

+17-15
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,25 @@ endmacro(set_join)
230230
###############################################################################
231231
# enable gtest framework, valgrind, and collection of results
232232

233-
enable_testing()
234-
include(CTest)
235-
236-
### google test + mock - enable "make test" and add_test()
237-
238-
# this fixes compilation with static libs on MSVC
239-
set(gtest_force_shared_crt ON CACHE BOOL "on" FORCE)
240-
if(NOT MSVC)
241-
# silence some warnings
242-
set(GTEST_SAVE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
243-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers -Wno-deprecated")
244-
endif()
233+
if (SAMPLING_BUILD_TESTS)
234+
enable_testing()
235+
include(CTest)
236+
237+
### google test + mock - enable "make test" and add_test()
238+
239+
# this fixes compilation with static libs on MSVC
240+
set(gtest_force_shared_crt ON CACHE BOOL "on" FORCE)
241+
if(NOT MSVC)
242+
# silence some warnings
243+
set(GTEST_SAVE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
244+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers -Wno-deprecated")
245+
endif()
245246

246-
add_subdirectory(extlib/googletest/googletest)
247+
add_subdirectory(extlib/googletest/googletest)
247248

248-
if(NOT MSVC)
249-
set(CMAKE_CXX_FLAGS "${GTEST_SAVE_CXX_FLAGS}")
249+
if(NOT MSVC)
250+
set(CMAKE_CXX_FLAGS "${GTEST_SAVE_CXX_FLAGS}")
251+
endif()
250252
endif()
251253

252254
################################################################################

0 commit comments

Comments
 (0)