PDA

View Full Version : qmake Project file has both "debug" and "release" conditions true



barryhf
13th February 2010, 00:24
Here's my project file:


TARGET = trialApp
TEMPLATE = app

win32 {
debug {
LIBS += -L../trialLibA/debug
PRE_TARGETDEPS += ../trialLibA/debug/libtrialLibA.a
}
release {
LIBS += -L../trialLibA/release
PRE_TARGETDEPS += ../trialLibA/release/libtrialLibA.a
}
}

INCLUDEPATH += ../trialLibA
LIBS += -ltrialLibA

SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui


The problem is that both "debug" and "release" are defined when the makefile is generated. (I had started with debug {} else {} but debug was always defined).

In both Makefile.Debug and Makefile.Release, LIBS is defined to have both "-L../trialLibA/debug" and "-L../trialLibA/release".

So, of course, when I build the app, it takes the debug library (even when building release) because it's listed first in the LIBS path.

How is my understanding of the qmake process flawed here?

norobro
13th February 2010, 03:19
From the Qt docs (http://doc.qt.nokia.com/4.6/qmake-advanced-usage.html#scopes)
Scopes are similar to if statements in procedural programming languages. If a certain condition is true, the declarations inside the scope are processed.
So your scope says that if the OS is win32 compile with debug and release libraries.

Try something like this:
CONFIG += debug

win32 {
CONFIG(debug) {
LIBS += -L../trialLibA/debug
PRE_TARGETDEPS += ../trialLibA/debug/libtrialLibA.a
} else {
LIBS += -L../trialLibA/release
PRE_TARGETDEPS += ../trialLibA/release/libtrialLibA.a
}
}

Coises
13th February 2010, 05:43
How is my understanding of the qmake process flawed here?

Your confusion is that you expect it to make sense, whereas this particular “feature” is entirely counter-intuitive.

This explanation of the CONFIG function (http://doc.trolltech.com/latest/qmake-function-reference.html#config-config) should help.

The problem is that the CONFIG variable can (and usually does) contain conflicting options, such as both “debug” and “release”; only the last of conflicting options is effective, but an ordinary scope test only discovers whether an option is present, not whether it is effective. Using CONFIG(debug, debug|release), for example, will test whether “debug” is the last (and hence, effective) among the “debug” and “release” options.

barryhf
15th February 2010, 17:27
Thank you, Coises, the following code now works to set the dependencies correctly (I can change a code file in the library, hit F5 and the app builds and links correctly).

Another question: How does this effect the notion of "scopes" in general? Is it still valid to use the "win32" scope, or is there a different Conditional, such as CONFIG, that I should be using?


TARGET = trialApp
TEMPLATE = app

win32 {
CONFIG(debug, debug|release) {
LIBS += -L../trialLibA/debug
PRE_TARGETDEPS += ../trialLibA/debug/libtrialLibA.a
} else {
LIBS += -L../trialLibA/release
PRE_TARGETDEPS += ../trialLibA/release/libtrialLibA.a
}
}

INCLUDEPATH += ../trialLibA
LIBS += -ltrialLibA

SOURCES += main.cpp\
MainWindow.cpp
HEADERS += MainWindow.h
FORMS += MainWindow.ui