Qmake: how to remove compiler flag for a certain project, without changing qmake.conf?

13,320

Solution 1

The only way this could work is

QMAKE_CFLAGS -= /GL /O2

but I doubt this works for QMAKE_CFLAGS.

Alternatively, you could redefine QMAKE_CFLAGS, forgetting its previous value:

QMAKE_CFLAGS = $$CFLAGS_WITHOUT_GL_O2

Solution 2

I had a similar problem and I solved it by adding the following directive in the .pro file:

QMAKE_CXXFLAGS_RELEASE -= -g

Observe the _RELEASE suffix, otherwise don't work.

Solution 3

I edited my .pro file by using this, and it worked!

QMAKE_CXXFLAGS_RELEASE  -= -Zc:strictStrings
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -Zc:strictStrings

It does not work:

QMAKE_CFLAGS_RELEASE -= -Zc:strictStrings
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO -= -Zc:strictStrings

You can try:

QMAKE_CXXFLAGS_RELEASE  -= -GL -O2
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -GL -O2

Take a look in:

your Qt dir\compiler\mkspecs\win32-msvc2013\qmake.conf

Solution 4

If -= does not work

try in your .pro file

QMAKE_CFLAGS = $$replace(QMAKE_CFLAGS, "-GL ", "")
QMAKE_CFLAGS = $$replace(QMAKE_CFLAGS, "-O2 ", "")

Solution 5

You can edit the qmakespec which is used by your configuration.

The easiest way to find it is by opening

%QTDIR%\mkspecs\%QMAKESPEC%

assuming the environment variables are set (they should be)

Just in case it's not working, it will be something like C:\Qt\4.x.x\mkspecs\win32-msvc2010

In the qmake.conf file you can adjust the folling two lines (they are in different places in the file)

QMAKE_CFLAGS_RELEASE    = -O2 -MT
QMAKE_CFLAGS_LTCG       = -GL

to

QMAKE_CFLAGS_RELEASE    = -MT
QMAKE_CFLAGS_LTCG       =

However note that you will have to do this for every Qt Version you are using (and for every future update you will do).

[Edit]
If you want to have -O2 -GL options for certain projects you will have to add

QMAKE_CFLAGS_RELEASE    += -O2
QMAKE_CFLAGS_LTCG       += -GL

to the .pro file of the projects which need those options.

Dependent on the amount of projects which use it and the ones which don't, either this approach or redefining QMAKE_CFLAGS will be more convenient.

Share:
13,320
Violet Giraffe
Author by

Violet Giraffe

I'm from Kharkiv, Ukraine. My city is being destroyed every day. Help us defend: https://www.comebackalive.in.ua/donate PC enthusiast, C++ fan and C++ / Qt / Android software developer. Also <3 Arduino. Music and car addict. Reinventing various wheels in my spare time. A custom-made square wheel is like a tailored suit, wouldn't you agree? Why do I have more rep from questions than from answers? Because you don't learn by answering; you learn by asking questions :) Ongoing personal open-source projects: Dual-panel file manager for Windows / Linux / Mac

Updated on October 26, 2022

Comments

  • Violet Giraffe
    Violet Giraffe over 1 year

    I'm using qmake and Visual Studio. In release build qmake adds /GL and /O2 flags to all projects, and I need to remove those two flags for certain libraries within my whole Qt project. Is there a way?

  • Violet Giraffe
    Violet Giraffe over 12 years
    tried -= - no luck. And the second solution is so obvious I didn't even think about it :)
  • Siav Josep
    Siav Josep about 7 years
    I believe checking the .conf file can't be underscored enough
  • Arbiter of buffoonery
    Arbiter of buffoonery over 4 years
    Please add details explaining what the line of code does. I suggest details on where this line is used (in a config file or from the command line), and an explanation of how this line removes the flags from the whole project. This will help others learn and evaluate whether the provided answer applies to them.