FindProtobuf¶
Locate and configure the Google Protocol Buffers library.
The following variables can be set and are optional:
PROTOBUF_SRC_ROOT_FOLDERWhen 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_DIRSList of additional directories to be searched for imported .proto files.
Defines the following variables:
PROTOBUF_FOUNDFound the Google Protocol Buffers library (libprotobuf & header files)
PROTOBUF_INCLUDE_DIRSInclude directories for Google Protocol Buffers
PROTOBUF_LIBRARIESThe protobuf libraries
PROTOBUF_PROTOC_LIBRARIESThe protoc libraries
PROTOBUF_LITE_LIBRARIESThe protobuf-lite libraries
The following cache variables are also available to set or use:
PROTOBUF_LIBRARYThe protobuf library
PROTOBUF_PROTOC_LIBRARYThe protoc library
PROTOBUF_INCLUDE_DIRThe include directory for protocol buffers
PROTOBUF_PROTOC_EXECUTABLEThe protoc compiler
PROTOBUF_LIBRARY_DEBUGThe protobuf library (debug)
PROTOBUF_PROTOC_LIBRARY_DEBUGThe protoc library (debug)
PROTOBUF_LITE_LIBRARYThe protobuf lite library
PROTOBUF_LITE_LIBRARY_DEBUGThe 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_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
.protofiles to C++:protobuf_generate_cpp (<SRCS> <HDRS> [<ARGN>...])
SRCSVariable to define with autogenerated source files
HDRSVariable to define with autogenerated header files
ARGN.protofiles
-
protobuf_generate_python¶ Add custom commands to process
.protofiles to Python:protobuf_generate_python (<PY> [<ARGN>...])
PYVariable to define with autogenerated Python files
ARGN.protofiless