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

INPUT

source files

OUTPUT_DIR

output directory

TARGET

add a custom target to run the generating command

INCLUDE_DIRECTORIES

extra include directories

OPTIONS

extra options passed to protobuf compiler

DEPENDS

dependencies

CREATE_ONCE

create 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) or find_package(Protobuf CONFIG). What is wanted out of it is protobuf::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.