Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

danfabo
Copy link
Contributor

@danfabo danfabo commented Feb 11, 2024

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

The global variable gtest_SOURCE_DIR is replaced by CMake when fetch-content is used with the name "GTest" and points to the root directory. The include directories from the gtest target are always valid.
@derekmauro derekmauro self-assigned this Feb 12, 2024
@copybara-service copybara-service bot merged commit 926f681 into google:main Mar 4, 2024
6 of 7 checks passed
@danfabo danfabo deleted the fix-fetch-content-uses-gtest branch March 5, 2024 00:47
@danfabo danfabo restored the fix-fetch-content-uses-gtest branch March 5, 2024 00:48
@danfabo danfabo deleted the fix-fetch-content-uses-gtest branch March 5, 2024 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: CMake FetchContent_* does not work with GTest as dependency name on Windows
3 participants