Search code examples
c++linuxwindowscmakegoogletest

How to set GoogleTest variables GTEST_LIBRARY GTEST_INCLUDE_DIR and GTEST_MAIN_LIBRARY to CMake on Windows?


There is a project that was developed for linux environment. Now I am trying to build this on windows using CMake.

I keep trying to build the project and always get this error:

CMake Error at C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)
Call Stack (most recent call first):
C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files(x86)/CMake/share/cmake-3.3/Modules/FindGTest.cmake:204 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
C:/Users/awy9/git/cmake_modules/modules/SigeoGTest.cmake:21 (find_package)  
C:/Users/awy9/git/cmake_modules/modules/SigeoInit.cmake:29 (include)  
CMakeLists.txt:12 (include)

How can I set these variables to work on this project now on Windows?


Solution

  • UPDATE

    @Tsyvarev helped me solving the first problem and I quote him:

    This is standard CMake message, when requested package(GTest in your case) is not found. You should install GTest before configuring your project. Or, if you already have installed it into non-standard location, pass this location via GTEST_ROOT variable: cmake -DGTEST_ROOT= ...

    As alternative for the passing variable to cmake, you can set environment variable: set GTEST_ROOT=

    This solved the problem with the value of GTEST_INCLUDE_DIR, but I still had these errors:

    CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.3/Modules/FindPackageH andleStandardArgs.cmake:148 (message): Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)

    SOLUTION

    I figured that on Windows environment some values are different from what the manuals say.

    After compiling Gtest, I got two libs: gtest.lib and gtest_main.lib Then, I set these filepath variables:

    GTEST_LIBRARY=C:\Users\awy9\Softwares\Gtest\gtest-1.7.0\Debug\gtest.lib GTEST_MAIN_LIBRARY=C:\Users\awy9\Softwares\Gtest\gtest-1.7.0\Debug\gtest_main.lib

    Now everything is working!

    Thank you