GTest: How to use Google Test in Cmake project?
GTest: How to use Google Test in Cmake project?
# Example
## CMake 3.0
```cmake
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(foo foo.cc)
target_link_libraries(foo ${GTEST_BOTH_LIBRARIES})
add_test(AllTestsInFoo foo)
```
## CMake 3.10
```cmake
enable_testing()
find_package(GTest REQUIRED)
add_executable(foo foo.cc)
target_link_libraries(foo GTest::GTest GTest::Main)
add_test(AllTestsInFoo foo)
```
## Installation using apt-repo
```sh
sudo apt-get install libgtest-dev
```
# References
- https://cmake.org/cmake/help/v3.10/module/FindGTest.html
![yubao_blog_cover](https://raw.githubusercontent.com/yubaoliu/assets/image/yubao_blog_cover.png)
No comments