How to specify different compiler flags for different cpp files within a single qmake project?

  • Is it possible to compile a number of .cpp files within a project with different compiler flags than other files?

  • I've found and tried this trick:

    @QMAKE_CXXFLAGS += -march=x86-64 -msse -msse2

    Creating a new compiler for sources that use AVX

    gccavx.input = SOURCES_AVX
    gccavx.output = ${QMAKE_FILE_BASE}.o
    gccavx.commands = g++ $$QMAKE_CXXFLAGS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} -mavx -mfma -I$$IN_PWD/linux

    SOURCES_AVX += AVX.cpp@

    But it doesn't exactly work as it should. I'm compiling a static lib using this trick, and am getting a lot of "undefined reference", including main, for this one file I'm compiling with this trick. I think a linker is invoked, while I only need to compile the file so that it's linked with others using global linker flags.

  • Why not have two different projects, which are then combined into a single SUBDIRS project?

  • Because I need it to link into a single library, not two libraries. Anyway, I've figured it out, just need to correct the code in my question a little bit.

Log in to reply

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