Skip to content

Commit af04fd2

Browse files
authored
[gtest] fix cppinterop testing with builtin_gtest (#22469)
When builtin_gtest is used, one should export defined include paths to PARENT_SCOPE And like with many other builtins, instead of silent switch to builtin version of package - produce for gtest error message and force user explicitly specify `-Dbuiltin_gtest=ON` Add extra argument to ROOT_FIND_REQUIRED_DEP macro to specify minimal version.
1 parent a776301 commit af04fd2

2 files changed

Lines changed: 24 additions & 30 deletions

File tree

builtins/gtest/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@ set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${_G_LIBRARY_PATH}/${CMAKE_
115115
set_property(TARGET gtest_main PROPERTY IMPORTED_LOCATION ${_G_LIBRARY_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX})
116116
set_property(TARGET gmock PROPERTY IMPORTED_LOCATION ${_G_LIBRARY_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}gmock${CMAKE_STATIC_LIBRARY_SUFFIX})
117117
set_property(TARGET gmock_main PROPERTY IMPORTED_LOCATION ${_G_LIBRARY_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}gmock_main${CMAKE_STATIC_LIBRARY_SUFFIX})
118+
119+
# The following variables are still needed publicly by CppInterop Testing since it does not use target-based CMake
120+
set(GTEST_INCLUDE_DIR ${GTEST_INCLUDE_DIR} PARENT_SCOPE)
121+
set(GMOCK_INCLUDE_DIR ${GMOCK_INCLUDE_DIR} PARENT_SCOPE)

cmake/modules/SearchInstalledSoftware.cmake

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ string(REPLACE "-Werror " "" ROOT_EXTERNAL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
8484
#--- Search for packages that are absolutely necessary--------------------------
8585

8686
#----------------------------------------------------------------------------
87-
# ROOT_FIND_REQUIRED_DEP(PACKAGE_NAME BUILTIN_CONFIG_OPTION)
87+
# ROOT_FIND_REQUIRED_DEP(PACKAGE_NAME BUILTIN_CONFIG_OPTION [MIN_REQUIRED_VERSION])
8888
# Search for a required dependency, unless it's meant to be a built-in.
8989
# A list of all missing required packages will be printed in case they could
9090
# not be found.
9191
macro(ROOT_FIND_REQUIRED_DEP PACKAGE_NAME BUILTIN_CONFIG_OPTION)
9292
if(NOT ${BUILTIN_CONFIG_OPTION})
93-
find_package(${PACKAGE_NAME})
93+
set(MIN_REQUIRED_VERSION "")
94+
if (${ARGC} GREATER 2) # ARGC: extra arguments + named ones
95+
set(MIN_REQUIRED_VERSION ${ARGV2}) # ARGV0 and ARGV1 are named required args
96+
endif()
97+
find_package(${PACKAGE_NAME} ${MIN_REQUIRED_VERSION})
9498
if(NOT ${PACKAGE_NAME}_FOUND)
9599
message(SEND_ERROR "The required package ${PACKAGE_NAME} was not found. "
96100
"Please install it in the system (preferred), set the corresponding CMake search variable, "
@@ -125,6 +129,9 @@ ROOT_FIND_REQUIRED_DEP(LibLZMA builtin_lzma)
125129
ROOT_FIND_REQUIRED_DEP(ZLIB builtin_zlib)
126130
ROOT_FIND_REQUIRED_DEP(ZSTD builtin_zstd)
127131
ROOT_FIND_REQUIRED_DEP(xxHash builtin_xxhash)
132+
if (testing OR testsupport)
133+
ROOT_FIND_REQUIRED_DEP(GTest builtin_gtest 1.10)
134+
endif()
128135

129136
if(NOT "${MISSING_PACKAGES}" STREQUAL "")
130137
message(FATAL_ERROR "The following packages need to be installed or enabled to build ROOT: ${MISSING_PACKAGES}")
@@ -1246,46 +1253,29 @@ endif (roofit_multiprocess)
12461253

12471254
#---Check for googletest---------------------------------------------------------------
12481255
if (testing OR testsupport)
1249-
if (NOT builtin_gtest)
1250-
if(fail-on-missing)
1251-
find_package(GTest 1.10 REQUIRED)
1252-
else()
1253-
find_package(GTest 1.10)
1254-
if(NOT GTEST_FOUND)
1255-
ROOT_CHECK_CONNECTION("testing=OFF")
1256-
if(NO_CONNECTION)
1257-
message(STATUS "GTest not found, and no internet connection. Disabling the 'testing' and 'testsupport' options.")
1258-
set(testing OFF CACHE BOOL "Disabled because testing requested and GTest not found (${builtin_gtest_description}) and there is no internet connection" FORCE)
1259-
set(testsupport OFF CACHE BOOL "Disabled because testsupport requested and GTest not found (${builtin_gtest_description}) and there is no internet connection" FORCE)
1260-
else()
1261-
message(STATUS "GTest not found, switching ON 'builtin_gtest' option.")
1262-
set(builtin_gtest ON CACHE BOOL "Enabled because testing requested and GTest not found (${builtin_gtest_description})" FORCE)
1263-
endif()
1264-
endif()
1265-
endif()
1266-
else()
1256+
if (builtin_gtest)
12671257
ROOT_CHECK_CONNECTION("testing=OFF")
12681258
if(NO_CONNECTION)
12691259
message(STATUS "No internet connection, disabling the 'testing', 'testsupport' and 'builtin_gtest' options")
12701260
set(testing OFF CACHE BOOL "Disabled because there is no internet connection" FORCE)
12711261
set(testsupport OFF CACHE BOOL "Disabled because there is no internet connection" FORCE)
12721262
set(builtin_gtest OFF CACHE BOOL "Disabled because there is no internet connection" FORCE)
1263+
else()
1264+
add_subdirectory(builtins/gtest)
12731265
endif()
12741266
endif()
12751267
endif()
12761268

1277-
if (builtin_gtest)
1278-
add_subdirectory(builtins/gtest)
1269+
if (testing OR testsupport)
1270+
# Starting from cmake 3.23, the GTest targets will have stable names.
1271+
# ROOT was updated to use those, but for older CMake versions, we have to declare the aliases:
1272+
foreach(LIBNAME gtest_main gmock_main gtest gmock)
1273+
if(NOT TARGET GTest::${LIBNAME} AND TARGET ${LIBNAME})
1274+
add_library(GTest::${LIBNAME} ALIAS ${LIBNAME})
1275+
endif()
1276+
endforeach()
12791277
endif()
12801278

1281-
# Starting from cmake 3.23, the GTest targets will have stable names.
1282-
# ROOT was updated to use those, but for older CMake versions, we have to declare the aliases:
1283-
foreach(LIBNAME gtest_main gmock_main gtest gmock)
1284-
if(NOT TARGET GTest::${LIBNAME} AND TARGET ${LIBNAME})
1285-
add_library(GTest::${LIBNAME} ALIAS ${LIBNAME})
1286-
endif()
1287-
endforeach()
1288-
12891279
#------------------------------------------------------------------------------------
12901280
if(webgui AND NOT builtin_openui5)
12911281
ROOT_CHECK_CONNECTION("builtin_openui5=ON")

0 commit comments

Comments
 (0)