microsoft/GSL

Support find_package for GTest to avoid redundant downloads

开放

#1,256 创建于 2026年7月27日

 (2 条评论) (0 个反应) (0 位负责人)C++ (721 个派生)batch import
Help WantedType: Infra

仓库指标

星标
 (5,695 个星标)
PR 合并指标
 (平均合并 8天) (30 天内合并 1 个 PR)

描述

Description

In tests/CMakeLists.txt, the current logic uses pkg_search_module(GTestMain gtest_main) to detect a pre-installed GTest. If not found, it falls back to downloading GTest source via Git.

However, pkg_search_module relies on pkg-config (.pc files), which is not commonly available or generated by package managers like vcpkg on Windows. vcpkg provides CMake config files (e.g., GTestConfig.cmake) instead, which are meant to be used with find_package().

As a result, even when GTest is already installed via vcpkg, pkg_search_module fails to find it, and the build unnecessarily downloads and compiles GTest from source.

Suggestion

Add find_package(GTest) as an additional detection method before falling back to the download step. For example:

find_package(GTest QUIET)
if (NOT GTest_FOUND)
    pkg_search_module(GTestMain gtest_main)
endif()

if (NOT GTest_FOUND AND NOT GTestMain_FOUND)
    # Fall back to downloading GTest via Git
    ...
endif()

This would allow users with GTest installed via vcpkg (or other CMake-config-based package managers) to use their existing installation without redundant downloads.

贡献者指南