Skip to content

Commit e1d083a

Browse files
Mads AndreasenMads Andreasen
Mads Andreasen
authored and
Mads Andreasen
committedJun 24, 2021
Removed download of gtest if tests are not built
1 parent c25cadd commit e1d083a

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed
 

‎CMakeLists.txt

+32-29
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,39 @@ endif ()
1717
#========================================= gtest INSTALL =========================================#
1818
#=================================================================================================#
1919

20-
# Download and unpack googletest at configure time
21-
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
22-
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
23-
RESULT_VARIABLE result
24-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
25-
if(result)
26-
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
27-
endif()
28-
execute_process(COMMAND ${CMAKE_COMMAND} --build .
29-
RESULT_VARIABLE result
30-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
31-
if(result)
32-
message(FATAL_ERROR "Build step for googletest failed: ${result}")
33-
endif()
20+
if (BUILD_TESTS)
21+
# Download and unpack googletest at configure time
22+
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
23+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
24+
RESULT_VARIABLE result
25+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
26+
if(result)
27+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
28+
endif()
29+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
30+
RESULT_VARIABLE result
31+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download )
32+
if(result)
33+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
34+
endif()
35+
36+
# Prevent overriding the parent project's compiler/linker
37+
# settings on Windows
38+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
39+
40+
# Add googletest directly to our build. This defines
41+
# the gtest and gtest_main targets.
42+
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
43+
${CMAKE_BINARY_DIR}/googletest-build
44+
EXCLUDE_FROM_ALL)
45+
46+
# The gtest/gtest_main targets carry header search path
47+
# dependencies automatically when using CMake 2.8.11 or
48+
# later. Otherwise we have to add them here ourselves.
49+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
50+
include_directories("${gtest_SOURCE_DIR}/include")
51+
endif()
3452

35-
# Prevent overriding the parent project's compiler/linker
36-
# settings on Windows
37-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
38-
39-
# Add googletest directly to our build. This defines
40-
# the gtest and gtest_main targets.
41-
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
42-
${CMAKE_BINARY_DIR}/googletest-build
43-
EXCLUDE_FROM_ALL)
44-
45-
# The gtest/gtest_main targets carry header search path
46-
# dependencies automatically when using CMake 2.8.11 or
47-
# later. Otherwise we have to add them here ourselves.
48-
if (CMAKE_VERSION VERSION_LESS 2.8.11)
49-
include_directories("${gtest_SOURCE_DIR}/include")
5053
endif()
5154

5255
#=================================================================================================#

0 commit comments

Comments
 (0)
Please sign in to comment.