Skip to content

Commit 465cf05

Browse files
committed
[CMake] Move to CMake's native FindGTest
- Remove own FindGTest, use the one from CMake. Starting from CMake 3.23, the GTest libraries have canonical names. - Replace uses of legacy targets like "gtest" in ROOT with canonical target names such as GTest::gtest or GTest::gtest_main. - Create ALIAS targets like in CMake 3.23 such as GTest::gtest_main. For CMake < 3.23, this will allow using the standard FindGTest with the modern names already in cmake 3.20.
1 parent 82cf414 commit 465cf05

File tree

5 files changed

+12
-87
lines changed

5 files changed

+12
-87
lines changed

cmake/modules/FindGTest.cmake

-81
This file was deleted.

cmake/modules/RootMacros.cmake

+1-4
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,10 @@ function(ROOT_ADD_GTEST test_suite)
17941794
# against. For example, tests in Core should link only against libCore. This could be tricky
17951795
# to implement because some ROOT components create more than one library.
17961796
ROOT_EXECUTABLE(${test_suite} ${source_files} LIBRARIES ${ARG_LIBRARIES})
1797-
target_link_libraries(${test_suite} PRIVATE gtest gtest_main gmock gmock_main)
1797+
target_link_libraries(${test_suite} PRIVATE GTest::gtest GTest::gmock GTest::gtest_main GTest::gmock_main)
17981798
if(TARGET ROOT::TestSupport)
17991799
target_link_libraries(${test_suite} PRIVATE ROOT::TestSupport)
18001800
else()
1801-
# Since we don't inherit the linkage against gtest from ROOT::TestSupport,
1802-
# we need to link against gtest here.
1803-
target_link_libraries(${test_suite} gtest)
18041801
message(WARNING "ROOT_ADD_GTEST(${test_suite} ...): The target ROOT::TestSupport is missing. It looks like the test is declared against a ROOT build that is configured with -Dtesting=OFF.
18051802
If this test sends warning or error messages, this will go unnoticed.")
18061803
endif()

cmake/modules/SearchInstalledSoftware.cmake

+9
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,15 @@ if (builtin_gtest)
19851985

19861986
endif()
19871987

1988+
# Starting from cmake 3.23, the GTest targets will have stable names.
1989+
# ROOT was updated to use those, but for older CMake versions, we have to declare the aliases:
1990+
foreach(LIBNAME gtest_main gmock_main gtest gmock)
1991+
if(NOT TARGET GTest::${LIBNAME} AND TARGET ${LIBNAME})
1992+
add_library(GTest::${LIBNAME} ALIAS ${LIBNAME})
1993+
endif()
1994+
endforeach()
1995+
1996+
#------------------------------------------------------------------------------------
19881997
if(webgui AND NOT builtin_openui5)
19891998
ROOT_CHECK_CONNECTION("builtin_openui5=ON")
19901999
if(NO_CONNECTION)

core/testsupport/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ target_include_directories(${libname} PUBLIC
1616
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc/>
1717
$<INSTALL_INTERFACE:./>
1818
)
19-
target_link_libraries(${libname} PUBLIC Core gtest)
19+
target_link_libraries(${libname} PRIVATE Core GTest::gtest)
2020

2121
# Installation of header and library:
2222
set_target_properties(${libname} PROPERTIES PUBLIC_HEADER inc/${header_dir}/TestSupport.hxx)

roofit/roofit/test/vectorisedPDFs/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL Intel)
1010
endif()
1111

1212
add_library(VectorisedPDFTests STATIC VectorisedPDFTests.cxx)
13-
target_link_libraries(VectorisedPDFTests PUBLIC gtest ROOT::Gpad ROOT::RooFitCore ROOT::RooFit)
13+
target_link_libraries(VectorisedPDFTests PUBLIC ROOT::Gpad ROOT::RooFitCore ROOT::RooFit GTest::gtest)
1414

1515
ROOT_ADD_GTEST(testCompatMode testCompatMode.cxx
1616
LIBRARIES VectorisedPDFTests)

0 commit comments

Comments
 (0)