I have some proto definitions that I compile to cpp.
To generate the corresponding make target I use cmake like this:protobuf_generate_cpp(CPP_SOURCES PROTO_HEADERS ${PROTO_FILES})
And I use the CPP_SOURCES
to build my lib.
Now I need to compile the same proto files for python also and I added this:protobuf_generate_python(PY_SOURCES ${PROTO_FILES})
This alone has no effect, and I am not sure what I should / can add more in order to have some make target that will trigger also the protoc for python
Protocol buffers (Protobuf) are a language-agnostic data serialization format developed by Google. Protobuf is great for the following reasons: Low data volume: Protobuf makes use of a binary format, which is more compact than other formats such as JSON. Persistence: Protobuf serialization is backward-compatible.
The parameter to the --python_out= option is the directory where you want the compiler to write your Python output. The compiler creates a . py file for each . proto file input.
The protobuf_generate_cpp function is responsible for executing the protoc and populating the PROTO_SRCS and PROTO_HDRS variables with their generated files. Without this functionality, you would need to manually add the protoc command and the required arguments.
To check which version of protobuf is installed, use pip show protobuf or pip3 show protobuf in your Linux terminal.
You already answered your question, but here is a complete answer.
The protobuf_generate_python() function add's a custom command. To trigger the command you need a define a target. So add a add_custom_target() like this
add_custom_target(myTarget ALL
DEPENDS ${PY_SOURCES})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With