Bruce Trask
Bruce Trask

Reputation: 63

GTEST_INCLUDE_DIRS not set after find_package(GTest REQUIRED)

I am running CMake 3.20.2 on Mac Catalina. I have built gtest and installed it on the system with sudo make install. gtest exists in /usr/include. But when I run cmake lines: find_package(GTest REQUIRED) GTEST_FOUND is true but GTEST_INCLUDE_DIRS is not set. Under what circumstances doe GTEST_INCLUDE_DIRS either get set or not by the call to find_package? The CMake docs say these should be set as result variables but only one seems to be set.

Upvotes: 5

Views: 1147

Answers (2)

Alexander Belyi
Alexander Belyi

Reputation: 21

Apparently, the OP has found the answer here.
In summary, it is a backward compatibility issue, which seems to happen only on Mac. The GTEST_INCLUDE_DIRS variable is not set correctly after calling find_package(GTest REQUIRED). If you can edit your CMakeLists.txt, the recommended modern way is to use target_link_libraries(GTest::gtest GTest::gtest_main) instead of include_directories(${GTEST_INCLUDE_DIRS}).

Upvotes: 0

why sir
why sir

Reputation: 1

In your CmakeLists.txt, add include_directories("GTEST_INCLUDE_DIRS")

Upvotes: 0

Related Questions