googletest icon indicating copy to clipboard operation
googletest copied to clipboard

Add CMake aliases

Open lukasm91 opened this issue 6 years ago • 9 comments

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.

lukasm91 avatar Aug 24 '19 12:08 lukasm91

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.

gennadiycivil avatar Oct 24 '19 03:10 gennadiycivil

My 2 cents,

GTest namespace

First this CMake install NAMESPACE (GTest) is defined here: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/CMakeLists.txt#L98 then used here: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/CMakeLists.txt#L105

To use this variable ${cmake_package_name}, it should be defined somewhere else IMHO... Edit: should be defined before including internal_utils.cmake: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/CMakeLists.txt#L90-L91

gtest and gtest_main targets

these libraries are defined later using a custom function cxx_library: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/CMakeLists.txt#L128-L129

which call cxx_library_with_type: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/cmake/internal_utils.cmake#L197-L203

which call the add_library: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/cmake/internal_utils.cmake#L147-L150 so we should try to add the add_library(... ALIAS ...) to this function IMHO

gmock and gmock_main targets

pretty the same story: https://github.com/google/googletest/blob/7b1cf6dd5fbe0c22c5e638fce8caf7f0f5c1abbf/googlemock/CMakeLists.txt#L89-L107

note gmock CMakeLists.txt include the gtest one https://github.com/google/googletest/blob/7b1cf6dd5fbe0c22c5e638fce8caf7f0f5c1abbf/googlemock/CMakeLists.txt#L51-L55

note: gmock install rules seems to use an other macro/function: https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googlemock/CMakeLists.txt#L121 defined here (EDIT: just adding targets to the googletest target): https://github.com/google/googletest/blob/306f3754a71d6d1ac644681d3544d06744914228/googletest/cmake/internal_utils.cmake#L327 (ed notice the of variable ${targets_export_name})

Mizux avatar Jan 09 '20 21:01 Mizux

can i take this?

piotrzarycki avatar Sep 07 '20 13:09 piotrzarycki

Do whatever you think is best.

On Mon, 7 Sep 2020, 17:57 Piotr Zarycki, [email protected] wrote:

can i take this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/googletest/issues/2429#issuecomment-688324891, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN5J4ZX3WG3U3OE7TXYD323SETNSHANCNFSM4IPGCP7A .

Mohammadmahdiamn avatar Sep 07 '20 13:09 Mohammadmahdiamn

Is there any progress on this?

AlexanderStein avatar Mar 10 '21 09:03 AlexanderStein

I think there is a pull request(https://github.com/google/googletest/pull/3155) for the same issue

ghost avatar Mar 11 '21 04:03 ghost

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

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

Mizux avatar Dec 27 '21 08:12 Mizux

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

kunjshukla avatar Jul 03 '23 13:07 kunjshukla

I think the issue is resolved.

LND694 avatar Sep 19 '23 14:09 LND694