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 aliases #2429

Open
lukasm91 opened this issue Aug 24, 2019 · 9 comments
Open

Add CMake aliases #2429

lukasm91 opened this issue Aug 24, 2019 · 9 comments

Comments

@lukasm91
Copy link
Contributor

GTest exports the following targets:

  • GTest::gtest
  • GTest::gtest_main
  • GTest::gmock
  • GTest::gmock_main

This targets should also be available when adding gtest with add_subdirectory (or FetchContent), because this should behave the same way as adding GTest with find_package. So somewhere, we should add the aliases to these targets, i.e.

add_library(GTest::gtest ALIAS gtest)
add_library(GTest::gtest_main ALIAS gtest_main)
add_library(GTest::gmock ALIAS gmock)
add_library(GTest::gmock_main ALIAS gmock_main)

I am not sure, where I should add these aliases.

@gennadiycivil
Copy link
Contributor

Anything related to CMake is community supported. We do not use it internally and we are not in position to check. In general the maintainers would look for community consensus.

@Mizux
Copy link

Mizux commented Jan 9, 2020

My 2 cents,

GTest namespace

First this CMake install NAMESPACE (GTest) is defined here:

set(cmake_package_name GTest)

then used here:
NAMESPACE ${cmake_package_name}::

To use this variable ${cmake_package_name}, it should be defined somewhere else IMHO...
Edit: should be defined before including internal_utils.cmake:

# Define helper functions and macros used by Google Test.
include(cmake/internal_utils.cmake)

gtest and gtest_main targets

these libraries are defined later using a custom function cxx_library:

cxx_library(gtest "${cxx_strict}" src/gtest-all.cc)
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)

which call cxx_library_with_type:

function(cxx_shared_library name cxx_flags)
cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN})
endfunction()
function(cxx_library name cxx_flags)
cxx_library_with_type(${name} "" "${cxx_flags}" ${ARGN})
endfunction()

which call the add_library:

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})

so we should try to add the add_library(... ALIAS ...) to this function IMHO

gmock and gmock_main targets

pretty the same story:

if (MSVC)
cxx_library(gmock
"${cxx_strict}"
"${gtest_dir}/src/gtest-all.cc"
src/gmock-all.cc)
cxx_library(gmock_main
"${cxx_strict}"
"${gtest_dir}/src/gtest-all.cc"
src/gmock-all.cc
src/gmock_main.cc)
else()
cxx_library(gmock "${cxx_strict}" src/gmock-all.cc)
target_link_libraries(gmock PUBLIC gtest)
set_target_properties(gmock PROPERTIES VERSION ${GOOGLETEST_VERSION})
cxx_library(gmock_main "${cxx_strict}" src/gmock_main.cc)
target_link_libraries(gmock_main PUBLIC gmock)
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
endif()

note gmock CMakeLists.txt include the gtest one

# Instructs CMake to process Google Test's CMakeLists.txt and add its
# targets to the current scope. We are placing Google Test's binary
# directory in a subdirectory of our own as VC compilation may break
# if they are the same (the default).
add_subdirectory("${gtest_dir}" "${gmock_BINARY_DIR}/${gtest_dir}")

note: gmock install rules seems to use an other macro/function:

install_project(gmock gmock_main)

defined here (EDIT: just adding targets to the googletest target):
function(install_project)

(ed notice the of variable ${targets_export_name})

@piotrzarycki
Copy link

can i take this?

@Mohammadmahdiamn
Copy link

Mohammadmahdiamn commented Sep 7, 2020 via email

@AlexanderStein
Copy link

Is there any progress on this?

@ghost
Copy link

ghost commented Mar 11, 2021

I think there is a pull request(#3155) for the same issue

@Mizux
Copy link

Mizux commented Dec 27, 2021

@derekmauro or @gennadiycivil please close this (since #3155 is merged).

ps: I don't have right to this repo to close it myself...

@kunjshukla
Copy link

hey, I would like to contribute to this issue. Please assign this to me.

@LND694
Copy link

LND694 commented Sep 19, 2023

I think the issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants