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.
CMakeLists.txt for gmock uses
gtest_SOURCE_DIR
for setting the include paths. When using fetch content with the name "GTest", the value ofgtest_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 fromgtest_SOURCE_DIR
plus the working paths from the target. For MSVC, gmock does not depend on gtest.fixed #4384