Search code examples
environment-variablesqmake

Add CFLAGS to QMake project without hard-coding them in the .pro file?


I'm using a distributed compiler, and I need to add -m64 to CFLAGS, CXXFLAGS and LDFLAGS. Usually, my definitions in .bashrc are fine, but qmake ignores them for some reason. The standard way of doing this seems to be to edit the .pro file, but I obviously don't want to hard code the architecture. So, I can edit the .pro file, but I can't hard code anything in it.

I tried setting CXXFLAGS like this:

QMAKE_CXXFLAGS += $(CFLAGS)

But it says:

Makefile:17: *** Recursive variable `CXXFLAGS' references itself (eventually). Stop.


Solution

  • I didn't need $(ENV_VAR), but $$(ENV_VAR), so I added these to my .pro file:

    QMAKE_CXXFLAGS += $$(CXXFLAGS)
    QMAKE_CFLAGS += $$(CFLAGS)
    QMAKE_LFLAGS += $$(LDFLAGS)
    

    This makes qmake respect those environment variables. Note that qmake uses LFLAGS instead of LDFLAGS.

    This is still not ideal, because you can need to rerun qmake to change the environment variables, instead of having make handle them intelligently, but it's definitely better than having to edit the .pro file every time.