protobuf.pri 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Qt qmake integration with Google Protocol Buffers compiler protoc
  2. #
  3. # To compile protocol buffers with qt qmake, specify PROTOS variable and
  4. # include this file
  5. #
  6. # Based on:
  7. # https://vilimpoc.org/blog/2013/06/09/using-google-protocol-buffers-with-qmake/
  8. PROTOC = protoc
  9. unix {
  10. PKG_CONFIG = $$pkgConfigExecutable()
  11. # All our dependency resolution depends on pkg-config. If it isn't
  12. # available, the errors we will get subsequently are a lot more cryptic than
  13. # this.
  14. !system($$PKG_CONFIG --version 2>&1 > /dev/null) {
  15. error("pkg-config executable is not available. please install it so I can find dependencies.")
  16. }
  17. !contains(QT_CONFIG, no-pkg-config) {
  18. CONFIG += link_pkgconfig
  19. PKGCONFIG += protobuf
  20. } else {
  21. # Some SDK builds (e.g. OS X 5.4.1) are no-pkg-config, so try to hack the linker flags in.
  22. QMAKE_LFLAGS += $$system($$PKG_CONFIG --libs protobuf)
  23. }
  24. gcc|clang {
  25. # Add -isystem for protobuf includes to suppress some loud compiler warnings in their headers
  26. PROTOBUF_CFLAGS = $$system($$PKG_CONFIG --cflags protobuf)
  27. PROTOBUF_CFLAGS ~= s/^(?!-I).*//g
  28. PROTOBUF_CFLAGS ~= s/^-I(.*)/-isystem \\1/g
  29. QMAKE_CXXFLAGS += $$PROTOBUF_CFLAGS
  30. }
  31. }
  32. win32 {
  33. isEmpty(PROTOBUFDIR):error(You must pass PROTOBUFDIR=path/to/protobuf to qmake on this platform)
  34. INCLUDEPATH += $${PROTOBUFDIR}/include
  35. LIBS += -L$${PROTOBUFDIR}/lib -lprotobuf
  36. contains(QMAKE_HOST.os,Windows):PROTOC = $${PROTOBUFDIR}/bin/protoc.exe
  37. }
  38. protobuf_decl.name = protobuf headers
  39. protobuf_decl.input = PROTOS
  40. protobuf_decl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.h
  41. protobuf_decl.commands = $$PROTOC --cpp_out=${QMAKE_FILE_IN_PATH} --proto_path=${QMAKE_FILE_IN_PATH} ${QMAKE_FILE_NAME}
  42. protobuf_decl.variable_out = HEADERS
  43. QMAKE_EXTRA_COMPILERS += protobuf_decl
  44. protobuf_impl.name = protobuf sources
  45. protobuf_impl.input = PROTOS
  46. protobuf_impl.output = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.cc
  47. protobuf_impl.depends = ${QMAKE_FILE_IN_PATH}/${QMAKE_FILE_BASE}.pb.h
  48. protobuf_impl.commands = $$escape_expand(\n)
  49. protobuf_impl.variable_out = SOURCES
  50. QMAKE_EXTRA_COMPILERS += protobuf_impl