Skip to content

Commit a376f81

Browse files
committed
Remove side-effects from included cmake file
1 parent 99f3e07 commit a376f81

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/AddGoogleTest.cmake

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ cmake_minimum_required(VERSION 3.11.0)
33
set(CMAKE_CXX_STANDARD 17)
44
project(cpp11training)
55

6-
include(AddGoogleTest.cmake)
76

87
project(cpp11training)
98
file (GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
109
add_executable(cpp11training ${SOURCES})
1110
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
12-
target_link_libraries(cpp11training gtest gmock_main)
11+
12+
include(FetchGoogleTest.cmake)
13+
fetch_google_test()
14+
target_link_libraries(cpp11training gtest)

src/FetchGoogleTest.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.11.0)
2+
3+
include(FetchContent)
4+
5+
function(fetch_google_test)
6+
FetchContent_Declare(
7+
googletest
8+
GIT_REPOSITORY https://github.com/google/googletest.git
9+
GIT_TAG release-1.8.0
10+
)
11+
FetchContent_MakeAvailable(googletest)
12+
FetchContent_GetProperties(googletest)
13+
if(NOT googletest_POPULATED)
14+
message(Fetching googletest)
15+
FetchContent_Populate(googletest)
16+
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
17+
endif()
18+
endfunction()
19+

0 commit comments

Comments
 (0)