Protobuf¶
Turning .proto files into sources with the protobuf compiler.
- qm_create_protobuf¶
Add rules for creating Google Protobuf source files.
qm_create_protobuf(<OUT> INPUT <files...> [OUTPUT_DIR <dir>] [TARGET <target>] [INCLUDE_DIRECTORIES <dirs...>] [OPTIONS <options...>] [DEPENDS <deps...>] [CREATE_ONCE] )
<OUT>the variable to answer with, holding the paths of the generated sources
INPUTsource files
OUTPUT_DIRoutput directory
TARGETadd a custom target to run the generating command
INCLUDE_DIRECTORIESextra include directories
OPTIONSextra options passed to protobuf compiler
DEPENDSdependencies
CREATE_ONCEcreate proto code files at configure phase if not exist
Note
protobuf has to be found before this is called, either way round:
find_package(Protobuf)orfind_package(Protobuf CONFIG). What is wanted out of it isprotobuf::protoc, and a call made without one stops with an error saying so.qm_import(Protobuf) find_package(Protobuf CONFIG REQUIRED) qm_create_protobuf(_proto_src INPUT a.proto b.proto INCLUDE_DIRECTORIES src/proto OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto ) target_sources(${PROJECT_NAME} PUBLIC ${_proto_src})
Where this page comes from
The comments in cmake/modules/Protobuf.cmake, which is what to change.