Why does CMake not find GTest (Google Test)?


There is a ready project. In one of the cmake-files there is a source code:

find_package(GTest REQUIRED) if (NOT GTest_FOUND) message(FATAL_ERROR "Cannot find Google Test Framework!") endif()

Gives an error: "Cannot find Google Test Framework!"

How to fix error?


The FindGTest.cmake file uses the environment variable GTEST_ROOT. You can add this variable to your system or just add it to your CMakeLists.txt file:

set(GTEST_ROOT "c:/path/to/gtest/root" CACHE PATH "path to gtest").

This should solve your problem. It is of course possible to completely add gtest to a project (like Luis Miglietti suggested), but thats maybe not what you want to do as a first try.


While CMake provides a <a href="https://github.com/Kitware/CMake/blob/master/Modules/FindGTest.cmake" rel="nofollow">FindGTest.cmake</a> module since 2009...

I prefer to incorporate googletest in your CMake project like explaining in the googletest documentation.<br /><a href="https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project" rel="nofollow">https://github.com/google/googletest/tree/master/googletest#incorporating-into-an-existing-cmake-project</a>

Note: a more detailed explanation <a href="http://crascit.com/2015/07/25/cmake-gtest/" rel="nofollow">http://crascit.com/2015/07/25/cmake-gtest/</a>


This could be useful for you so you don't have to depend on a local google test install, this should work independently if you have google test installed in your machine

You can add this to your cmake file (you should take care of the proper linking / include depending on your project structure)

This will download google test, configure the installation and build it in <strong>vendor/gtm/gtest</strong> (you could always change this) inside your main build folder. Then you can link <strong>gtest</strong> to an executable so you can run your tests from there

include(ExternalProject) find_package(Git REQUIRED) # Build googletest ExternalProject_Add( googletest PREFIX "vendor/gtm" GIT_REPOSITORY "https://github.com/google/googletest.git" GIT_TAG release-1.8.0 TIMEOUT 10 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" UPDATE_COMMAND "" ) # Build gtest ExternalProject_Add( gtest_src PREFIX "vendor/gtm" SOURCE_DIR "vendor/gtm/src/googletest/googletest" INSTALL_DIR "vendor/gtm/gtest" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/vendor/gtm/gtest -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} DOWNLOAD_COMMAND "" UPDATE_COMMAND "" ) # Prepare gtest ExternalProject_Get_Property(gtest_src install_dir) set(GTEST_INCLUDE_DIR ${install_dir}/include) set(GTEST_LIBRARY_PATH ${install_dir}/lib/libgtest.a) file(MAKE_DIRECTORY ${GTEST_INCLUDE_DIR}) add_library(gtest STATIC IMPORTED) set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH}) set_property(TARGET gtest APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR}) add_dependencies(gtest_src googletest) add_dependencies(gtest gtest_src)

Then you can link <strong>gtest</strong> to an executable with something like

add_executable(tester test/tester.cc) target_link_libraries(tester gtest) enable_testing() add_test(<library> tester)


  • French characters not displaying correctly in PHP mail
  • Extract Url From a String
  • Extract value form XML
  • covariance matrix by group
  • How to fetch data from file using ajax on clicking table rows
  • Xamarin Forms/Prism Custom Popup
  • Roslyn Rename variable const in Majusucle
  • How to enable httpsrc plug-in in my gstreamer?
  • Reformatting scraped selenium table
  • WPF DataGrid - Can I decorate my POCOs with attributes to have custom column names?
  • Regex substring one mismatch in any location of string
  • Lua - How to find a substring with 1 or 2 characters discrepancy
  • plot phylogenetic logistic regression with binary response variable
  • Is Android capable of managing microphone/input volume?
  • Add Special Case to Power BI Query (M)
  • Plotting Route with Multiple Points in iOS
  • SSIS Designer is running VERY slowly
  • Mixing WebForms and MVC: What should I do with the MasterPage?
  • JQuery .html() remove line break on IE 8
  • How to get links to open in the native browser in iOS Meteor apps?
  • Android device acting as an accessory
  • Application level floating views with navigation in Android
  • How to generate and display a QR Code in ionic 2
  • Seeking advice on Jetty HttpClient Hang
  • Ajax Loaded meta Tags
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • RectangularRangeIndicator format like triangular using dojo
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • Java applet as stand-alone Windows application?
  • Cross-Platform Protobuf Serialization
  • Shallow update not allowed (git > 1.9)
  • Jquery - Jquery Wysiwyg return html as a string
  • Google cloud sdk not working when python points python3
  • How do I rollback to a specific git commit
  • Revoking OAuth Access Token Results in 404 Not Found
  • SQL merge duplicate rows and join values that are different
  • using HTMLImports.whenReady not working in chrome
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Reading document lines to the user (python)
  • Android Heatmap on canvas or ImageView