Skip to content

Commit 1117dfe

Browse files
committed
Add CMake interface library GTest::gtest_prod
Production code that contains `#include <gtest/gtest_prod.h>` should link against this interface library: it sets the correct include path for the compiler but does not instruct the linker to pull in any GoogleTest library code.
1 parent 29e40f5 commit 1117dfe

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

googletest/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ include_directories(${gtest_build_include_dirs})
116116
#
117117
# Defines the gtest & gtest_main libraries. User tests should link
118118
# with one of them.
119+
# Production code that includes <gtest/gtest_prod.h> should link with the
120+
# interface library gtest_prod.
119121

120122
# Google Test libraries. We build them using more strict warnings than what
121123
# are used for other targets, to ensure that gtest can be compiled by a user
122124
# aggressive about warnings.
125+
add_library_and_alias(gtest_prod INTERFACE)
126+
set_target_properties(gtest_prod PROPERTIES VERSION ${GOOGLETEST_VERSION})
123127
cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
124128
set_target_properties(gtest PROPERTIES VERSION ${GOOGLETEST_VERSION})
125129
if(GTEST_HAS_ABSL)
@@ -141,6 +145,9 @@ endif()
141145
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
142146
set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
143147
string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
148+
target_include_directories(gtest_prod SYSTEM INTERFACE
149+
"$<BUILD_INTERFACE:${dirs}>"
150+
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
144151
target_include_directories(gtest SYSTEM INTERFACE
145152
"$<BUILD_INTERFACE:${dirs}>"
146153
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
@@ -155,7 +162,7 @@ target_link_libraries(gtest_main PUBLIC gtest)
155162
########################################################################
156163
#
157164
# Install rules.
158-
install_project(gtest gtest_main)
165+
install_project(gtest_prod gtest gtest_main)
159166

160167
########################################################################
161168
#

googletest/cmake/gtest_prod.pc.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
2+
3+
Name: gtest_prod
4+
Description: GoogleTest (header for production code)
5+
Version: @PROJECT_VERSION@
6+
URL: https://github.com/google/googletest
7+
Cflags: -I${includedir}

0 commit comments

Comments
 (0)