FindProtobuf¶
Locate and configure the Google Protocol Buffers library.
New in version 3.6: Support for find_package() version checks.
Changed in version 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_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.
Protobuf_DEBUGNew in version 3.6.
Show debug messages.
Protobuf_USE_STATIC_LIBSNew in version 3.9.
Set to ON to force the use of the static libraries. Default is OFF.
Defines the following variables:
Protobuf_FOUNDFound the Google Protocol Buffers library (libprotobuf & header files)
Protobuf_VERSIONNew in version 3.6.
Version of package found.
Protobuf_INCLUDE_DIRSInclude directories for Google Protocol Buffers
Protobuf_LIBRARIESThe protobuf libraries
Protobuf_PROTOC_LIBRARIESThe protoc libraries
Protobuf_LITE_LIBRARIESThe protobuf-lite libraries
New in version 3.9: The following IMPORTED targets are also defined:
protobuf::libprotobufThe protobuf library.
protobuf::libprotobuf-liteThe protobuf lite library.
protobuf::libprotocThe protoc library.
protobuf::protocNew in version 3.10: The protoc compiler.
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_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
.protofiles to C++:protobuf_generate_cpp (<SRCS> <HDRS> [DESCRIPTORS <DESC>] [EXPORT_MACRO <MACRO>] [<ARGN>...])SRCSVariable to define with autogenerated source files
HDRSVariable to define with autogenerated header files
DESCRIPTORSNew in version 3.10: Variable to define with autogenerated descriptor files, if requested.
EXPORT_MACROis a macro which should expand to
__declspec(dllexport)or__declspec(dllimport)depending on what is being compiled.ARGN.protofiles
-
protobuf_generate_python¶ New in version 3.4.
Add custom commands to process
.protofiles to Python:protobuf_generate_python (<PY> [<ARGN>...])
PYVariable to define with autogenerated Python files
ARGN.protofiles