Skip to content

Instantly share code, notes, and snippets.

@ericjang
Created April 20, 2016 20:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericjang/419973938a8f3c940805f3d72b29da1d to your computer and use it in GitHub Desktop.
Save ericjang/419973938a8f3c940805f3d72b29da1d to your computer and use it in GitHub Desktop.
#
# Qt qmake integration with Google Protocol Buffers compiler protoc
#
# To compile protocol buffers with qt qmake, specify PROTOS variable and
# include this file
#
# Example:
# LIBS += /usr/lib/libprotobuf.so
# PROTOS = a.proto b.proto
# include(protobuf.pri)
# PROTOS = protobuf/boxbot.proto
# PROTOPATH = protobuf
# include(protobuf.pri) # compile the protobufs
#
# By default protoc looks for .proto files (including the imported ones) in
# the current directory where protoc is run. If you need to include additional
# paths specify the PROTOPATH variable
#
# {proto_path}/bar/baz.proto will result in creation of {cpp_out}/bar/baz.pb.cc, {cpp_out}/bar/baz.pb.h,
PROTOBUF_DIR = /contrib/projects/protobuf # installation location of protocol buffers
INCLUDEPATH += $${PROTOBUF_DIR}/include
#PROTOPATH += .
#PROTOPATHS =
for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
BUILD_DIR=build
#message("hello " $${PROTOPATHS})
## *.pb.h
protobuf_decl.name = protobuf header
protobuf_decl.input = PROTOS
protobuf_decl.output = $${BUILD_DIR}/${QMAKE_FILE_BASE}.pb.h
protobuf_decl.commands = $${PROTOBUF_DIR}/bin/protoc --cpp_out=$${BUILD_DIR} $${PROTOPATHS} ${QMAKE_FILE_NAME}
protobuf_decl.variable_out = GENERATED_FILES
QMAKE_EXTRA_COMPILERS += protobuf_decl
## *.pb.cc
protobuf_impl.name = protobuf implementation
protobuf_impl.input = PROTOS
protobuf_impl.output = $${BUILD_DIR}/${QMAKE_FILE_BASE}.pb.cc
protobuf_impl.depends = $${BUILD_DIR}/${QMAKE_FILE_BASE}.pb.h
protobuf_impl.commands = $$escape_expand(\n)
protobuf_impl.variable_out = GENERATED_SOURCES
QMAKE_EXTRA_COMPILERS += protobuf_impl
# WTF, qmake can't generate the python outputs automatically...
# *_pb2.py
#py_decl.name = protobuf header
#py_decl.input = PROTOS
#py_decl.output = $${BUILD_DIR}/${QMAKE_FILE_BASE}_pb2.py
#py_decl.commands = $${PROTOBUF_DIR}/bin/protoc --python_out=$${BUILD_DIR} $${PROTOPATHS} ${QMAKE_FILE_NAME}
#py_decl.variable_out = GENERATED_FILES
#QMAKE_EXTRA_COMPILERS += py_decl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment