Question

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?

Was it helpful?

Solution

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}
}   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top