Fix CMake documentation to prevent GoogleTest install
- Dominant language
- C++
- Stars
- 39.5k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
I added GoogleTest to my project by following the `Setup` section of the [Building with CMake](https://google.github.io/googletest/quickstart-cmake.html) documentation page in order to add unit tests. The issue is that the example does NOT disable installing GoogleTest. As a result I ended up polluting my system with headers and libs from GoogleTest when it is clearly not what I wanted to do...
Here is a proposed fix:
```
cmake_minimum_required(VERSION 3.14)
project(my_project)
# GoogleTest requires at least C++11
set(CMAKE_CXX_STANDARD 11)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# So that GoogleTest does not get installed with this project
option(INSTALL_GTEST "Enable installation of googletest." OFF)
FetchContent_MakeAvailable(googletest)
```
Contributor guide
Assessment
This issue has not been assessed yet.