Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 826
Brendan Long Avatar asked Jul 10 '13 18:07

Brendan Long


1 Answers

I figured this out right before I posted the question, but since no one else has a good answer for this, I figured I'd post it anyway.

What I needed wasn't $(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 re-run qmake to change the environment variables, instead of having make handle them intellegently, but it's definitely better than having to edit the .pro file every time.

like image 125
Brendan Long Avatar answered Nov 24 '22 15:11

Brendan Long