2
votes

I want to change some DEFINES and LIBS paths depending on Debug or Release build configuration, but my CONFIG variable constains release and debug variables at the same time.

Simple test in pro file:

CONFIG(debug, debug|release) {
    message(DEBUG build)
}

CONFIG(release, debug|release) {
    message(RELEASE build)
}

This test outputs:

Project MESSAGE: DEBUG build
Project MESSAGE: RELEASE build

How should I set up my project?

1
It's the last occurrence of "debug" or "release" that counts. See this answer for details: stackoverflow.com/a/16974223/856199 - Nikos C.

1 Answers

1
votes

You should use this:

debug_and_release_target {
    CONFIG(debug, debug|release) {
        message("debug")
    } else {
        message("release")
    }   
}

This is what we use inside Qt as well, including QtSerialPort. Although we use this as well for Mac, just in case:

if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
    LIBS += -lQtSerialPort$${QT_LIBINFIX}_debug
} else {
   LIBS += -lQtSerialPort$${QT_LIBINFIX}
}