4

In my qmake-based project, I want to run 'xxd' on some files before compilation. Following the documentation, the relevant part in my pro file looks as following:

SHADERS = shader/tone.frag \
          shader/trans.frag \
          shader/hue.frag

# xxd
xxd.output = ${QMAKE_FILE_NAME}.xxd
xxd.commands = xxd -i ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT}
xxd.depends = SHADERS
xxd.input = $$SHADERS
xxd.variable_out = HEADERS

QMAKE_EXTRA_COMPILERS += xxd

Qmake doesn't complain, but it also doesn't run xxd at all. Do I have to create special targets for each file I want to have pre-processed? (The resulting *.xxd files will not be compiled afterwards by me, only included in other cpp files)

Edit: With smokris's help, this is how I fixed the part in my pro file:

# xxd
xxd.output = ${QMAKE_FILE_NAME}.xxd
xxd.commands = xxd -i ${QMAKE_FILE_NAME} > ${QMAKE_FILE_OUT}
xxd.depends = $$SHADERS
xxd.input = SHADERS
xxd.variable_out = HEADERS
smokris
  • 11,740
  • 2
  • 39
  • 59
Ancurio
  • 1,698
  • 1
  • 17
  • 32
  • Glad you got it working. I just figured out my confusion about `.variable_out` and clarified my answer. – smokris Jan 12 '13 at 16:25
  • Just in case anyone else is looking at this and can't make it work: I had to add `$${QMAKE_FILE_NAME}.xxd` (it was called differently in my code) to the .depends list. So for me it was `xxd.depends = SHADERS $${QMAKE_FILE_NAME}.xxd`. Without it the shader compiler didn't execute in case of a re-build and `$${QMAKE_FILE_NAME}.xxd` was never created. – rsp1984 Mar 06 '17 at 17:44
  • I made all the above changes, and nothing happened. It turns out you need to actually #include the generated file into your C++ file, and then run qmake. Then the dependencies will be updated and it will generate the file. Or you can alternatively do "xxd.CONFIG = target_predeps" to force it to generate the file even if not used anywhere. Hope this helps someone. – Wayne Piekarski Dec 04 '21 at 05:46

1 Answers1

5

The .input attribute expects the name of a variable, not a list of files. Try taking away the $$ and just use xxd.input = SHADERS.

.depends, on the other hand, expects a list of files, so use xxd.depends = $$SHADERS.

If you set .variable_out to HEADERS, SOURCES, or OBJECTS, the compiler will run. However, if you set .variable_out to another variable name, you must also set .CONFIG = target_predeps in order for the compiler to run.

smokris
  • 11,740
  • 2
  • 39
  • 59