Skip to content

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

Open
@sicherha

Description

@sicherha

Does the feature exist in the most recent commit?

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

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions