FindGTest¶
Locate the Google C++ Testing Framework.
Imported targets¶
This module defines the following IMPORTED targets:
GTest::GTestThe Google Test
gtestlibrary, if found; adds Thread::Thread automaticallyGTest::MainThe Google Test
gtest_mainlibrary, if found
Result variables¶
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
gtestlibrary; note it also requires linking with an appropriate thread libraryGTEST_MAIN_LIBRARIESThe Google Test
gtest_mainlibraryGTEST_BOTH_LIBRARIESBoth
gtestandgtest_main
Cache variables¶
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
MDorMT(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::Main)
add_test(AllTestsInFoo foo)
Deeper integration with CTest¶
If you would like each Google test to show up in CTest as a test you may use the following macro:
GTEST_ADD_TESTS(executable extra_args files...)
executablethe path to the test executable
extra_argsa list of extra arguments to be passed to executable enclosed in quotes (or
""for none)files...a list of source files to search for tests and test fixtures. Or
AUTOto find them from executable target
However, note that this macro will slow down your tests by running an executable for each test and test fixture.
Example usage:
set(FooTestArgs --foo 1 --bar 2)
add_executable(FooTest FooUnitTest.cc)
GTEST_ADD_TESTS(FooTest "${FooTestArgs}" AUTO)