为什么CMake找不到GTest(Google测试)? [英] Why does CMake not find GTest (Google Test)?

查看:447
本文介绍了为什么CMake找不到GTest(Google测试)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个准备好的项目。在其中一个cmake文件中,有一个源代码:

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()

给出错误:找不到Google测试框架!

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

如何修复错误?

推荐答案

FindGTest.cmake 文件使用环境变量 GTEST_ROOT
您可以将此变量添加到系统中,也可以仅将其添加到 CMakeLists.txt 文件中:

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"). 

这应该可以解决您的问题。当然可以将gtest完全添加到项目中(就像Luis Miglietti所建议的那样),但是那也许不是您第一次尝试时想要做的。

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.

这篇关于为什么CMake找不到GTest(Google测试)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆