diff --git a/Help/release/3.4.rst b/Help/release/3.4.rst index e17e6ad515..ee7bf27637 100644 --- a/Help/release/3.4.rst +++ b/Help/release/3.4.rst @@ -140,7 +140,7 @@ Modules (such as for related tools or data and plugin install paths). * The :module:`FindProtobuf` module gained a new - :command:`protobuf_generate_python` function to generate python + :command:`protobuf_generate_python` command to generate Python sources from ``.proto`` files. * The :module:`FindTIFF` module learned to search separately for diff --git a/Help/release/dev/FindProtobuf.rst b/Help/release/dev/FindProtobuf.rst index b346403c64..3be51ffa9d 100644 --- a/Help/release/dev/FindProtobuf.rst +++ b/Help/release/dev/FindProtobuf.rst @@ -3,3 +3,7 @@ FindProtobuf * The :module:`FindProtobuf` module's :command:`protobuf_generate(DEPENDENCIES)` command argument now accepts multiple values. +* The :module:`FindProtobuf` module's commands :command:`protobuf_generate_cpp` + and :command:`protobuf_generate_python` together with their hint variables + ``Protobuf_IMPORT_DIRS`` and ``PROTOBUF_GENERATE_CPP_APPEND_PATH`` are now + deprecated in favor of :command:`protobuf_generate`. diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index b46d9a9bf2..4402afa43a 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -5,204 +5,211 @@ FindProtobuf ------------ -Locate and configure the Google Protocol Buffers library. +.. note:: -.. versionadded:: 3.6 - Support for :command:`find_package` version checks. + If the Protobuf library is built and installed using its CMake-based + build system, it provides a :ref:`package configuration file + ` for use with the :command:`find_package` command + in *config mode*: -.. versionchanged:: 3.6 - All input and output variables use the ``Protobuf_`` prefix. - Variables with ``PROTOBUF_`` prefix are still supported for compatibility. + .. code-block:: cmake -The following variables can be set and are optional: + find_package(Protobuf CONFIG) -``Protobuf_SRC_ROOT_FOLDER`` - When compiling with MSVC, if this cache variable is set - the protobuf-default VS project build locations - (vsprojects/Debug and vsprojects/Release - or vsprojects/x64/Debug and vsprojects/x64/Release) - will be searched for libraries and binaries. -``Protobuf_IMPORT_DIRS`` - List of additional directories to be searched for - imported .proto files. -``Protobuf_DEBUG`` - .. versionadded:: 3.6 + In this case, imported targets and CMake commands such as + :command:`protobuf_generate` are provided by the upstream package rather + than this module. Additionally, some variables documented here are not + available in *config mode*, as imported targets are preferred. For usage + details, refer to the upstream documentation, which is the recommended + way to use Protobuf with CMake. - Show debug messages. -``Protobuf_USE_STATIC_LIBS`` - .. versionadded:: 3.9 + This module works only in *module mode*. - Set to ON to force the use of the static libraries. - Default is OFF. - -Defines the following variables: - -``Protobuf_FOUND`` - Found the Google Protocol Buffers library - (libprotobuf & header files) -``Protobuf_VERSION`` - .. versionadded:: 3.6 - - Version of package found. -``Protobuf_INCLUDE_DIRS`` - Include directories for Google Protocol Buffers -``Protobuf_LIBRARIES`` - The protobuf libraries -``Protobuf_PROTOC_LIBRARIES`` - The protoc libraries -``Protobuf_LITE_LIBRARIES`` - The protobuf-lite libraries - -.. versionadded:: 3.9 - The following :prop_tgt:`IMPORTED` targets are also defined: - -``protobuf::libprotobuf`` - The protobuf library. -``protobuf::libprotobuf-lite`` - The protobuf lite library. -``protobuf::libprotoc`` - The protoc library. -``protobuf::protoc`` - .. versionadded:: 3.10 - The protoc compiler. - -The following cache variables are also available to set or use: - -``Protobuf_LIBRARY`` - The protobuf library -``Protobuf_PROTOC_LIBRARY`` - The protoc library -``Protobuf_INCLUDE_DIR`` - The include directory for protocol buffers -``Protobuf_PROTOC_EXECUTABLE`` - The protoc compiler -``Protobuf_LIBRARY_DEBUG`` - The protobuf library (debug) -``Protobuf_PROTOC_LIBRARY_DEBUG`` - The protoc library (debug) -``Protobuf_LITE_LIBRARY`` - The protobuf lite library -``Protobuf_LITE_LIBRARY_DEBUG`` - The protobuf lite library (debug) - -Example: +This module finds the Protocol Buffers library (Protobuf) in *module mode*: .. code-block:: cmake - find_package(Protobuf REQUIRED) - include_directories(${Protobuf_INCLUDE_DIRS}) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto) - protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS EXPORT_MACRO DLL_EXPORT foo.proto) - protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS DESCRIPTORS PROTO_DESCS foo.proto) - protobuf_generate_python(PROTO_PY foo.proto) - add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS}) - target_link_libraries(bar ${Protobuf_LIBRARIES}) + find_package(Protobuf [] [...]) -.. note:: - The ``protobuf_generate_cpp`` and ``protobuf_generate_python`` - functions and :command:`add_executable` or :command:`add_library` - calls only work properly within the same directory. +Protobuf is an open-source, language-neutral, and platform-neutral mechanism +for serializing structured data, developed by Google. It is commonly used +for data exchange between programs or across networks. -.. command:: protobuf_generate_cpp +.. versionadded:: 3.6 + Support for the ```` argument in + :command:`find_package(Protobuf \)`. - Add custom commands to process ``.proto`` files to C++: +.. versionchanged:: 3.6 + All input and output variables use the ``Protobuf_`` prefix. Variables + with ``PROTOBUF_`` prefix are supported for backward compatibility. - .. code-block:: cmake +Imported Targets +^^^^^^^^^^^^^^^^ - protobuf_generate_cpp ( - - [DESCRIPTORS ] - [EXPORT_MACRO ] - [...]) +This module provides the following :ref:`Imported Targets`: - ```` - Variable to define with autogenerated source files +``protobuf::libprotobuf`` + .. versionadded:: 3.9 - ```` - Variable to define with autogenerated header files + Target encapsulating the Protobuf library usage requirements, available if + Protobuf library is found. - ``DESCRIPTORS `` - .. versionadded:: 3.10 - Variable to define with autogenerated descriptor files, if requested. +``protobuf::libprotobuf-lite`` + .. versionadded:: 3.9 - ``EXPORT_MACRO `` - is a macro which should expand to ``__declspec(dllexport)`` or - ``__declspec(dllimport)`` depending on what is being compiled. + Target encapsulating the ``protobuf-lite`` library usage requirements, + available if Protobuf and its lite library are found. - ``...`` - ``.proto`` files +``protobuf::libprotoc`` + .. versionadded:: 3.9 -.. command:: protobuf_generate_python + Target encapsulating the ``protoc`` library usage requirements, available + if Protobuf and its ``protoc`` library are found. - .. versionadded:: 3.4 +``protobuf::protoc`` + .. versionadded:: 3.10 - Add custom commands to process ``.proto`` files to Python: + Imported executable target encapsulating the ``protoc`` compiler usage + requirements, available if Protobuf and ``protoc`` are found. - .. code-block:: cmake +Result Variables +^^^^^^^^^^^^^^^^ - protobuf_generate_python ( [...]) +This module defines the following variables: - ```` - Variable to define with autogenerated Python files +``Protobuf_FOUND`` + Boolean indicating whether (the requested version of) Protobuf library is + found. +``Protobuf_VERSION`` + .. versionadded:: 3.6 - ``...`` - ``.proto`` files + The version of Protobuf found. +``Protobuf_INCLUDE_DIRS`` + Include directories needed to use Protobuf. +``Protobuf_LIBRARIES`` + Libraries needed to link against to use Protobuf. +``Protobuf_PROTOC_LIBRARIES`` + Libraries needed to link against to use the ``protoc`` library. +``Protobuf_LITE_LIBRARIES`` + Libraries needed to link against to use the ``protobuf-lite`` library. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``Protobuf_INCLUDE_DIR`` + The include directory containing Protobuf headers. +``Protobuf_LIBRARY`` + The path to the ``protobuf`` library. +``Protobuf_PROTOC_LIBRARY`` + The path to the ``protoc`` library. +``Protobuf_PROTOC_EXECUTABLE`` + The path to the ``protoc`` compiler. +``Protobuf_LIBRARY_DEBUG`` + The path to the ``protobuf`` debug library. +``Protobuf_PROTOC_LIBRARY_DEBUG`` + The path to the ``protoc`` debug library. +``Protobuf_LITE_LIBRARY`` + The path to the ``protobuf-lite`` library. +``Protobuf_LITE_LIBRARY_DEBUG`` + The path to the ``protobuf-lite`` debug library. +``Protobuf_SRC_ROOT_FOLDER`` + When compiling with MSVC, if this cache variable is set, the + protobuf-default Visual Studio project build locations will be searched for + libraries and binaries: + + * ``/vsprojects/{Debug,Release}``, or + * ``/vsprojects/x64/{Debug,Release}`` + +Hints +^^^^^ + +This module accepts the following optional variables before calling the +``find_package(Protobuf)``: + +``Protobuf_DEBUG`` + .. versionadded:: 3.6 + + Boolean variable that enables debug messages of this module to be printed + for debugging purposes. + +``Protobuf_USE_STATIC_LIBS`` + .. versionadded:: 3.9 + + Set to ON to force the use of the static libraries. Default is OFF. + +Commands +^^^^^^^^ + +This module provides the following commands if Protobuf is found: + +Generating Source Files +""""""""""""""""""""""" .. command:: protobuf_generate .. versionadded:: 3.13 - Automatically generate source files from ``.proto`` schema files at build time: + Automatically generates source files from ``.proto`` schema files at build + time: .. code-block:: cmake - protobuf_generate ( - TARGET - [LANGUAGE ] - [OUT_VAR ] - [EXPORT_MACRO ] - [PROTOC_OUT_DIR ] - [PLUGIN ] - [PLUGIN_OPTIONS ] - [DEPENDENCIES ...] - [PROTOS ...] - [IMPORT_DIRS ...] - [GENERATE_EXTENSIONS ...] - [PROTOC_OPTIONS