microsoft / microsoft/GSL

Support find_package for GTest to avoid redundant downloads

Open Beginner friendly
#1,256 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Help Wanted Type: Infra
Dominant language
C++
Stars
6.7k
Forks
772
Avg merge
4d 23h
Merged PRs (30d)
9

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tests/CMakeLists.txt and read the existing pkg_search_module(GTestMain gtest_main) detection and Git fallback. Add the CMake-config-based detection before the fallback, then verify that an installed GTest is used and that downloading remains available when neither detection method succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, testing-qa
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.