FindGTest¶
Locate the Google C++ Testing Framework.
New in version 3.20: Upstream GTestConfig.cmake is used if possible.
Imported targets¶
New in version 3.20: This module defines the following IMPORTED targets:
- GTest::gtest
- The Google Test - gtestlibrary, if found; adds Thread::Thread automatically
- GTest::gtest_main
- The Google Test - gtest_mainlibrary, if found
New in version 3.23.
- GTest::gmock
- The Google Mock - gmocklibrary, if found; adds Thread::Thread automatically
- GTest::gmock_main
- The Google Mock - gmock_mainlibrary, if found
Deprecated since version 3.20: For backwards compatibility, this module defines additionally the
following deprecated IMPORTED targets (available since 3.5):
- GTest::GTest
- The Google Test - gtestlibrary, if found; adds Thread::Thread automatically
- GTest::Main
- The Google Test - gtest_mainlibrary, if found
Result variables¶
This module will set the following variables in your project:
- GTest_FOUND
- Found the Google Testing framework 
- GTEST_INCLUDE_DIRS
- the directory containing the Google Test headers 
The library variables below are set as normal variables. These contain debug/optimized keywords when a debugging library is found.
- GTEST_LIBRARIES
- The Google Test - gtestlibrary; note it also requires linking with an appropriate thread library
- GTEST_MAIN_LIBRARIES
- The Google Test - gtest_mainlibrary
- GTEST_BOTH_LIBRARIES
- Both - gtestand- gtest_main
Cache variables¶
The following cache variables may also be set:
- GTEST_ROOT
- The root directory of the Google Test installation (may also be set as an environment variable) 
- GTEST_MSVC_SEARCH
- If compiling with MSVC, this variable can be set to - MTor- MD(the default) to enable searching a GTest build tree
Example usage¶
enable_testing()
find_package(GTest REQUIRED)
add_executable(foo foo.cc)
target_link_libraries(foo GTest::gtest GTest::gtest_main)
add_test(AllTestsInFoo foo)
Deeper integration with CTest¶
See GoogleTest for information on the gtest_add_tests()
and gtest_discover_tests() commands.
Changed in version 3.9: Previous CMake versions defined gtest_add_tests() macro in this
module.
