google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
33.7k stars 9.98k forks source link

[#4384] CMake FetchContent_* does not work with GTest as dependency name on Windows #4466

Closed danfabo closed 4 months ago

danfabo commented 4 months ago

CMakeLists.txt for gmock uses gtest_SOURCE_DIR for setting the include paths. When using fetch content with the name "GTest", the value of gtest_SOURCE_DIR is updated to the repository root instead of the googletest subdirectory. As a result, gmock will fail to compile due to invalid include paths.

This can be fixed by not relying on gtest_SOURCE_DIR but reading the include directories from the gtest target.

It used to work for other compilers because gmock depends on gtest (using target_link_libraries). So gmock had the broken include paths from gtest_SOURCE_DIR plus the working paths from the target. For MSVC, gmock does not depend on gtest.

fixed #4384