Welcome to OStack Knowledge Sharing 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...