### Navigation

- index
- next |
- previous |
- CMake »
- 3.2.0 Documentation »
- cmake-modules(7) »

# FindGTest

Locate the Google C++ Testing Framework.

Defines the following variables:

    GTEST_FOUND - Found the Google Testing framework
    GTEST_INCLUDE_DIRS - Include directories

Also defines the library variables below as normal variables. These contain debug/optimized keywords when a debugging library is found.

    GTEST_BOTH_LIBRARIES - Both libgtest & libgtest-main
    GTEST_LIBRARIES - libgtest
    GTEST_MAIN_LIBRARIES - libgtest-main

Accepts the following variables as input:

    GTEST_ROOT - (as a CMake or environment variable)
                 The root directory of the gtest install prefix

    GTEST_MSVC_SEARCH - If compiling with MSVC, this variable can be set to
                        "MD" or "MT" to enable searching a GTest build tree
                        (defaults: "MD")

Example Usage:

    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)

If you would like each Google test to show up in CTest as a test you may use the following macro. NOTE: It will slow down your tests by running an executable for each test and test fixture. You will also have to rerun CMake after adding or removing tests or test fixtures.

GTEST_ADD_TESTS(executable extra_args ARGN)

    executable = The path to the test executable
    extra_args = Pass a list of extra arguments to be passed to
                 executable enclosed in quotes (or "" for none)
    ARGN =       A list of source files to search for tests & test
                 fixtures. Or AUTO to find them from executable target.

    Example:
       set(FooTestArgs --foo 1 --bar 2)
       add_executable(FooTest FooUnitTest.cc)
       GTEST_ADD_TESTS(FooTest "${FooTestArgs}" AUTO)

### Navigation

- index
- next |
- previous |
- CMake »
- 3.2.0 Documentation »
- cmake-modules(7) »