Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

cmake - could not find GTest but googletest was fetched

I'm using googletest in my project. To add it I used the following code to my CMake

include(FetchContent)

FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG        release-1.8.0
)

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
  FetchContent_Populate(googletest)
  add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
endif()

The problem is whenever I build my project I get a following error

Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)

This is caused by this line of code in one of the tests

find_package(GTest REQUIRED)

I'm not the owner of the test so I can't change this line. I also can't install googletest on the machine where we run our tests. The only option is to use it as a dependency. I'm not really sure how to fix this problem.

Based on the reading of this page, I tried changing module path

set(CMAKE_MODULE_PATH ${googletest_BINARY_DIR}/googletest/generated)

But it didn't work.

Has anyone encountered a problem like that? How did you solve it?

question from:https://stackoverflow.com/questions/65881615/could-not-find-gtest-but-googletest-was-fetched

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...