QMAKE_FILE_NAME is weird



  • 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!



  • @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.



  • @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



  • @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.



  • 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!



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.