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

Update gtest target names to CMake 3.23's canonical names. #1250

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 cmake/modules/RoottestMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,14 @@ function(ROOTTEST_ADD_UNITTEST_DIR)

add_executable(${binary} ${unittests_SRC})
target_include_directories(${binary} PRIVATE ${GTEST_INCLUDE_DIR})
target_link_libraries(${binary} gtest gtest_main ${libraries})
if(TARGET GTest::gtest AND TARGET GTest::gtest_main)
# Canonical target names since CMake 3.20, and also now used in ROOT:
target_link_libraries(${binary} GTest::gtest GTest::gtest_main ${libraries})
else()
# Fallback solution, which just names the libraries. Might lead to undefined symbol
# errors if the libraries are not found:
target_link_libraries(${binary} gtest gtest_main ${libraries})
endif()

if(MSVC AND DEFINED ROOT_SOURCE_DIR)
if(TARGET ROOTStaticSanitizerConfig)
Expand Down
6 changes: 3 additions & 3 deletions cmake/modules/SearchInstalledSoftwareRoottest.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(ExternalProject)

if(NOT TARGET gtest)
if(NOT TARGET GTest::gtest AND NOT TARGET gtest)

set(_gtest_byproduct_binary_dir
${CMAKE_CURRENT_BINARY_DIR}/googletest-prefix/src/googletest-build)
Expand Down Expand Up @@ -94,7 +94,7 @@ if(NOT TARGET gtest)
set_property(TARGET gmock PROPERTY IMPORTED_LOCATION ${_G_LIBRARY_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET gmock_main PROPERTY IMPORTED_LOCATION ${_G_LIBRARY_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX})

endif(NOT TARGET gtest)
endif()

#---Find timeout binary---------------------------------------------------------
if(NOT MSVC)
Expand All @@ -109,4 +109,4 @@ if(ROOT_mpi_FOUND)
message(FATAL_ERROR "MPI not found. Ensure that the installation of MPI is in the CMAKE_PREFIX_PATH."
" Example: CMAKE_PREFIX_PATH=<MPI_install_path> (e.g. \"/usr/local/mpich\")")
endif()
endif()
endif()