Locate and configure the Google Protocol Buffers library.
The following variables can be set and are optional:
Protobuf_SRC_ROOT_FOLDER
Protobuf_IMPORT_DIRS
Protobuf_DEBUG
Protobuf_USE_STATIC_LIBS
Defines the following variables:
Protobuf_FOUND
Protobuf_VERSION
Protobuf_INCLUDE_DIRS
Protobuf_LIBRARIES
Protobuf_PROTOC_LIBRARIES
Protobuf_LITE_LIBRARIES
The following IMPORTED
targets are also defined:
protobuf::libprotobuf
protobuf::libprotobuf-lite
protobuf::libprotoc
protobuf::protoc
The following cache variables are also available to set or use:
Protobuf_LIBRARY
Protobuf_PROTOC_LIBRARY
Protobuf_INCLUDE_DIR
Protobuf_PROTOC_EXECUTABLE
Protobuf_LIBRARY_DEBUG
Protobuf_PROTOC_LIBRARY_DEBUG
Protobuf_LITE_LIBRARY
Protobuf_LITE_LIBRARY_DEBUG
Example:
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 add_executable()
or add_library()
calls only work properly within the same directory.
protobuf_generate_cpp
Add custom commands to process .proto
files to C++:
protobuf_generate_cpp (<SRCS> <HDRS> [DESCRIPTORS <DESC>] [EXPORT_MACRO <MACRO>] [<ARGN>...])
SRCS
HDRS
DESCRIPTORS
EXPORT_MACRO
__declspec(dllexport)
or __declspec(dllimport)
depending on what is being compiled.ARGN
.proto
filesprotobuf_generate_python
Add custom commands to process .proto
files to Python:
protobuf_generate_python (<PY> [<ARGN>...])
PY
ARGN
.proto
filess
© 2000–2019 Kitware, Inc. and Contributors
Licensed under the BSD 3-clause License.
https://cmake.org/cmake/help/v3.15/module/FindProtobuf.html