google / google/googletest

Provide ALIAS targets to unify the usage

Open
#3,320 1 comment 0 reactions 1 assignee Claimed by @derekmauro View on GitHub
bug
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

If googletest is made part of the dependent's build tree (via FetchContent), then usage is different compared to using it from an install location (via find_package).

Ever since FetchContent has been introduced, the example has been using googletest. See here.

Usage differences in code:

# make googletest part of hte build tree
include(FetchContent)
FetchContent_Declare(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG master)
FetchContent_MakeAvailable(googletest)

# no ALIAS target, must use non-namespaced target instead
target_link_libraries(my_target PRIVATE gtest_main)

# ----

# use googletest from an install location
find_package(GTest REQUIRED CONFIG)

# the install(EXPORT) command namespaces the targets
target_link_libraries(my_target PRIVATE GTest::gtest_main)
I see from another issue (#3040 (comment)), that due to CMake 3.19 deprecating <2.8.12 there are also plans to set that as the minimum version and conveniently 2.8.12 is also the version that introduced the ALIAS form for add_library.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.