# Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: FindProtobuf ------------ Locate and configure the Google Protocol Buffers library. .. versionadded:: 3.6 Support for :command:`find_package` version checks. .. versionchanged:: 3.6 All input and output variables use the ``Protobuf_`` prefix. Variables with ``PROTOBUF_`` prefix are still supported for compatibility. The following variables can be set and are optional: ``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 Show debug messages. ``Protobuf_USE_STATIC_LIBS`` .. versionadded:: 3.9 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: .. 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}) .. 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. .. command:: protobuf_generate_cpp Add custom commands to process ``.proto`` files to C++:: protobuf_generate_cpp ( [DESCRIPTORS ] [EXPORT_MACRO ] [...]) ```` Variable to define with autogenerated source files ```` Variable to define with autogenerated header files ``DESCRIPTORS `` .. versionadded:: 3.10 Variable to define with autogenerated descriptor files, if requested. ``EXPORT_MACRO `` is a macro which should expand to ``__declspec(dllexport)`` or ``__declspec(dllimport)`` depending on what is being compiled. ``...`` ``.proto`` files .. command:: protobuf_generate_python .. versionadded:: 3.4 Add custom commands to process ``.proto`` files to Python:: protobuf_generate_python ( [...]) ```` Variable to define with autogenerated Python files ``...`` ``.proto`` files .. command:: protobuf_generate .. versionadded:: 3.13 Automatically generate source files from ``.proto`` schema files at build time:: protobuf_generate ( TARGET [LANGUAGE ] [OUT_VAR ] [EXPORT_MACRO ] [PROTOC_OUT_DIR ] [PLUGIN ] [PLUGIN_OPTIONS ] [DEPENDENCIES ] [PROTOS ...] [IMPORT_DIRS ...] [GENERATE_EXTENSIONS ...] [PROTOC_OPTIONS