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

Using QMAKE_EXTRA_COMPILERS for header generation



  • I am using Qt5 with VS2012. My .vcxproj files are generated from .pro files using qmake. My current task is to generate a header file (that contains simple version information) every time the application is built using Visual Studio. I could add a custom pre-build step to my VS project but that would get lost every time the .vcxproj is regnerated from .pro. So I need a .pro file based solution.

    I was told QMAKE_EXTRA_COMPILERS is what I need. So I tried to add a new compiler to one of my .pro files. Something like this:

    @
    PHONY_DEPS = .
    headergen.input = PHONY_DEPS
    headergen.output = test.c
    headergen.variable_out = GENERATED_SOURCES
    headergen.commands = echo Test > test.c
    headergen.name = CREATE test.c
    headergen.CONFIG += combine
    QMAKE_EXTRA_COMPILERS += headergen
    @

    This actually creates a test.c file every time I build my application. However I do not want to generate a .c file but a .h header:

    @
    PHONY_DEPS = .
    headergen.input = PHONY_DEPS
    headergen.output = test.h
    headergen.variable_out = HEADERS
    headergen.commands = echo Test > test.h
    headergen.name = CREATE test.h
    headergen.CONFIG += combine
    QMAKE_EXTRA_COMPILERS += headergen
    @

    This one fails without any error printed by qmake. The .vcxproj simply does not contain any additional build step.

    I never used QMAKE_EXTRA_COMPILERS before and the documentation is pretty poor. Could someone please give me a hint how to create a header generation rule?



  • Nobody who could give a hint? Nobody who knows that technique?



  • for headers, you need to add xxx.CONFIG += no_link. if you are lucky, things will be executed in the right order ...



  • Many thanks for your answer! Sorry for the late reply. I could not try out your suggestion earlier.

    I added the no_link config option. This means I used
    @
    PHONY_DEPS = .
    headergen.input = PHONY_DEPS
    headergen.output = test.h
    headergen.variable_out = HEADERS
    headergen.commands = echo Test > test.h
    headergen.name = CREATE test.h
    headergen.CONFIG += combine no_link
    QMAKE_EXTRA_COMPILERS += headergen
    @

    This adds a <ClInclude Include="test.h" /> line to the generated .vcxproj file but unfortunately no CustomBuild step. So still there is something missing. One more idea?


Log in to reply