Commit Graph

34 Commits

Author SHA1 Message Date
Alexey Edelev 2bed0bc836 Make sure that we require the cpp exports
When building static libraries or shared libraries on Windows platforms
we need to make sure that _protobuf_registration targets depend on the
generated cpp exports. This add the header file containing exports as
the source file to the _protobuf_registration targets and also
makes sure that we add the dependencies when using both qt_add_protobuf
and qt_add_grpc calls on the same target.

Pick-to: 6.7
Change-Id: Ibc6c04e363093c54dc7ff1725fc6e816b3c9ffdf
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2024-02-21 11:52:57 +01:00
Alexey Edelev ae2f1ed3d3 Fix the generation of the export macro
Consider the EXPORT_MACRO CMake argument of qt_add_<protobuf|grpc>
calls.

Add the support for the EXPORT_MACRO option extras to the
qt<protobuf|grpc>gen generators. The extras now allow setting:
 - export file name
 - boolean flag that indicates if export file needs to be generated

The EXPORT_MACRO option of the generators now has the following format:
   EXPORT_MACRO=<export_name>[:export_filename[:<true|false>]]

If export_filename is not set, then generators fall back to the previos
behavior and use the export_name as the export filename base, the file
will be generated unconditionally. If export_filename is set and the
follow boolean flag is not set or is set to false, generators skip the
generating of the export file.

[ChangeLog][Protobuf][qtprotobufgen] EXPORT_MACRO option now has the
following format:
    EXPORT_MACRO=<export_name>[:export_filename[:<true|false>]]
New option extras allow setting the generated export filename and
control if it should be generated at the generator run.
[ChangeLog][GRPC][qtgrpcgen] EXPORT_MACRO option now has the
following format:
    EXPORT_MACRO=<export_name>[:export_filename[:<true|false>]]
New option extras allow setting the generated export filename and
control if it should be generated at the generator run.

Pick-to: 6.7
Fixes: QTBUG-121854
Change-Id: Ifff6506ab363d18dc417f222e9929d7eba135d8a
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2024-02-06 06:59:48 +01:00
Alexey Edelev 4a354e65b8 Add output directory to the include paths
Add the protobuf output directory to the target include paths in a
build interface.

Pick-to: 6.7 6.6 6.5
Change-Id: I75fabb9b21267221b66a42fd118a78fe4fd80f9c
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2024-02-05 15:12:13 +01:00
Alexey Edelev 3f6f829ea7 Only allow using cached generated files when CMake generator is Ninja-like
Allow using the cached protobuf/grpc generated files only when the
CMake generator is Ninja-like. Other generators may ignore/not support
the add_custom_command by-products.

This shouldn't affect any officially supported build scenario, since
this feature is only applicable for QtGrpc builds, but not user
projects and we only officially support Ninja-like generators.

Ammends 152fe1748da638a1af1a7beedab8f3718432a607

Pick-to: 6.5 6.6 6.7
Task-number: QTBUG-121544
Change-Id: I339578500afd561d863550b2c6e24940a7231775
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2024-01-29 10:53:31 +01:00
Alexey Edelev d2a9d9d8c3 Add the temporary files produced by qt<protobuf|grpc>gen to BYPRODUCTS
Force Ninja to consider the temporary files produced by
qt<protobuf|grpc>gen. Timestamp of these files still has no effect on
the "main" dependency chain in developer builds, but if files were
changed during generating process, Ninja will rerun copy_if_different
rules.

Fixes: QTBUG-121544
Pick-to: 6.5 6.6 6.7
Change-Id: I7e3780d971cca9ae132b88ed2e927eb12e6bb551
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2024-01-29 10:53:28 +01:00
Alexey Edelev c649de9633 Enable AUTOMOC for Qt GRPC and Qt Protobuf targets unconditionally
We should enable AUTOMOC for all types of targets support by modules.
The current condition breaks executables and modules(plugins).

Pick-to: 6.7 6.6 6.5
Change-Id: I4c078d4dbadbbb26b2eb393da729a4d2c808de1b
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2024-01-12 14:44:45 +01:00
Tatiana Borisova faef75c24c qt_add_protobuf() warns a user about adding duplicated proto file names
Task-number: QTBUG-114079
Pick-to: 6.7 6.6 6.5
Change-Id: I08c618d9f656ad26d88301eb40b2f002460771d6
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
2024-01-11 17:32:02 +01:00
Alexey Edelev c7b93781ce Add '-mbig-obj' for all protobuf targets
Increase number of sections in object files if MinGW compiler is used.
We do the same for MSVC already.

Pick-to: 6.7 6.6 6.5
Change-Id: Ibc469809048db462e2e2c7b3236de801b6395d93
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
2023-12-16 13:53:09 +01:00
Alexey Edelev 8a32a7c8b9 Add "--experimental_allow_proto3_optional" for legacy protoc versions
The protoc tool doesn't support field presence for proto3 syntax in
versions less than 3.15. In versions higher than or equal to 3.12 the
support can be enabled using the --experimental_allow_proto3_optional
flag.

This fixes the build issue in LTS Ubuntu.

Pick-to: 6.5 6.6
Change-Id: I3b897139e184c307e8d21839cca3aa9fdc9d9f7f
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-11-24 16:12:13 +01:00
Alexey Edelev 98eb2a9e34 Allow adding protobuf types to the existing QML module
We should allow adding protobuf types to the existing QML modules.
This will allow users to create customized QML module targets and
compliment them with protobuf types. The qt_add_protobuf function
still requires the single package name for all .proto files passed
to the function. Also if QML_URI is passed to a qt_add_protobuf
call and target is QML module already, QML_URI argument will be
ignored. The target now collects protobuf package names in the
QT_PROTOBUF_PACKAGES variable.

Amends 0e6a605867

Pick-to: 6.6
Change-Id: I2cdaddb829be6b1ec32a3123d2bbf5136024d087
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
2023-11-08 08:05:00 +01:00
Tatiana Borisova dd897eea93 Move C++ definitions to a common header file
Task-number: QTBUG-116045
Change-Id: I000c08318e748109782603a620686e2252fc4511
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-10-26 12:01:39 +02:00
Alexey Edelev c9f05c32a5 Wrap PROTOC_ARGS with quotes to 'mark' them as the single argument
Somehow CMake does not really good job on escaping the arguments
we pass using PROTOC_ARGS. For VS generators it even wraps each
semicolon with quotes. Not sure if it's CMake-user bug or CMake
bug, but since the fix is easy, we probably shouldn't care much.

Pick-to: 6.5 6.6
Fixes: QTBUG-116463
Change-Id: I9b8db8ecce2e88134b708b5530e459572ac93e36
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-08-26 11:18:13 +02:00
Alexey Edelev b089a773e9 Move enums to the nested namespace out of class
Protobuf allows the following construction:
  message A {
      enum AEnum {
        AVal0 = 0;
      }
      B.BEnum val = 1;
  }
  message B {
      enum BEnum {
          BVal0 = 0;
      }
      A.AEnum val = 1;
  }

This requires forward declaration of nested enums, that is not possible
in C++. To solve this problem we may do the same trick that we do
for nested messages already.
This patch moves the nested enum type out of class to the
_QtProtobufNested namespace. The solution require the enum name
specification when using enums from this moment, since the owning
messages only contain type aliases now. So from example above to access
the AVal0 you need to use the full qualifier:
  A::AEnum::AVal0

The new generated code structure registrates Qml types using the built-in
macros, that unlocks direct linking of backing library without the need
of Qml plugin usage.

[ChangeLog][Protobuf] Nested enums moved out of message classes to the
nested namespace, same as the nested messages.

[ChangeLog][Protobuf][Qml] The geneated protobuf Qml modules do not
require the use of Qml plugins.

Fixes: QTBUG-115800
Change-Id: Ia67fcbecf492c3fd41350eada4d62fc9e5ea4dab
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-08-18 19:01:25 +02:00
Alexey Edelev b839d2d757 Filter the brackets from .proto file content
The recent finding from CMake shown that if list contain the
open bracket '[', CMake ignores any semicolon separators as this
list chunk is treated as escaped string until the closing bracket
is faced. This happened with .proto files that have the open
bracket at one line and the closing bracket on another one, or
even miss the closing bracket.

Remove all brackets preliminary from .proto file content to make sure
we don't hit this issue.

Note: We are not interested in brackets in this parser.

Pick-to: 6.5 6.6
Fixes: QTBUG-116043
Change-Id: I282e1f4a93db4486fde0370045c22d1c8ecf9afa
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
2023-08-18 14:00:34 +02:00
Alexey Edelev 822d8b12fd Make sure that .proto files are displayed in IDE
Add .proto files using _qt_internal_expose_source_file_to_ide.

Pick-to: 6.5 6.6
Fixes: QTBUG-115057
Change-Id: I5051e4554ba3bc7a7c261de5a1e7b7c503021df1
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-07-27 11:55:23 +02:00
Alexey Edelev 6dda607f6d Fix the GENERATE_PACKAGE_SUBFOLDERS option for Qml modules
Add the missing include directory to workaround QTBUG-115499.
Make sure that '$<TARGET_PROPERTY' genex is evaluated for
_protobuf_registration targets.

TODO: Extra include directories should be removed since they might
lead to ambiguous include records if .proto files contain messages
with same name but in different protobuf packages.

Fixes: QTBUG-114077
Task-number: QTBUG-115499
Pick-to: 6.6
Change-Id: Ifb9002435b20034967f202a5dc94ec51a3704f64
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-07-26 15:43:32 +02:00
Alexey Edelev e9f6546483 Create both plugin and backing library in qt_add_protobuf
This approach allows reusing the existing backing target if it's
library and makes step towards plugin-less Qml module.

Pick-to: 6.6
Task-number: QTBUG-115117
Change-Id: I02243d700683ac9e01c1471c3ccccaae71841165
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-07-25 10:18:07 +02:00
Alexey Edelev 16713c6e32 Refactor _qt_internal_protobuf_preparse_proto_files
Move the logic that is unreleated to the pre-parsing of the .proto
files to the qt6_add_protobuf function. This leave the single
responsibility for _qt_internal_protobuf_preparse_proto_files and
unlocks the file manipulations for the furter Qml API improvements.

Pick-to: 6.6
Task-number: QTBUG-114077
Task-number: QTBUG-104513
Change-Id: I9d18fbb5d26be1ffb19844cb7d7c3f8736136a76
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-07-25 10:17:59 +02:00
Alexey Edelev 66e5efc5ec Use the type of the created protobuf/grpc library but don't predict it
BUILD_SHARED_LIBS cmake flag usually indicates the type of library
that will be created by the cmake add_library call. This solution
doesn't work with _qt_internal_add_library since the logic of library
creation differs there.

Instead of predicting, let's rely on creation result.

Pick-to: 6.6 6.5
Change-Id: Ie983b30377f1e0f3f42fdbb1a6dc8ec340770ee5
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-07-06 18:37:30 +02:00
Piotr Wierciński 367e153793 CMake: Fix evaluating generator expressions recursively
Make sure that TARGET_PROPERTY will be properly
evaluated as recursive generator expression.

Pick-to: 6.5 6.6
Change-Id: Ia51f01a386c97ef543b44393081db693dd07a334
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-06-29 06:55:15 +00:00
Tatiana Borisova 0b270e4602 Add qt_add_qml_module to qt_add_protobuf function for QML generation
In case of generating Qt protobuf source code with QML argument,
QML plugin will be created and included into Application build tree.

New QML_URI option is introduced. If there is no package name,
qtprotobufgen must request the QML_URI setting.

Also, it is possible to link several *.proto files to the same plugin
via common URI.

Add nopackage auto-test. Update protobufgen auto-test.
Remove the usage of RESOURCE_PREFIX, replaced by qt_policy.

Task-number: QTBUG-104513
Change-Id: If5c5496245144fa2b499730ab9fdf7d0ee7b2c25
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
2023-06-01 12:44:22 +02:00
Alexey Edelev 0b14713b1e Fix arguments for _qt_internal_protoc_generate
Fix the function arguments processing. Both generated_files and
generation_options were visible because of scope visibility and
were not processed by _qt_internal_protoc_generate correctly.
Fix this by using and processing arguments the proper way.

Pick-to: 6.5
Change-Id: I1eaad92cecfd9d8b415ec2d06cb947979d6baba6
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2023-05-31 17:01:53 +02:00
Tatiana Borisova 0e6a605867 Add enum registration logic and enums-test in QML
QtProtobufgen registers global and local enums in QML context now.
Registration is in qml extension plugin part.

Task-number: QTBUG-104513
Change-Id: Iecbc08d4b915113e7d5753b1f1d24d3c34088ba2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-17 17:07:02 +02:00
Tatiana Borisova 21e208ec96 QtProtobuf: add QML support
Enable QML flag for qtgrpcgen/qtprotobufgen plugins.
Generated output is updated: QProtobufMessage classes are Q_GADGETs,
such classes can be registered in QML code via QML_VALUE_TYPE macros only.
Also QProtobufMessages are not inherited from QObject class, it means
there is no full qmetaobject system support (no signals!).

Task-number: QTBUG-104513
Change-Id: I18c8f93782884efb8d923843df716ff8284ed8fb
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-05-04 12:35:22 +03:00
Alexey Edelev 6ad476257c Fix the way proto includes assembled into a single command
The CMake list(JOIN command doesn't expand the generator expressions
before merging the list. This leads to the situation when generator
expressions that are empty string after the evaluation put an empty
-I argument to a protoc command line. Using '$<JOIN ' generator
expression we avoid this situation since list will be assembled into
argument only after evauation of the all nested genertor expressions.

Pick-to: 6.5
Change-Id: Ibbb141a46e89bb71c6f6151c70b7ec754b44355f
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-02-10 18:33:04 +01:00
Alexey Edelev 227557ad36 Avoid adding the generated header files to PUBLIC_HEADERS by default
This should be done by the qt_add_protobuf/grpc functions caller
instead. Otherwise this could break exising deployment rules, like it
happens for qt protobuf modules.

Amends 326ebfaadb

Pick-to: 6.5
Change-Id: I79e562cf1a0041b4bf7fc550b69dfa7fa41cb862
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-02-02 18:28:11 +01:00
Alexey Edelev 50b9027829 Use temporary directory for the generated protobuf sources
protoc doesn't check if file content is changed when writing data to
a generated file. This triggers rebuild of all the generated source
files even after minor changes in qtprotobuf/qtgrpcgen code. Use a
temporary output directory for the files generated by protoc and
copy them to a real output directory only if they are different from
previously generated files. This trick avoids rebuilding all the
generated source files that are not changed when debugging
qtprotobuf/qtgrpcgen.

The introduced behavior doesn't work if the generator executable is
imported or can be suppressed by setting the
QT_INTERNAL_AVOID_USING_PROTOBUF_TMP_OUTPUT_DIR option when configuring
qtgrpc repo.

Pick-to: 6.5
Change-Id: I8acbc3528298ecf3a266a7a0e33c34c3fb8e6527
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-01-11 16:24:44 +01:00
Alexey Edelev 907b8077d0 Allow using generator expressions in PROTO_INCLUDES argument
As user may want to use generator expressions like in PROTO_INCLUDES
argument we need to add their evaluation before passing the merged
list to the command line.

Pick-to: 6.5
Change-Id: I4ab41ee42ff051e76882eac696af5eed315359c9
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2023-01-11 16:24:34 +01:00
Tatiana Borisova 326ebfaadb QtGrpc: Update code generator to generate gRPC structures
Split the .proto files generator into QtProtobuf and QtGrpc parts.

Pick-to: 6.5
Task-number: QTBUG-105496
Change-Id: Ib43abe4c1fb849ecf68952b82af9d3988e88e02a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2023-01-11 12:04:11 +01:00
Konrad Kujawa 0d56724387 Introduce QtGrpc
QtGrpc provides support for serializing and deserializing
gRPC services using Qt.

The tool was originally written by Alexey Edelev, along with various
contributors, on GitHub. Originally under MIT license, but major
contributors have agreed to relicense the code under GPL/commercial for
inclusion in tools for Qt. Their copyright notice is retained and
the original source code, still licensed as MIT, can be found in its
original repository[0].

[0]: https://github.com/semlanik/qtprotobuf

Change-Id: Id29e70df1249e9369fbfaa2c543f3ff29efbdbea
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-12-09 15:00:04 +01:00
Alexey Edelev d0047b2846 Rename qtprotobufgen options
Rename:
  FOLDER option to GENERATE_PACKAGE_SUBFOLDERS
  COMMENTS option to COPY_COMMENTS
  OUT_GENERATED_HEADERS option to OUTPUT_HEADERS
  OUT_GENERATED_TARGETS option to OUTPUT_TARGETS

Adjust and cleanup the corresponding documentation.

Change-Id: I2fdeaaba89257c8bbca4389a08119abf3158702f
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-12-07 12:29:45 +01:00
Alexey Edelev 270b37f462 Remove FIELD_ENUM option
Oneof fields depend on the enum that contains field numbers. Enable
the option by default.

Change-Id: I4d5dd63f328d26bdce15d6310489c4146fbf5c0d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-12-07 12:29:45 +01:00
Alexey Edelev 964249aaa4 Add protoc-native way of option handling
The protoc tool has the generic mechanisms for plugin option handling.
The plugin-specific options can be specified using the
--<plugin_name>_opt argument or by prepending options to the
--<plugin_name>_out argument with colon separator. In both cases
options need to be separated by semicolon. Add the processing of this
argument to generator and use --<plugin_name>_opt as the default one
in CMake API. Also adjust format of the QT_PROTOBUF_OPTIONS environment
variable to make them consistent.

Change-Id: I269ca7b9b2a952d0d30b18cb57c1465ae261c83a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-11-08 12:03:14 +01:00
Mårten Nordheim fffdeaea77 Long live qtprotobufgen
The generator generates Qt-based classes to be used in conjunction with
'QProtobuf' (separate patch).

qtprotobufgen works as an extension to the protoc tool from Google, and
thus also depends on its libraries for building.

The tool was originally written by Alexey Edelev, along with various
contributors, on GitHub. Originally under MIT license, but major
contributors have agreed to relicense the code under GPL/commercial for
inclusion in tools for Qt. Their copyright notice is retained and
the original source code, still licensed as MIT, can be found in its
original repository[0].

[0]: https://github.com/semlanik/qtprotobuf

Done-with: Alexey Edelev <alexey.edelev@qt.io>
Change-Id: I0d5f3d722cb98bca70fc0d4544ed840edb27430c
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
2022-11-08 10:33:39 +01:00