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 · 4 comments
Open

Add CMake aliases #2429

lukasm91 opened this issue Aug 24, 2019 · 4 comments

Comments

@lukasm91
Copy link
Contributor

@lukasm91 lukasm91 commented Aug 24, 2019

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
Member

@gennadiycivil gennadiycivil commented Oct 24, 2019

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

@piotrzarycki piotrzarycki commented Sep 7, 2020

can i take this?

@Mohammadmahdiamn
Copy link

@Mohammadmahdiamn Mohammadmahdiamn commented Sep 7, 2020

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

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant