Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile protobuf to python, cmake command

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

like image 518
codentary Avatar asked Feb 24 '18 19:02

codentary


People also ask

What is Protobuf in 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.

What is-- Python_ out?

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.

What is Protobuf_generate_cpp?

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.

How do I check Protobuf version?

To check which version of protobuf is installed, use pip show protobuf or pip3 show protobuf in your Linux terminal.


1 Answers

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})
like image 179
Sam Avatar answered Sep 27 '22 22:09

Sam