Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How qmake extra compilers work?



  • Greetings.

    I'm trying to use protobuf compiler, but I can't fully understand how it work. As example I took a code from here "Example of adding protobuf build as a part of .pro file":http://qt-project.org/doc/note_revisions/423/693/view. I'll put slightly modified code here:
    @protobuf_decl.name = protobuf header
    protobuf_decl.input = PROTOS
    protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
    protobuf_decl.commands = $$PWD/../Protobuf/protoc.exe --cpp_out=$$PWD --proto_path=$$PWD/protos $$PWD/protos/${QMAKE_FILE_BASE}.proto
    protobuf_decl.variable_out = HEADERS
    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 = SOURCES
    QMAKE_EXTRA_COMPILERS += protobuf_impl@

    Now questions:

    in protobuf_decl.commands I specified the command to run protobuf compiler. That compiler generates *.pb..h and *.pb..cc files. But why protobuf_decl.output have only *.pb.h? Anyway, this command generates correct files, so why do I need to specify this output?

    if I remove protobuf_decl.output and protobuf_decl.variable_out I can't build a project - it says me about missing headers and protobuf compiler doesn't run at all. Is there any way to force it to run always first?

    protobuf_impl.commands = $$escape_expand(\n). What is this? What this command do and why I need this?



  • Not, that Im so sure about this myself, but:

    This looks like it's there mostly for the dependencies in the makefile. Simply put: qmake must know that something.pb.h is made by calling protobuf on something.proto to write it down properly in the makefile.

    As above: if you include something.pb.h and qmake doesn't know how to make that header so doesn't make so it isn't created -> you get a missing header.

    Probably it's basically "do nothing" said in elaborate way, but I'm not sure


Log in to reply