When using the default qmake compiler (via the SOURCES variable), I can use precompiled headers like so:
CONFIG += precompile_header
PRECOMPILED_HEADER = stable.h
SOURCES = main.c
However, I’d like to use a custom compiler (via QMAKE_EXTRA_COMPILERS). I tried this:
CONFIG += precompile_header
PRECOMPILED_HEADER = stable.h
MY_SOURCES = main.c
my.input = MY_SOURCES
my.output = ${QMAKE_FILE_IN_BASE}.o
my.commands = clang $$QMAKE_CFLAGS_USE_PRECOMPILE -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += my
…and the precompiled headers are built, but my custom compiler fails because QMAKE_CFLAGS_USE_PRECOMPILE doesn’t contain the path to the precompiled header. (It is defined as -Xclang -include-pch -Xclang ${QMAKE_PCH_OUTPUT}, and apparently ${QMAKE_PCH_OUTPUT} is empty.)
How can I get the name of the generated precompiled header, so I can pass it as a parameter to my custom compiler?
Looking at the qmake source code, precompiled header handling seems to be hardcoded in
UnixMakefileGenerator::init()to only work for the built-in C, CXX, OBJC, and OBJCXX compilers.QMAKE_PCH_OUTPUT, for GCC and Clang-style precompiled headers, is constructed by combiningPRECOMPILED_DIR,TARGET, one ofc/c++/objective-c/objective-c++, andQMAKE_PCH_OUTPUT_EXT. So, in the question’s second example, the following command line should work: