Locate the Google C++ Testing Framework.
Added in version 3.20: Upstream GTestConfig.cmake is used if possible.
Added in version 3.20: This module defines the following IMPORTED targets:
GTest::gtestThe Google Test gtest library, if found; adds Thread::Thread
automatically
GTest::gtest_mainThe Google Test gtest_main library, if found
Added in version 3.23.
GTest::gmockThe Google Mock gmock library, if found; adds Thread::Thread
automatically
GTest::gmock_mainThe Google Mock gmock_main library, if found
Deprecated since version 3.20: For backwards compatibility, this module defines additionally the
following deprecated IMPORTED targets (available since 3.5):
GTest::GTestThe Google Test gtest library, if found; adds Thread::Thread
automatically
GTest::MainThe Google Test gtest_main library, if found
This module will set the following variables in your project:
GTest_FOUNDFound the Google Testing framework
GTEST_INCLUDE_DIRSthe 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_LIBRARIESThe Google Test gtest library; note it also requires linking
with an appropriate thread library
GTEST_MAIN_LIBRARIESThe Google Test gtest_main library
GTEST_BOTH_LIBRARIESBoth gtest and gtest_main
The following cache variables may also be set:
GTEST_ROOTThe root directory of the Google Test installation (may also be set as an environment variable)
GTEST_MSVC_SEARCHIf compiling with MSVC, this variable can be set to MT or
MD (the default) to enable searching a GTest build tree
enable_testing()
find_package(GTest REQUIRED)
add_executable(foo foo.cc)
target_link_libraries(foo GTest::gtest GTest::gtest_main)
add_test(AllTestsInFoo foo)
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.