CMake: Find ZLIB before gRPC in the standalone tests
The standalone tests find gRPC inside a block that sets
CMAKE_FIND_PACKAGE_PREFER_CONFIG to TRUE. gRPC's package config exports
gRPC::grpc with ZLIB::ZLIB in its link interface, but only resolves that
target itself via a guarded "if(NOT ZLIB_FOUND) find_package(ZLIB)".
If ZLIB_FOUND is already set in the configure scope without ZLIB::ZLIB
existing in that directory scope, gRPC's config skips its own
find_package(ZLIB), leaving gRPC::grpc referencing a target that does not
exist. The generate step then aborts with:
CMake Error at .../share/grpc/gRPCTargets.cmake (set_target_properties):
The link interface of target "gRPC::grpc" contains:
ZLIB::ZLIB
but the target was not found.
The module build is unaffected because src/grpc/CMakeLists.txt finds
WrapZLIB explicitly, but the test project never resolves ZLIB in its own
scope.
Find ZLIB up front in MODULE mode, before enabling
CMAKE_FIND_PACKAGE_PREFER_CONFIG, so that ZLIB::ZLIB exists in the
consuming scope before gRPC is found. This mirrors the existing OpenSSL
handling for the same class of transitive dependency.
Pick-to: 6.12
Change-Id: Ie95b6491666b7e91aa5bc1396e5cba7c510c2acc
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>