summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVollstrecker <github@vollstreckernet.de>2021-03-13 16:58:42 +0100
committerGitHub <noreply@github.com>2021-03-13 16:58:42 +0100
commit5065389aabfa1d70a49d57eb355b9db4500801be (patch)
treeb1075d3ddc9370cdea8e4c16a4f8fe48000c224c
parente8512bc38c4c0060858c3306b0660a3f126aee30 (diff)
downloadgoogletest-5065389aabfa1d70a49d57eb355b9db4500801be.tar.gz
googletest-5065389aabfa1d70a49d57eb355b9db4500801be.zip
Use Fetchcontent instead of ExternalProject
Hi, instead of ExternalProject and a new file that is spawned in a new process, it's easier to just use FetchContent. cmake 3.14 should be old enough to be spread.
-rw-r--r--googletest/README.md62
1 files changed, 10 insertions, 52 deletions
diff --git a/googletest/README.md b/googletest/README.md
index 717c8867..33604bd8 100644
--- a/googletest/README.md
+++ b/googletest/README.md
@@ -85,58 +85,18 @@ main build can be done a few different ways:
is just a little more complex, but doesn't have the limitations of the other
methods.
-The last of the above methods is implemented with a small piece of CMake code in
-a separate file (e.g. `CMakeLists.txt.in`) which is copied to the build area and
-then invoked as a sub-build _during the CMake stage_. That directory is then
-pulled into the main build with `add_subdirectory()`. For example:
+The last of the above methods is implemented with a small piece of CMake code so
+the code is pulled into the main build.
-New file `CMakeLists.txt.in`:
+Just add to your `CMakeLists.txt`:
```cmake
-cmake_minimum_required(VERSION 2.8.12)
-
-project(googletest-download NONE)
-
-include(ExternalProject)
-ExternalProject_Add(googletest
- GIT_REPOSITORY https://github.com/google/googletest.git
- GIT_TAG master
- SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src"
- BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build"
- CONFIGURE_COMMAND ""
- BUILD_COMMAND ""
- INSTALL_COMMAND ""
- TEST_COMMAND ""
+include (FetchContent)
+FetchContent_Declare(
+ googletest
+ GIT_REPOSITORY https://github.com/google/googletest.git
)
-```
-
-Existing build's `CMakeLists.txt`:
-
-```cmake
-# Download and unpack googletest at configure time
-configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
-execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
- RESULT_VARIABLE result
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
-if(result)
- message(FATAL_ERROR "CMake step for googletest failed: ${result}")
-endif()
-execute_process(COMMAND ${CMAKE_COMMAND} --build .
- RESULT_VARIABLE result
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
-if(result)
- message(FATAL_ERROR "Build step for googletest failed: ${result}")
-endif()
-
-# Prevent overriding the parent project's compiler/linker
-# settings on Windows
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-
-# Add googletest directly to our build. This defines
-# the gtest and gtest_main targets.
-add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
- ${CMAKE_CURRENT_BINARY_DIR}/googletest-build
- EXCLUDE_FROM_ALL)
+FetchContent_MakeAvailable(googletest)
# Now simply link against gtest or gtest_main as needed. Eg
add_executable(example example.cpp)
@@ -144,10 +104,8 @@ target_link_libraries(example gtest_main)
add_test(NAME example_test COMMAND example)
```
-Note that this approach requires CMake 2.8.2 or later due to its use of the
-`ExternalProject_Add()` command. The above technique is discussed in more detail
-in [this separate article](http://crascit.com/2015/07/25/cmake-gtest/) which
-also contains a link to a fully generalized implementation of the technique.
+Note that this approach requires CMake 3.14 or later due to its use of the
+`FetchContent_MakeAvailable()` command.
##### Visual Studio Dynamic vs Static Runtimes
OpenPOWER on IntegriCloud