google / google/googletest

[FR]: Export a header-only library `GTest::gtest_prod` via CMake

Open
#4,673 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
39.6k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

### Does the feature exist in the most recent commit?

The Bazel infrastructure already provides a dedicated `gtest_prod` library, which was introduced by commit 105579a6e43908bc88a289d309492eda8be896be.

Unfortunately, the same does not yet exist for CMake.

### Why do we need this feature?

### User story
As a C++ application developer using CMake,
I want GoogleTest's CMake config to provide a dedicated header-only library for `gtest_prod.h`,
so that I can use the `FRIEND_TEST()` macro in my application code without having to link against the static `GTest::gtest` library.
Only my unit tests should link against `GTest::gtest`.

### Describe the proposal.

The implementation should look roughly like this:
* In `googletest/CMakeLists.txt`, add a library named `gtest_prod` of type `INTERFACE`.
* Include `gtest_prod` in the list of targets to be installed.
* Add a pkgconf template `googletest/cmake/gtest_prod.pc.in` that adds the correct include-path to the compiler flags.

This will cause a new target, `GTest::gtest_prod`, to be added to `GTestTargets.cmake`.

When a user application subsequently links against `GTest::gtest_prod` in its `CMakeLists.txt`, the correct include-path will be set. *The user application will not pull in the static gtest library*.

### Is the feature specific to an operating system, compiler, or build system version?

No; this is a platform-agnostic feature.
To the best of my knowledge, it does not pose any specific requirements on the CMake version.

Contributor guide

Open the contributing guide

Research direction

Start in googletest/CMakeLists.txt and compare the existing Bazel gtest_prod infrastructure with the CMake library targets. Add the requested target and installation entry, then create googletest/cmake/gtest_prod.pc.in with the correct include path. Verify that the installed CMake package exposes GTest::gtest_prod and that linking it does not pull in the static gtest library.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.