Skip to content

Commit 844e39c

Browse files
committed
msvc fix
1 parent b4b4b90 commit 844e39c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

third_party/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ if(NOT ${GTEST_FOUND})
3030
GIT_TAG v1.14.0
3131
OVERRIDE_FIND_PACKAGE)
3232
fetchcontent_makeavailable(GTest)
33+
34+
if(MSVC)
35+
# ------------------------------------------------------------------------------
36+
# gtest MSVC fix
37+
# ------------------------------------------------------------------------------
38+
# For some reason, googletest has include path issues when built with MSVC.
39+
# Specifically, this seems like some incorrect assumptions about include paths
40+
# inside the gmock project.
41+
# We can fix this by injecting the include paths here.
42+
function(fix_gtest_include TARGET)
43+
target_include_directories(
44+
${TARGET}
45+
PUBLIC $<BUILD_INTERFACE:${gtest_SOURCE_DIR}>
46+
$<BUILD_INTERFACE:${gtest_SOURCE_DIR}/include>
47+
$<BUILD_INTERFACE:${gtest_SOURCE_DIR}/googletest>
48+
$<BUILD_INTERFACE:${gtest_SOURCE_DIR}/googletest/include>
49+
$<INSTALL_INTERFACE:include/${TARGET}>)
50+
endfunction()
51+
set(gtest_erroneous_targets gmock gmock_main)
52+
foreach(target ${gtest_erroneous_targets})
53+
fix_gtest_include(${target})
54+
endforeach()
55+
endif()
3356
endif()
3457

3558
set(PREVIOUS_BUILD_TESTING ${BUILD_TESTING})

0 commit comments

Comments
 (0)