Use double lookup for protobuf/Protobuf packages

find_package with NAMES argument forces the CONFIG mode look up.
We accidentally looked for Protobuf uppercase in MODULE mode in
configure.cmake which allowed Protobuf targets be found for tests
and tools. Make this double lookup procedure explicit. All efforts
to support ubuntu/debian platforms, that decline to deliver protobuf
Config files.

Drive-by, use the correct variable to check that Protobuf is found
in golang grpc test server.

Pick-to: 6.9
Change-Id: I50d17aec72540a472bff30782d83e4555c51604a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2025-01-31 14:15:11 +01:00
parent 073429bfb1
commit ee3326e298
3 changed files with 15 additions and 3 deletions
cmake
src/protobuf
tests/auto/grpc/client/shared/test_server_go

View File

@ -28,10 +28,13 @@ if(NOT CMAKE_CROSSCOMPILING)
set(__WrapProtoc_CMAKE_FIND_PACKAGE_PREFER_CONFIG_save ${CMAKE_FIND_PACKAGE_PREFER_CONFIG})
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(protobuf ${WrapProtoc_FIND_VERSION} NAMES protobuf Protobuf ${__WrapProtoc_find_package_args})
if(NOT protobuf_FOUND)
find_package(Protobuf ${__WrapProtoc_find_package_args})
endif()
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${__WrapProtoc_CMAKE_FIND_PACKAGE_PREFER_CONFIG_save})
unset(__WrapProtoc_CMAKE_FIND_PACKAGE_PREFER_CONFIG_save)
if(protobuf_FOUND AND TARGET protobuf::protoc)
if((protobuf_FOUND OR Protobuf_FOUND) AND TARGET protobuf::protoc)
get_target_property(__WrapProtoc_is_protoc_imported protobuf::protoc IMPORTED)
if(__WrapProtoc_is_protoc_imported)
foreach(config IN ITEMS _RELWITHDEBINFO "" _RELEASE _MINSIZEREL _DEBUG)

View File

@ -3,9 +3,18 @@
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG_save "${CMAKE_FIND_PACKAGE_PREFER_CONFIG}")
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
qt_find_package(Protobuf
qt_find_package(protobuf
MODULE_NAME global
NAMES protobuf Protobuf
)
if(NOT protobuf_FOUND)
# Attempt looking in MODULE mode
qt_find_package(Protobuf
MODULE_NAME global
)
endif()
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG "${CMAKE_FIND_PACKAGE_PREFER_CONFIG_save}")
# WrapProtoc::WrapProtoc could come from top-level CMakeLists.txt so avoid promoting it to GLOBAL

View File

@ -4,7 +4,7 @@ set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
find_package(Protobuf)
if(NOT WrapProtobuf_FOUND)
if(NOT Protobuf_FOUND)
message(WARNING "Dependencies of Qt GRPC test server not found. Skipping.")
return()
endif()