### gRPC Service Setup Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/server/CMakeLists.txt Configures gRPC client or server components based on proto files. This example sets up a client. Specify the proto files and the output directory for generated code. ```cmake qt6_add_grpc(tst_grpc_server_qtgrpc_gen CLIENT PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../shared/proto/testservice.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated" ) ``` -------------------------------- ### Installation Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/magic8ball/server/CMakeLists.txt Configures the installation of the built executable. ```cmake install(TARGETS magic8ball_server RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Install Server Executable Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Installs the compiled server executable to a specified runtime destination. ```cmake install(TARGETS clientguide_server RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Setup Autogen Tools Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/nested/CMakeLists.txt Initializes the setup for autogen tools, which is necessary for processing generated code. This is a preparatory step before adding tests that utilize the generated protobuf code. ```cmake qt_autogen_tools_initial_setup(tst_protobuf_nestedtypes_qtprotobuf_gen) ``` -------------------------------- ### Install Protobuf Sensors Client Executable Source: https://github.com/qt/qtgrpc/blob/dev/examples/protobuf/sensors/client/CMakeLists.txt Configures the installation of the protobuf_sensors_client executable, including runtime, bundle, and library destinations. ```cmake install(TARGETS protobuf_sensors_client RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Set Up Autogen Tools Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/syntax/CMakeLists.txt Initializes Qt autogen tools for the specified target. This is a setup step for code generation processes. ```cmake qt_autogen_tools_initial_setup(tst_protobuf_syntax_qtprotobuf_gen) ``` -------------------------------- ### Basic CMake Project Setup for gRPC Client Test Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpcquick/client/unarycall/CMakeLists.txt Initializes the CMake project, specifies the minimum required version, and finds necessary Qt build internals for standalone tests. This setup is conditional to avoid running when building the entire Qt. ```cmake if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.16) project(tst_grpc_client_unarycall_qml LANGUAGES CXX) find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) include("../../../grpc/client/shared/test_server/CMakeLists.txt") endif() ``` -------------------------------- ### Install Vehicle Server Executable Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/vehicle/server/CMakeLists.txt Configures the installation of the vehicle server executable. It specifies the destination directory relative to the installation prefix. ```cmake install(TARGETS vehicle_server RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) ``` -------------------------------- ### Setting up Autogen Tools Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpcquick/client/unarycall/CMakeLists.txt Initializes the autogen tools setup for various targets, including the main test executable, the generated code target, and a plugin target. This is necessary for Qt's code generation and build system integration. ```cmake qt_autogen_tools_initial_setup(tst_grpc_client_unarycall_qml) qt_autogen_tools_initial_setup(tst_grpc_client_unarycall_qml_gen) qt_autogen_tools_initial_setup(tst_grpc_client_unarycall_qml_genplugin) ``` -------------------------------- ### Add Qt gRPC Example Source: https://github.com/qt/qtgrpc/blob/dev/examples/protobuf/CMakeLists.txt Conditionally adds a Qt gRPC example if the qtprotobufgen feature is enabled and necessary Qt targets are available. This is typically used in build system configurations. ```cmake if(QT_FEATURE_qtprotobufgen AND TARGET Qt6::Network AND TARGET Qt6::Widgets) qt_internal_add_example(sensors) endif() ``` -------------------------------- ### Setup Autogen Tools Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_service/CMakeLists.txt Initializes the autogen tools for the specified target library. This is typically used to set up code generation processes. ```cmake qt_autogen_tools_initial_setup(tst_grpc_client_qtgrpc_gen) ``` -------------------------------- ### Set up Autotools for Protobuf Generation Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/recursive/CMakeLists.txt Initialize the autotools setup for the protobuf generation target. This is a prerequisite for using generated protobuf code in tests. ```cmake qt_autogen_tools_initial_setup(tst_protobuf_recursive_gen) ``` -------------------------------- ### Find OpenSSL and Protobuf Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/test_server/CMakeLists.txt Locates OpenSSL and Protobuf libraries. Ensure these are installed and findable by CMake. ```cmake find_package(OpenSSL) set(_qt_grpc_backup_prefer_config ${CMAKE_FIND_PACKAGE_PREFER_CONFIG}) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) find_package(Protobuf) find_package(gRPC) ``` -------------------------------- ### Define gRPC Test Server Executable Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/test_server/CMakeLists.txt Creates the 'grpc_testserver' executable using the 'grpc_testserverrunner' library. It specifies source files, linked libraries, output directory, and installation path. ```cmake qt_internal_add_executable(grpc_testserver SOURCES ${CMAKE_CURRENT_LIST_DIR}/testserver.cpp LIBRARIES grpc_testserverrunner OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" INSTALL_DIRECTORY "${INSTALL_TESTSDIR}/shared" ) ``` -------------------------------- ### Conditional Build Setup Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/interceptors/CMakeLists.txt Ensures that the CMake configuration proceeds only when building standalone tests or when Qt itself is being built. It sets the minimum CMake version and defines the project. ```cmake if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.16) project(tst_grpc_client_interceptors LANGUAGES CXX) find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) include("../shared/mockserver/CMakeLists.txt") endif() ``` -------------------------------- ### Find Qt6BuildInternals Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/nested/CMakeLists.txt Finds the Qt6BuildInternals package, which is required for building standalone tests or Qt itself. This setup is conditional and skipped if building standalone tests or Qt. ```cmake if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) cmake_minimum_required(VERSION 3.16) project(tst_protobuf_nested LANGUAGES CXX) find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) endif() ``` -------------------------------- ### Set up Standalone Test Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/nopackage/CMakeLists.txt Configure a standalone test executable using `qt_internal_add_test`. This includes specifying source files, include directories, and linking necessary libraries like QtTest and QtProtobuf, as well as the generated protobuf code. ```cmake qt_internal_add_test(tst_protobuf_nopackagetypes SOURCES tst_protobuf_nopackagetypes.cpp INCLUDE_DIRECTORIES ../shared LIBRARIES Qt::Test Qt::Protobuf tst_protobuf_nopackagetypes_qtprotobuf_gen ) ``` -------------------------------- ### Project and Dependency Configuration Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/magic8ball/server/CMakeLists.txt Sets up the CMake project, finds necessary packages like OpenSSL, Protobuf, and gRPC, and configures C++ standard. ```cmake cmake_minimum_required(VERSION 3.16) project(magic8ball_server LANGUAGES CXX) # Find OpenSSL first since it's a transitive dependency that may not be available in CONFIG mode find_package(OpenSSL) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) find_package(Protobuf) find_package(gRPC) if(CMAKE_CROSSCOMPILING) find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE) elseif(TARGET gRPC::grpc_cpp_plugin) set(grpc_cpp_plugin $) else() set(grpc_cpp_plugin "") endif() if(NOT grpc_cpp_plugin OR NOT TARGET gRPC::grpc++) return() endif() if(MINGW) message(WARNING "${PROJECT_NAME} uses reference grpc++ library that doesn't officially support" " MinGW. Please use the MSVC compiler to build this example. The correct work is not" " guaranteed otherwise.") endif() # Avoid "Protobuf requires at least C++11." errors set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) ``` -------------------------------- ### Create grpc_mock_server Library Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/mockserver/CMakeLists.txt This code defines the 'grpc_mock_server' static library using 'mockserver.h' and 'mockserver.cpp'. It sets public include directories and links against protobuf, gRPC++, and Qt Test libraries. ```cmake add_library(grpc_mock_server STATIC mockserver.h mockserver.cpp) target_include_directories(grpc_mock_server PUBLIC "${CMAKE_CURRENT_LIST_DIR}" ) target_link_libraries(grpc_mock_server PUBLIC protobuf::libprotobuf gRPC::grpc++ Qt::Test ) ``` -------------------------------- ### Configure Protocol Buffer Files Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/interceptors/CMakeLists.txt Sets up variables for Protocol Buffer files, import directories, and output directories for generated code. ```cmake set(proto_files "${CMAKE_CURRENT_LIST_DIR}/interceptor1.proto" "${CMAKE_CURRENT_LIST_DIR}/interceptor2.proto" ) set(proto_import "${CMAKE_CURRENT_LIST_DIR}") set(proto_out_include "${CMAKE_CURRENT_BINARY_DIR}/include") set(proto_out_server "${proto_out_include}/proto/server") set(proto_out_client "${proto_out_include}/proto/client") ``` -------------------------------- ### Set up Test Target with Protobuf Library Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/extranamespace/CMakeLists.txt Define a test target using `qt_internal_add_test`, including sources, include directories, and linking against Qt modules and the generated protobuf library. ```cmake qt_internal_add_test(tst_protobuf_extranamespace SOURCES tst_protobuf_extranamespace.cpp INCLUDE_DIRECTORIES ../shared LIBRARIES Qt::Test Qt::Protobuf tst_protobuf_extranamespace_qtprotobuf_gen ) ``` -------------------------------- ### Create Benchmark Executable Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt Defines the benchmark executable 'bench_async_ref_client', specifying its source files, linked libraries (protobuf, gRPC, Qt::Core), and include directories. It also sets the output directory and adds a dependency on 'asyncbenchserver' if it exists. ```cmake qt_internal_add_executable( bench_async_ref_client SOURCES bench_async_ref_client.cpp "${generated_files}" LIBRARIES protobuf::libprotobuf gRPC::grpc++ Qt::Core INCLUDE_DIRECTORIES "${proto_out_include}" "${qrpcbench_common_include}" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) if(TARGET asyncbenchserver) add_dependencies(bench_async_ref_client asyncbenchserver) endif() ``` -------------------------------- ### Configure Qt gRPC Client Build Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/client/CMakeLists.txt Sets up the CMake build for a Qt gRPC client. It finds Qt6 components for Protobuf and gRPC, sets up the project, defines the client executable, processes proto files using qt_add_protobuf, and generates gRPC client code using qt_add_grpc. Finally, it links the necessary Qt libraries. ```cmake set(proto_files "${CMAKE_CURRENT_LIST_DIR}/../proto/clientguide.proto") find_package(Qt6 COMPONENTS Protobuf Grpc) qt_standard_project_setup(REQUIRES 6.9) qt_add_executable(clientguide_client main.cpp interceptors.cpp) # Using the executable as input target will append the generated files to it. qt_add_protobuf(clientguide_client PROTO_FILES ${proto_files} ) qt_add_grpc(clientguide_client CLIENT PROTO_FILES ${proto_files} ) target_link_libraries(clientguide_client PRIVATE Qt6::Protobuf Qt6::Grpc) ``` -------------------------------- ### Test Application Configuration Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/server/CMakeLists.txt Defines a test executable, linking it with necessary Qt modules and generated gRPC code. Ensure all required SOURCES, INCLUDE_DIRECTORIES, and LIBRARIES are correctly specified. ```cmake qt_internal_add_test(tst_grpc_server SOURCES tst_grpc_server.cpp INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/../shared LIBRARIES Qt::Test Qt::Core Qt::Grpc tst_grpc_server_qtgrpc_gen ) ``` -------------------------------- ### Define Executable and Libraries Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_qtgrpcclient/CMakeLists.txt Defines the benchmark executable, lists its source files, and specifies the required Qt libraries and include directories. Ensures the executable is built with the correct dependencies. ```cmake set(proto_out_dir "${CMAKE_CURRENT_BINARY_DIR}/include/proto/") set(proto_out_include "${CMAKE_CURRENT_BINARY_DIR}/include/") if (NOT TARGET Qt6::Grpc) message(WARNING "Dependencies of QtGrpc bench_qtgrpcclient not found. Skipping.") return() endif() qt_internal_add_executable( bench_qtgrpcclient SOURCES bench_qtgrpcclient.cpp LIBRARIES Qt::Grpc Qt::ProtobufWellKnownTypes INCLUDE_DIRECTORIES "${proto_out_include}" "${qrpcbench_common_include}" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) ``` -------------------------------- ### Add Test Executable with Protobuf Support Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/recursive/CMakeLists.txt Configure a test executable using `qt_internal_add_test`. This includes specifying source files, include directories, and linking against necessary libraries like Qt::Test, Qt::Protobuf, and the generated protobuf code. ```cmake qt_internal_add_test(tst_protobuf_recursive SOURCES tst_protobuf_recursive.cpp INCLUDE_DIRECTORIES ../shared LIBRARIES Qt::Test Qt::Protobuf tst_protobuf_recursive_gen ) ``` -------------------------------- ### Configure Protobuf JSON Deserialization Benchmark Source: https://github.com/qt/qtgrpc/blob/dev/tests/benchmarks/protobuf/deserialize/CMakeLists.txt Sets up a benchmark target specifically for Protobuf JSON deserialization. It includes sources, directories, and links against Qt Test, Qt Protobuf, and the base library, with Protobuf list aliases disabled. ```cmake qt_internal_add_benchmark(tst_bench_deserialize_protobuf_json SOURCES tst_bench_deserialize_protobuf_json.cpp INCLUDE_DIRECTORIES . LIBRARIES Qt::Test Qt::Protobuf tst_bench_deserialize_protobuf_base ) set_target_properties(tst_bench_deserialize_protobuf_json PROPERTIES QT_USE_PROTOBUF_LIST_ALIASES FALSE ) ``` -------------------------------- ### Configure Include Directories Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_test_common/CMakeLists.txt Sets up interface and private include directories for the test common library, ensuring access to shared headers. ```cmake target_include_directories(tst_grpc_client_test_common INTERFACE "$" PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../../../shared" ) ``` -------------------------------- ### Configure Protobuf Deserialization Benchmark Source: https://github.com/qt/qtgrpc/blob/dev/tests/benchmarks/protobuf/deserialize/CMakeLists.txt Sets up a benchmark target for Protobuf deserialization. It includes necessary sources, directories, and links against Qt Test, Qt Protobuf, and the base library. Protobuf list aliases are disabled for this target. ```cmake qt_internal_add_benchmark(tst_bench_deserialize_protobuf SOURCES tst_bench_deserialize_protobuf.cpp INCLUDE_DIRECTORIES . LIBRARIES Qt::Test Qt::Protobuf tst_bench_deserialize_protobuf_base ) set_target_properties(tst_bench_deserialize_protobuf PROPERTIES QT_USE_PROTOBUF_LIST_ALIASES FALSE) ``` -------------------------------- ### Define Async Benchmark Server Executable Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt Defines the asynchronous benchmark server executable using `qt_internal_add_executable`. It lists the source files, including the generated gRPC code, and specifies the required libraries (protobuf, gRPC++, Qt::Core) and include directories. ```cmake qt_internal_add_executable( asyncbenchserver SOURCES asyncbenchserver.cpp "${generated_files}" LIBRARIES protobuf::libprotobuf gRPC::grpc++ Qt::Core INCLUDE_DIRECTORIES "${proto_out_include}" "${qrpcbench_common_include}" OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" ) ``` -------------------------------- ### Executable and Linking Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/magic8ball/server/CMakeLists.txt Defines the main executable for the server and links it with necessary libraries. ```cmake qt_add_executable(magic8ball_server ${generated_files} main.cpp ) target_include_directories(magic8ball_server PRIVATE ${out_dir} ) target_link_libraries(magic8ball_server PRIVATE protobuf::libprotobuf gRPC::grpc++ ) ``` -------------------------------- ### Define Protobuf and gRPC Libraries Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/chat/client/CMakeLists.txt This snippet defines a static library for protobuf generated code and configures gRPC client support. It specifies the QML URI for generated protobuf types and lists the proto files for both message definitions and gRPC services. Ensure Qt6::ProtobufQtCoreTypes is available for proto includes. ```cmake add_library(qtgrpc_chat_client_proto STATIC) qt_add_protobuf(qtgrpc_chat_client_proto QML QML_URI QtGrpcChat.Proto PROTO_FILES ../proto/chatmessages.proto PROTO_INCLUDES $ ) qt_add_grpc(qtgrpc_chat_client_proto CLIENT PROTO_FILES ../proto/qtgrpcchat.proto PROTO_INCLUDES $ ) ``` -------------------------------- ### Initialize Autogen Tools Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_test_common/CMakeLists.txt Initializes Qt's autogen tools for the specified target, ensuring MOC, UIC, and other code generation steps are set up. ```cmake qt_autogen_tools_initial_setup(tst_grpc_client_test_common) ``` -------------------------------- ### Compile Definition and Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_qtgrpcclient/CMakeLists.txt Adds a private compile definition 'QTGRPCCLIENT' to the benchmark executable. Optionally adds a dependency on 'asyncbenchserver' if that target exists, ensuring proper build order. ```cmake target_compile_definitions(bench_qtgrpcclient PRIVATE QTGRPCCLIENT) if(TARGET asyncbenchserver) add_dependencies(bench_qtgrpcclient asyncbenchserver) endif() ``` -------------------------------- ### Configure gRPC Client with Qt6 Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_service/CMakeLists.txt Uses the `qt6_add_grpc` command to configure the gRPC client functionality for a target library. It specifies the proto files and the output directory for generated gRPC code. ```cmake qt6_add_grpc(tst_grpc_client_qtgrpc_gen CLIENT PROTO_FILES ${CMAKE_CURRENT_LIST_DIR}/../../../shared/proto/testservice.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated" ) ``` -------------------------------- ### Add Protobuf Files for Code Generation Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/recursive/CMakeLists.txt Use `qt6_add_protobuf` to process .proto files and generate C++ code. Specify the input proto files and the output directory for the generated code. ```cmake qt6_add_protobuf(tst_protobuf_recursive_gen PROTO_FILES recursive.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" ) ``` -------------------------------- ### Add gRPC Test Server Resources Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/test_server/CMakeLists.txt Embeds the generated SSL certificates (cert.pem and key.pem) as Qt resources into the 'grpc_testserverrunner' library if they exist. They are aliased to 'assets/cert.pem' and 'assets/key.pem'. ```cmake if(EXISTS "${certificates_output_dir}/key.pem" AND EXISTS "${certificates_output_dir}/cert.pem") set_source_files_properties("${certificates_output_dir}/cert.pem" PROPERTIES QT_RESOURCE_ALIAS assets/cert.pem) set_source_files_properties("${certificates_output_dir}/key.pem" PROPERTIES QT_RESOURCE_ALIAS assets/key.pem) qt_add_resources(grpc_testserverrunner "keys" PREFIX "/" FILES "${certificates_output_dir}/cert.pem" "${certificates_output_dir}/key.pem" ) endif() ``` -------------------------------- ### Link Protobuf and gRPC Libraries Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/chat/client/CMakeLists.txt This snippet links the necessary Qt Protobuf and gRPC modules to the generated proto library. This ensures that the protobuf and gRPC functionalities are available for use by the client application. ```cmake target_link_libraries(qtgrpc_chat_client_proto PUBLIC Qt6::Protobuf Qt6::ProtobufQtCoreTypes Qt6::Grpc ) ``` -------------------------------- ### Set Include Directories for Server Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/vehicle/server/CMakeLists.txt Adds the binary output directory to the include paths for the vehicle server. This allows the server to find the generated header files. ```cmake target_include_directories(vehicle_server PRIVATE ${out_dir} ) ``` -------------------------------- ### Generate gRPC Sources from Proto Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Configures a custom command to generate C++ gRPC and Protobuf code from the .proto file using protoc and the gRPC plugin. ```cmake add_custom_command( OUTPUT ${generated_files} COMMAND $ ARGS --grpc_out "${proto_out}" --cpp_out "${proto_out}" -I "${CMAKE_CURRENT_LIST_DIR}/../proto" --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${proto_out} DEPENDS "${proto_files}" COMMENT "Generating gRPC ${target} sources..." COMMAND_EXPAND_LISTS VERBATIM ) set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE) ``` -------------------------------- ### Dependency Check for QtGrpc Benchmark Server Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt Checks if all required dependencies, including the gRPC C++ plugin, WrapProtoc, and the gRPC++ library, are found. If any are missing, a warning is issued, and the build process for the benchmark server is skipped. ```cmake if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc OR NOT TARGET gRPC::grpc++) message(WARNING "Dependencies of QtGrpc benchmark-server not found. Skipping.") return() endif() ``` -------------------------------- ### Configure Protobuf Generation Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/nopackage/CMakeLists.txt Use `qt6_add_protobuf` to generate C++ code from .proto files. Specify the input proto files and an output directory for the generated code. `GENERATE_PACKAGE_SUBFOLDERS` is used here to ensure generated files are placed in subfolders. ```cmake qt6_add_protobuf(tst_protobuf_nopackagetypes_qtprotobuf_gen PROTO_FILES ../../shared/data/proto/nopackage.proto ../../shared/data/proto/nopackageexternal.proto GENERATE_PACKAGE_SUBFOLDERS OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" ) ``` -------------------------------- ### Define Protocol Buffer Files Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/vehicle/server/CMakeLists.txt Lists the .proto files that define the gRPC services. These files will be used to generate C++ code. ```cmake set(proto_files "${CMAKE_CURRENT_LIST_DIR}/../proto/vehicleservice.proto" "${CMAKE_CURRENT_LIST_DIR}/../proto/navigationservice.proto") ``` -------------------------------- ### Generate Protobuf Code for Client Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/interceptors/CMakeLists.txt Uses qt_add_protobuf to generate C++ code from .proto files for the client side, specifying output directory and extra namespace. ```cmake qt_add_protobuf(tst_grpc_client_interceptors PROTO_FILES ${proto_files} OUTPUT_DIRECTORY ${proto_out_client} EXTRA_NAMESPACE "qt" ) ``` -------------------------------- ### Configure Protobuf Generation with Qt Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/syntax/CMakeLists.txt Use `qt6_add_protobuf` to generate C++ code from .proto files. Specify input proto files, output directory, and options like `ALLOW_MUTABLE_GETTER_CONFLICTS`. ```cmake qt6_add_protobuf(tst_protobuf_syntax_qtprotobuf_gen PROTO_FILES ../../shared/data/proto/syntax.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" ALLOW_MUTABLE_GETTER_CONFLICTS ) ``` -------------------------------- ### Defining a QML Module for Testing Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpcquick/client/unarycall/CMakeLists.txt Creates a QML module with a specified URI and version, including the necessary QML files for the test. This makes the QML components available to the test runner. ```cmake qt_add_qml_module(tst_grpc_client_unarycall_qml URI QmlTestUri VERSION 1.0 QML_FILES qml/tst_grpc_client_unarycall.qml ) ``` -------------------------------- ### Generate Protobuf Code with Qt6 Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_service/CMakeLists.txt Uses the `qt6_add_protobuf` command to generate C++ code from a .proto file. The generated code is placed in a specified output directory. ```cmake qt6_add_protobuf(tst_grpc_client_qtgrpc_gen OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated" PROTO_FILES ${CMAKE_CURRENT_LIST_DIR}/../../../shared/proto/testservice.proto ) ``` -------------------------------- ### Add Basic Protobuf Test Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/basic/CMakeLists.txt Configures a test target for basic protobuf functionality. It specifies source files, include directories, and links against necessary Qt libraries and the generated protobuf code. ```cmake qt_internal_add_test(tst_protobuf_basictypes SOURCES tst_protobuf_basictypes.cpp INCLUDE_DIRECTORIES ../shared LIBRARIES Qt::Test Qt::Protobuf tst_protobuf_basictypes_gen ) ``` -------------------------------- ### Define Protobuf Sensors Client Executable Source: https://github.com/qt/qtgrpc/blob/dev/examples/protobuf/sensors/client/CMakeLists.txt Defines the main executable for the client application and lists its source files and UI files. ```cmake qt_add_executable(protobuf_sensors_client main.cpp clientconsole.cpp clientconsole.h sensorclient.cpp sensorclient.h clientconsole.ui ) ``` -------------------------------- ### Link gRPC and Protobuf Libraries Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Links the server executable against the necessary gRPC and Protocol Buffers libraries. ```cmake target_link_libraries(clientguide_server PRIVATE protobuf::libprotobuf gRPC::grpc++ ) ``` -------------------------------- ### Generate gRPC Client Code Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/interceptors/CMakeLists.txt Uses qt_add_grpc to generate gRPC client-specific C++ code from .proto files, including output directory and extra namespace. ```cmake qt_add_grpc(tst_grpc_client_interceptors CLIENT PROTO_FILES ${proto_files} OUTPUT_DIRECTORY ${proto_out_client} EXTRA_NAMESPACE "qt" ) ``` -------------------------------- ### Find gRPC and Protobuf Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt Ensures that the necessary gRPC and Protobuf libraries and tools are available. If not found, a warning is issued and the build is skipped. ```cmake find_package(WrapProtoc) find_package(Protobuf) find_package(gRPC) ``` ```cmake if(CMAKE_CROSSCOMPILING) find_program(grpc_cpp_plugin grpc_cpp_plugin NO_CACHE) elseif(TARGET gRPC::grpc_cpp_plugin) set(grpc_cpp_plugin $) else() set(grpc_cpp_plugin "") endif() if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc OR NOT TARGET gRPC::grpc++) message(WARNING "Dependencies of QtGrpc bench_async_ref_client not found. Skipping.") return() endif() ``` -------------------------------- ### Configure Protobuf Plugin Test Common Library Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protocplugintestcommon/CMakeLists.txt Defines a static library for common protobuf plugin test functionalities. It enables automatic meta-object compilation and links against Qt Core and Qt Test libraries. ```cmake set(CMAKE_AUTOMOC TRUE) qt_add_library(protocplugintestcommon STATIC protocplugintestcommon.h protocplugintestcommon.cpp) qt_autogen_tools_initial_setup(protocplugintestcommon) target_include_directories(protocplugintestcommon PUBLIC "$") target_link_libraries(protocplugintestcommon PUBLIC Qt6::Core Qt6::Test) ``` -------------------------------- ### Define gRPC Test Server Runner Library Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/test_server/CMakeLists.txt Defines the static library 'grpc_testserverrunner' which includes the server runner's source files. It sets include directories and links against the generated gRPC sources and Qt Core. ```cmake add_library(grpc_testserverrunner STATIC ${CMAKE_CURRENT_LIST_DIR}/testserverrunner.cpp ${CMAKE_CURRENT_LIST_DIR}/testserverrunner.h ) target_include_directories(grpc_testserverrunner PRIVATE ${out_dir} ${CMAKE_CURRENT_LIST_DIR}/../../../shared ) target_link_libraries(grpc_testserverrunner PRIVATE grpc_testserverrunner_gen gRPC::grpc++ Qt6::Core ) ``` -------------------------------- ### Link Libraries for Vehicle Server Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/vehicle/server/CMakeLists.txt Links the necessary libraries, protobuf::libprotobuf and gRPC::grpc++, to the vehicle server executable. These provide the core gRPC and Protobuf functionality. ```cmake target_link_libraries(vehicle_server PRIVATE protobuf::libprotobuf gRPC::grpc++ ) ``` -------------------------------- ### Add Protobuf Definitions Source: https://github.com/qt/qtgrpc/blob/dev/examples/protobuf/sensors/CMakeLists.txt Use `qt_add_protobuf` to process Protobuf definition files. This command generates C++ code from `.proto` files, which is then compiled into the target. ```cmake qt_add_protobuf(protobuf_sensors PROTO_FILES sensors.proto tlv.proto ) ``` -------------------------------- ### Find gRPC and Protobuf Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Locates necessary gRPC and Protocol Buffers libraries and tools. Ensures configuration is preferred for finding packages. ```cmake find_package(OpenSSL) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) find_package(protobuf) find_package(gRPC) find_package(Qt6 COMPONENTS ProtobufTools) ``` -------------------------------- ### Add Protobuf Library Target Source: https://github.com/qt/qtgrpc/blob/dev/tests/benchmarks/protobuf/deserialize/CMakeLists.txt Defines a static library for Protobuf deserialization benchmarks and integrates it with Qt's Protobuf module. Ensures Protobuf list aliases are disabled. ```cmake qt6_add_library(tst_bench_deserialize_protobuf_base STATIC tst_bench_deserialize_protobuf_base.h tst_bench_deserialize_protobuf_base.cpp ) qt_autogen_tools_initial_setup(tst_bench_deserialize_protobuf_base) target_link_libraries(tst_bench_deserialize_protobuf_base PRIVATE Qt::Test) set_target_properties(tst_bench_deserialize_protobuf_base PROPERTIES QT_USE_PROTOBUF_LIST_ALIASES FALSE) qt6_add_protobuf(tst_bench_deserialize_protobuf_base PROTO_FILES data/bench.proto ) ``` -------------------------------- ### Define Protocol Buffer Files and Output Directory Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Specifies the input Protocol Buffer file and the output directory for generated C++ source and header files. ```cmake set(proto_files "${CMAKE_CURRENT_LIST_DIR}/../proto/clientguide.proto") set(proto_out "${CMAKE_CURRENT_BINARY_DIR}") ``` -------------------------------- ### Define Server Executable Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Creates the main executable target for the server, including the generated C++ files. ```cmake add_executable(clientguide_server main.cpp ${generated_files}) ``` -------------------------------- ### Find gRPC and Protobuf Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/vehicle/server/CMakeLists.txt Locates the Protobuf and gRPC libraries required for building the gRPC server. Ensures that configuration mode is preferred for finding packages. ```cmake find_package(OpenSSL) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) find_package(Protobuf) find_package(gRPC) ``` -------------------------------- ### Check for Required Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Verifies if all essential gRPC and Protobuf components are found. If not, it issues a warning and skips the build. ```cmake if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc OR NOT TARGET gRPC::grpc++) message(WARNING "Dependencies of ${PROJECT_NAME} not found. Skipping.") return() endif() ``` -------------------------------- ### gRPC Client Code Generation for QML Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpcquick/client/unarycall/CMakeLists.txt Configures gRPC code generation for a client. It specifies the proto files to use and the output directory for the generated QML code. ```cmake qt_add_grpc(tst_grpc_client_unarycall_qml_gen CLIENT PROTO_FILES ../../../grpc/shared/proto/testservice.proto QML OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated_qml" ) ``` -------------------------------- ### Define Generated Files List Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Lists all the expected generated C++ source and header files based on the Protocol Buffer definition. ```cmake set(generated_files "${proto_out}/clientguide.pb.h" "${proto_out}/clientguide.pb.cc" "${proto_out}/clientguide.grpc.pb.h" "${proto_out}/clientguide.grpc.pb.cc") ``` -------------------------------- ### Generate gRPC and Protobuf C++ Sources Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_async_ref_client/CMakeLists.txt Configures a custom CMake command to generate C++ header and source files from .proto definitions using WrapProtoc and grpc_cpp_plugin. It handles different protoc versions and specifies output directories and include paths. ```cmake set(proto_out_dir "${CMAKE_CURRENT_BINARY_DIR}/include/proto") set(proto_out_include "${CMAKE_CURRENT_BINARY_DIR}/include/") set(generated_files "${proto_out_dir}/bench.grpc.pb.h" "${proto_out_dir}/bench.grpc.pb.cc" "${proto_out_dir}/bench.pb.h" "${proto_out_dir}/bench.pb.cc" ) set(extra_protoc_args "") get_target_property(protoc_version WrapProtoc::WrapProtoc _qt_internal_protobuf_version) if(protoc_version VERSION_GREATER_EQUAL "3.12" AND protoc_version VERSION_LESS "3.15") list(APPEND extra_protoc_args "--experimental_allow_proto3_optional") endif() add_custom_command( OUTPUT ${generated_files} COMMAND $ ARGS "${extra_protoc_args}" "--grpc_out \"${proto_out_dir}\"" "--cpp_out \"${proto_out_dir}\"" -I \"${proto_include}\"" --plugin=protoc-gen-grpc=${grpc_cpp_plugin} \"${proto_path}\"" WORKING_DIRECTORY "${proto_out_dir}" DEPENDS "${proto_path}" $ ${grpc_cpp_plugin} COMMENT "Generating gRPC ${target} sources..." COMMAND_EXPAND_LISTS VERBATIM ) ``` ```cmake set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE) ``` -------------------------------- ### Protocol Buffer and gRPC Code Generation Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/asyncbenchserver/CMakeLists.txt Configures a custom CMake command to generate C++ header and source files for protocol buffers and gRPC services. It specifies output directories, includes necessary arguments for protoc and grpc_out, and lists dependencies including the proto file itself and the WrapProtoc tool. ```cmake set(proto_out_dir "${CMAKE_CURRENT_BINARY_DIR}/include/proto/") set(proto_out_include "${CMAKE_CURRENT_BINARY_DIR}/include/") set(generated_files "${proto_out_dir}/bench.grpc.pb.h" "${proto_out_dir}/bench.grpc.pb.cc" "${proto_out_dir}/bench.pb.h" "${proto_out_dir}/bench.pb.cc" ) set(extra_protoc_args "") get_target_property(protoc_version WrapProtoc::WrapProtoc _qt_internal_protobuf_version) if(protoc_version VERSION_GREATER_EQUAL "3.12" AND protoc_version VERSION_LESS "3.15") list(APPEND extra_protoc_args "--experimental_allow_proto3_optional") endif() add_custom_command( OUTPUT ${generated_files} COMMAND $ ARGS "${extra_protoc_args}" --grpc_out "${proto_out_dir}" --cpp_out "${proto_out_dir}" -I "${proto_include}" --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_path}" WORKING_DIRECTORY "${proto_out_dir}" DEPENDS "${proto_path}" $ ${grpc_cpp_plugin} COMMENT "Generating gRPC ${target} sources..." COMMAND_EXPAND_LISTS VERBATIM ) set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE) ``` -------------------------------- ### Protobuf Generation for gRPC Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/server/CMakeLists.txt Generates C++ code from .proto files for gRPC services. Specify the proto files and the output directory for the generated code. ```cmake qt6_add_protobuf(tst_grpc_server_qtgrpc_gen PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/../shared/proto/testservice.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated" ) ``` -------------------------------- ### Link Libraries for Test Common Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_test_common/CMakeLists.txt Links necessary libraries, including generated gRPC code, Qt Core, Qt Test, and Qt gRPC, to the test common library. ```cmake target_link_libraries(tst_grpc_client_test_common PRIVATE tst_grpc_client_qtgrpc_gen Qt::Core Qt::Test Qt::Grpc ) ``` -------------------------------- ### Set Include Directories Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/clientguide/server/CMakeLists.txt Adds the output directory for generated files to the include path for the server executable. ```cmake target_include_directories(clientguide_server PRIVATE ${proto_out}) ``` -------------------------------- ### Define gRPC Generated Sources Library Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/test_server/CMakeLists.txt Creates a static library 'grpc_testserverrunner_gen' from the generated gRPC protocol buffer files. It sets include directories for generated files and links against protobuf and gRPC libraries. ```cmake set_source_files_properties(${generated_files} PROPERTIES GENERATED TRUE) add_library(grpc_testserverrunner_gen STATIC ${generated_files}) target_include_directories(grpc_testserverrunner_gen PRIVATE ${out_dir} WrapgRPC_INCLUDE_PATH ) target_link_libraries(grpc_testserverrunner_gen PRIVATE protobuf::libprotobuf gRPC::grpc++ ) ``` -------------------------------- ### Configure Qt Protobuf with Extra Namespace Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/extranamespace/CMakeLists.txt Use `qt6_add_protobuf` to generate C++ code from protobuf files. Specify `EXTRA_NAMESPACE` to control the namespace of the generated code. ```cmake qt6_add_protobuf(tst_protobuf_extranamespace_qtprotobuf_gen OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" PROTO_FILES proto/extranamespace.proto EXTRA_NAMESPACE "MyTestNamespace" ) ``` -------------------------------- ### Generate gRPC C++ Sources from Protobuf Source: https://github.com/qt/qtgrpc/blob/dev/examples/grpc/vehicle/server/CMakeLists.txt Configures a custom command to run the protoc compiler with the gRPC plugin. This command generates C++ source and header files from the specified .proto files. ```cmake add_custom_command( OUTPUT ${generated_files} COMMAND $ ARGS --grpc_out "${out_dir}" --cpp_out "${out_dir}" -I "${CMAKE_CURRENT_LIST_DIR}/../proto/" --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${out_dir} DEPENDS "${proto_files}" COMMENT "Generating gRPC ${target} sources..." COMMAND_EXPAND_LISTS VERBATIM ) ``` -------------------------------- ### Check for gRPC Mock Server Dependencies Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/mockserver/CMakeLists.txt This snippet checks if essential gRPC mock server dependencies, including the gRPC C++ plugin, WrapProtoc, and gRPC++ library, are found. If not, it issues a warning and skips the build. ```cmake if(NOT grpc_cpp_plugin OR NOT TARGET WrapProtoc::WrapProtoc OR NOT TARGET gRPC::grpc++) message(WARNING "Dependencies of 'grpc_mock_server' not found. Skipping.") return() endif() ``` -------------------------------- ### Protobuf Code Generation for QML Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpcquick/client/unarycall/CMakeLists.txt Generates Protobuf code specifically for QML integration. It uses the specified proto files, defines a QML URI, and sets the output directory for the generated code. ```cmake qt_add_protobuf(tst_grpc_client_unarycall_qml_gen PROTO_FILES ../../../grpc/shared/proto/testservice.proto QML QML_URI qtgrpc.tests OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_grpc_generated_qml" ) ``` -------------------------------- ### Protobuf Code Generation Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_qtgrpcclient/CMakeLists.txt Configures Protobuf code generation for the benchmark executable. It specifies the proto files to process and the output directory for generated code, utilizing well-known types from Qt::ProtobufWellKnownTypes. ```cmake qt_add_protobuf(bench_qtgrpcclient PROTO_FILES "${proto_path}" OUTPUT_DIRECTORY "${proto_out_dir}" PROTO_INCLUDES $ ) ``` -------------------------------- ### Link Libraries for Protobuf Sensors Client Source: https://github.com/qt/qtgrpc/blob/dev/examples/protobuf/sensors/client/CMakeLists.txt Specifies the libraries to be linked with the protobuf_sensors_client executable. This includes Qt modules and a custom protobuf_sensors library. ```cmake target_link_libraries(protobuf_sensors_client PRIVATE Qt6::Core Qt6::Protobuf Qt6::Widgets Qt6::Network protobuf_sensors ) ``` -------------------------------- ### Generate gRPC Protocol Buffer Sources Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/test_server/CMakeLists.txt Generates C++ header and source files for gRPC services from a .proto file using protoc and grpc_cpp_plugin. Includes experimental flags for specific protoc versions. ```cmake set(proto_files "${CMAKE_CURRENT_LIST_DIR}/../../../shared/proto/testservice.proto") set(out_dir ${CMAKE_CURRENT_BINARY_DIR}) set(generated_files "${out_dir}/testservice.pb.h" "${out_dir}/testservice.pb.cc" "${out_dir}/testservice.grpc.pb.h" "${out_dir}/testservice.grpc.pb.cc") set(extra_protoc_args "") get_target_property(protoc_version WrapProtoc::WrapProtoc _qt_internal_protobuf_version) if(protoc_version VERSION_GREATER_EQUAL "3.12" AND protoc_version VERSION_LESS "3.15") list(APPEND extra_protoc_args "--experimental_allow_proto3_optional") endif() add_custom_command( OUTPUT ${generated_files} COMMAND $ ARGS ${extra_protoc_args} --grpc_out "${out_dir}" --cpp_out "${out_dir}" -I "${CMAKE_CURRENT_LIST_DIR}/../../../shared/proto/" --plugin=protoc-gen-grpc=${grpc_cpp_plugin} "${proto_files}" WORKING_DIRECTORY ${out_dir} DEPENDS "${proto_files}" $ COMMENT "Generating gRPC ${target} sources..." COMMAND_EXPAND_LISTS VERBATIM ) ``` -------------------------------- ### Generate Protobuf Code for Basic Messages Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/basic/CMakeLists.txt Generates C++ code from protobuf definition files using qt6_add_protobuf. The generated code is placed in a specified output directory. This is used for basic message types. ```cmake qt6_add_protobuf(tst_protobuf_basictypes_gen PROTO_FILES proto/basicmessages.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" ) qt_autogen_tools_initial_setup(tst_protobuf_basictypes_gen) ``` -------------------------------- ### Adding a Qt gRPC Client Unary Call Test Target Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpcquick/client/unarycall/CMakeLists.txt Defines the main test executable for the gRPC client unary call. It specifies sources, include directories, preprocessor definitions including the path to the test server, and required Qt libraries. ```cmake qt_internal_add_test(tst_grpc_client_unarycall_qml QMLTEST SOURCES tst_grpc_client_unarycall_qml.cpp INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/../../../grpc/shared DEFINES TEST_GRPC_SERVER_PATH="$" LIBRARIES Qt::Qml Qt::Grpc ) ``` -------------------------------- ### gRPC Client Code Generation Source: https://github.com/qt/qtgrpc/blob/dev/tests/manual/grpc/benchmarks/bench_qtgrpcclient/CMakeLists.txt Configures gRPC client code generation for the benchmark executable. Similar to Protobuf generation, it specifies proto files and output directories, ensuring compatibility with Qt::ProtobufWellKnownTypes. ```cmake qt_add_grpc(bench_qtgrpcclient CLIENT PROTO_FILES "${proto_path}" OUTPUT_DIRECTORY "${proto_out_dir}" PROTO_INCLUDES $ ) ``` -------------------------------- ### Generate Protobuf Code Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/nested/CMakeLists.txt Generates C++ code from .proto files using qt6_add_protobuf. This command processes nested messages and external packages, outputting generated code to a specified directory. ```cmake qt6_add_protobuf(tst_protobuf_nestedtypes_qtprotobuf_gen PROTO_FILES proto/nestedmessages.proto proto/externalpackage.proto OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated" ) ``` -------------------------------- ### Define gRPC Test Server Path Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/shared/client_test_common/CMakeLists.txt Sets a compile definition for the gRPC test server binary path, used for locating test assets. ```cmake target_compile_definitions(tst_grpc_client_test_common PRIVATE TEST_GRPC_SERVER_PATH="$" ) ``` -------------------------------- ### Generate Protobuf Code with Custom Output Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/grpc/client/interceptors/CMakeLists.txt Invokes protobuf_generate to create C++ code from .proto files, specifying target, import directories, and a custom output directory for server-side generated files. ```cmake protobuf_generate( PROTOS ${proto_files} TARGET tst_grpc_client_interceptors IMPORT_DIRS ${proto_import} PROTOC_OUT_DIR ${proto_out_server} ) ``` -------------------------------- ### Add Test Executable Source: https://github.com/qt/qtgrpc/blob/dev/tests/auto/protobuf/nested/CMakeLists.txt Adds a test executable using qt_internal_add_test. This function configures the test with specified sources, include directories, and links against necessary Qt libraries, including the generated protobuf code. ```cmake qt_internal_add_test(tst_protobuf_nestedtypes SOURCES tst_protobuf_nestedtypes.cpp INCLUDE_DIRECTORIES ../shared LIBRARIES Qt::Test Qt::Protobuf tst_protobuf_nestedtypes_qtprotobuf_gen ) ```