mirror of https://github.com/qt/qtgrpc.git
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:
parent
5c2c831703
commit
68b2e1db08
|
|
@ -10,7 +10,7 @@ find_program(__WrapgRPCPlugin_plugin_imported_location
|
||||||
NAMES grpc_cpp_plugin grpc_cpp_plugin.exe
|
NAMES grpc_cpp_plugin grpc_cpp_plugin.exe
|
||||||
# Support for vcpkg-based directory layout
|
# Support for vcpkg-based directory layout
|
||||||
PATH_SUFFIXES tools/grpc
|
PATH_SUFFIXES tools/grpc
|
||||||
HINTS "$ENV{gRPC_ROOT}/bin")
|
HINTS "$ENV{gRPC_ROOT}/bin" "${gRPC_ROOT}/bin")
|
||||||
|
|
||||||
set(WrapgRPCPlugin_FOUND FALSE)
|
set(WrapgRPCPlugin_FOUND FALSE)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,34 @@
|
||||||
# Copyright (C) 2023 The Qt Company Ltd.
|
# Copyright (C) 2023 The Qt Company Ltd.
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# 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)
|
qt_examples_build_begin(EXTERNAL_BUILD)
|
||||||
|
|
||||||
add_subdirectory(protobuf)
|
add_subdirectory(protobuf)
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ find_package(Qt6 REQUIRED COMPONENTS
|
||||||
Protobuf
|
Protobuf
|
||||||
Grpc
|
Grpc
|
||||||
GrpcQuick
|
GrpcQuick
|
||||||
|
GrpcTools
|
||||||
Quick
|
Quick
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ if(NOT TARGET WrapgRPC::WrapgRPCPlugin OR NOT TARGET WrapProtoc::WrapProtoc
|
||||||
return()
|
return()
|
||||||
endif()
|
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(proto_files "${CMAKE_CURRENT_LIST_DIR}/../proto/exampleservice.proto")
|
||||||
set(out_dir ${CMAKE_CURRENT_BINARY_DIR})
|
set(out_dir ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue