CMake: Make examples build as external projects

A couple of things are needed to ensure examples can be built as
external projects.

Change FindWrapgRPCPlugin to look for a cache var in addition to _ROOT
env var, because we can't easily pass env vars to external projects.

Ensure one of the non-Qt test libraries is built with at least C++17
to avoid compilation errors.

Derive a path to absl_ROOT from gRPC_ROOT assuming they are in the
same parent directory.

Use the new QT_EXAMPLE_CMAKE_VARS_TO_PASS variable introduced in
qtbase to allow passing additional cmake variables to all examples
that are built as external projects.
We need to use it for all 3rd party dependencies that have to be
found by the examples.

Make sure to look for GrpcTools package for magic8ball example, to
ensure the public api is available when cross-compiling, but there
is no target native grpc library available.

Task-number: QTBUG-90820
Task-number: QTBUG-96232
Change-Id: I4420b7348c6a3b02b5516f34a96b19cceaccc649
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-07-25 15:29:39 +02:00
parent 5c2c831703
commit 68b2e1db08
4 changed files with 34 additions and 1 deletions

View File

@ -10,7 +10,7 @@ find_program(__WrapgRPCPlugin_plugin_imported_location
NAMES grpc_cpp_plugin grpc_cpp_plugin.exe
# Support for vcpkg-based directory layout
PATH_SUFFIXES tools/grpc
HINTS "$ENV{gRPC_ROOT}/bin")
HINTS "$ENV{gRPC_ROOT}/bin" "${gRPC_ROOT}/bin")
set(WrapgRPCPlugin_FOUND FALSE)

View File

@ -1,6 +1,34 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# Pass 3rd party dependency locations to examples as external projects.
if(NOT Protobuf_ROOT AND "$ENV{Protobuf_ROOT}")
set(Protobuf_ROOT "$ENV{Protobuf_ROOT}")
endif()
if(NOT gRPC_ROOT AND "$ENV{gRPC_ROOT}")
set(gRPC_ROOT "$ENV{gRPC_ROOT}")
endif()
if(NOT absl_ROOT AND "$ENV{absl_ROOT}")
set(absl_ROOT "$ENV{absl_ROOT}")
endif()
if(NOT OPENSSL_ROOT_DIR AND "$ENV{OPENSSL_ROOT_DIR}")
set(OPENSSL_ROOT_DIR "$ENV{OPENSSL_ROOT_DIR}")
endif()
set(QT_EXAMPLE_CMAKE_VARS_TO_PASS Protobuf_ROOT:STRING gRPC_ROOT:STRING OPENSSL_ROOT_DIR:STRING)
# In the CI, we assume the absl dependency is next to the gRPC one.
if(gRPC_ROOT AND NOT absl_ROOT)
get_filename_component(absl_ROOT "${gRPC_ROOT}" DIRECTORY)
string(APPEND absl_ROOT "/absl")
if(EXISTS "${absl_ROOT}")
list(APPEND QT_EXAMPLE_CMAKE_VARS_TO_PASS absl_ROOT:STRING)
endif()
endif()
qt_examples_build_begin(EXTERNAL_BUILD)
add_subdirectory(protobuf)

View File

@ -15,6 +15,7 @@ find_package(Qt6 REQUIRED COMPONENTS
Protobuf
Grpc
GrpcQuick
GrpcTools
Quick
)

View File

@ -16,6 +16,10 @@ if(NOT TARGET WrapgRPC::WrapgRPCPlugin OR NOT TARGET WrapProtoc::WrapProtoc
return()
endif()
# Avoid "Protobuf requires at least C++11." errors
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(proto_files "${CMAKE_CURRENT_LIST_DIR}/../proto/exampleservice.proto")
set(out_dir ${CMAKE_CURRENT_BINARY_DIR})