Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake interface library GTest::gtest_prod #4680

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ include_directories(${gtest_build_include_dirs})
#
# Defines the gtest & gtest_main libraries. User tests should link
# with one of them.
# Production code that includes <gtest/gtest_prod.h> should link with the
# interface library gtest_prod.

# Google Test libraries. We build them using more strict warnings than what
# are used for other targets, to ensure that gtest can be compiled by a user
# aggressive about warnings.
add_library_and_alias(gtest_prod INTERFACE)
set_target_properties(gtest_prod PROPERTIES VERSION ${GOOGLETEST_VERSION})
cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
set_target_properties(gtest PROPERTIES VERSION ${GOOGLETEST_VERSION})
if(GTEST_HAS_ABSL)
Expand All @@ -141,6 +145,9 @@ endif()
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
target_include_directories(gtest_prod SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gtest SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
Expand All @@ -155,7 +162,7 @@ target_link_libraries(gtest_main PUBLIC gtest)
########################################################################
#
# Install rules.
install_project(gtest gtest_main)
install_project(gtest_prod gtest gtest_main)

########################################################################
#
Expand Down
7 changes: 7 additions & 0 deletions googletest/cmake/gtest_prod.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: gtest_prod
Description: GoogleTest (header for production code)
Version: @PROJECT_VERSION@
URL: https://github.com/google/googletest
Cflags: -I${includedir}
8 changes: 6 additions & 2 deletions googletest/cmake/internal_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ macro(config_compiler_and_linker)
set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
endmacro()

function(add_library_and_alias name type)
add_library(${name} ${type} ${ARGN})
add_library(${cmake_package_name}::${name} ALIAS ${name})
endfunction()

# Defines the gtest & gtest_main libraries. User tests should link
# with one of them.
function(cxx_library_with_type name type cxx_flags)
# type can be either STATIC or SHARED to denote a static or shared library.
# ARGN refers to additional arguments after 'cxx_flags'.
add_library(${name} ${type} ${ARGN})
add_library(${cmake_package_name}::${name} ALIAS ${name})
add_library_and_alias(${name} ${type} ${ARGN})
set_target_properties(${name}
PROPERTIES
COMPILE_FLAGS "${cxx_flags}")
Expand Down