Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMAKE_FILE_NAME is weird
QtWS25 Last Chance

QMAKE_FILE_NAME is weird

Scheduled Pinned Locked Moved General and Desktop
qmakeqmake makefilebuildcompilercompilationprotobuf
5 Posts 2 Posters 5.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spez
    wrote on last edited by Spez
    #1

    I've got a very annoying problem integrating the protoc compiler for the protocol buffers in my qmake build steps,

    Looking for "qmake protocol buffers" on Google I found this code:

    #
    # 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/local/lib/libprotobuf.so
    # PROTOS = a.proto b.proto
    # include(protobuf.pri)
    #
    # 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
    #
     
    PROTOPATH += .
    PROTOPATHS =
    for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
     
    protobuf_decl.name = protobuf header
    protobuf_decl.input = PROTOS
    protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
    protobuf_decl.commands = protoc --cpp_out="." $${PROTOPATHS} ${QMAKE_FILE_NAME}
    protobuf_decl.variable_out = GENERATED_FILES
    QMAKE_EXTRA_COMPILERS += protobuf_decl
     
    protobuf_impl.name = protobuf implementation
    protobuf_impl.input = PROTOS
    protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc
    protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h
    protobuf_impl.commands = $$escape_expand(\n)
    protobuf_impl.variable_out = GENERATED_SOURCES
    QMAKE_EXTRA_COMPILERS += protobuf_impl
    

    and when I include those two lines in my .pro file:

    include(protobuf.pri)
    PROTOS=project/interface_definitions.proto
    

    and try to compile my project I got the following error from protoc:

     /tmp/project/definitions/interface_definitions.proto:-1: error: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
    

    what I figured out so far is that protoc is being called this way:

    protoc --cpp_out=. --proto_path=. ../project/definitions/interface_definitions.proto
    

    the problem is that the file path in QMAKE_FILE_NAME begins with "../" and protoc seems no to get it managed because of this, I tested the direct path "definitions/interface_definitions.proto" and it worked!

    So now I'm trying to figure out how to solve this weird problem....

    QMAKE_FILE_BASE gives me the actual file name without the path though which is not a solution...

    Could somebody please help? spent the whole night on this *** already!

    K 1 Reply Last reply
    0
    • S Spez

      I've got a very annoying problem integrating the protoc compiler for the protocol buffers in my qmake build steps,

      Looking for "qmake protocol buffers" on Google I found this code:

      #
      # 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/local/lib/libprotobuf.so
      # PROTOS = a.proto b.proto
      # include(protobuf.pri)
      #
      # 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
      #
       
      PROTOPATH += .
      PROTOPATHS =
      for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
       
      protobuf_decl.name = protobuf header
      protobuf_decl.input = PROTOS
      protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
      protobuf_decl.commands = protoc --cpp_out="." $${PROTOPATHS} ${QMAKE_FILE_NAME}
      protobuf_decl.variable_out = GENERATED_FILES
      QMAKE_EXTRA_COMPILERS += protobuf_decl
       
      protobuf_impl.name = protobuf implementation
      protobuf_impl.input = PROTOS
      protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc
      protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h
      protobuf_impl.commands = $$escape_expand(\n)
      protobuf_impl.variable_out = GENERATED_SOURCES
      QMAKE_EXTRA_COMPILERS += protobuf_impl
      

      and when I include those two lines in my .pro file:

      include(protobuf.pri)
      PROTOS=project/interface_definitions.proto
      

      and try to compile my project I got the following error from protoc:

       /tmp/project/definitions/interface_definitions.proto:-1: error: File does not reside within any path specified using --proto_path (or -I).  You must specify a --proto_path which encompasses this file.  Note that the proto_path must be an exact prefix of the .proto file names -- protoc is too dumb to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).
      

      what I figured out so far is that protoc is being called this way:

      protoc --cpp_out=. --proto_path=. ../project/definitions/interface_definitions.proto
      

      the problem is that the file path in QMAKE_FILE_NAME begins with "../" and protoc seems no to get it managed because of this, I tested the direct path "definitions/interface_definitions.proto" and it worked!

      So now I'm trying to figure out how to solve this weird problem....

      QMAKE_FILE_BASE gives me the actual file name without the path though which is not a solution...

      Could somebody please help? spent the whole night on this *** already!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Spez
      Possibly clean_path() or absolute_path() could be of help. More likely absolute_path, since AFAIK clean_path() removes only strange '..' in the middle.

      Vote the answer(s) that helped you to solve your issue(s)

      S 1 Reply Last reply
      0
      • K koahnig

        @Spez
        Possibly clean_path() or absolute_path() could be of help. More likely absolute_path, since AFAIK clean_path() removes only strange '..' in the middle.

        S Offline
        S Offline
        Spez
        wrote on last edited by
        #3

        @koahnig

        I tried this:

        protobuf_decl.commands = protoc --cpp_out="." $${PROTOPATHS} $$clean_path(${QMAKE_FILE_NAME})
        

        the path was the same:

        ../project/definitions/interface_definitions.proto
        

        then I tried:

        $$absolute_path(${QMAKE_FILE_NAME})
        

        result:

        /tmp/project/../project/definitions/interface_definitions.proto
        

        finally I thought I could try:

        $$clean_path($$absolute_path(${QMAKE_FILE_NAME}))
        

        didn't work as well, path still the same:

        /tmp/project/../project/definitions/interface_definitions.proto
        

        neither clean_path nor absolute_path worked for me

        K 1 Reply Last reply
        0
        • S Spez

          @koahnig

          I tried this:

          protobuf_decl.commands = protoc --cpp_out="." $${PROTOPATHS} $$clean_path(${QMAKE_FILE_NAME})
          

          the path was the same:

          ../project/definitions/interface_definitions.proto
          

          then I tried:

          $$absolute_path(${QMAKE_FILE_NAME})
          

          result:

          /tmp/project/../project/definitions/interface_definitions.proto
          

          finally I thought I could try:

          $$clean_path($$absolute_path(${QMAKE_FILE_NAME}))
          

          didn't work as well, path still the same:

          /tmp/project/../project/definitions/interface_definitions.proto
          

          neither clean_path nor absolute_path worked for me

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Spez
          The one should work, because clean_path is meant to remove the redundant path section.

          What OS are you using?
          Which Qt version are you using?

          You can also check for bug reports on JIRA. Possibly it is already known or you may file a bug report there.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Spez
            wrote on last edited by Spez
            #5

            qmake provides functions for processing the contents of variables during the configuration process.

            As QMAKE_FILE_NAME is a run-time and not a configuration-time variable it cannot be edited by clean_path, seems this problem cannot be solved this way, anyone any ideas?

            EDIT:

            I think I finally found a proper solution:

              PROTOS = interface_definitions.proto
              PROTOPATH = $$relative_path($$PWD, $$OUT_PWD) \
            

            protoc is now being called this way:

              protoc --cpp_out=. --proto_path=. --proto_path=../project/ ../project/interface_definitions.proto
            

            everything works fine now!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved