Search code examples
qtif-statementqmake

if/else if equivalent for qmake/pro Qt file


I sometimes have to write qmake pro file like this:

QMAKE_EXTRA_TARGETS += activate

macos {
    clear_cache.commands += defaults write io.delille.$$TARGET activated 1;
}

win32 {
    clear_cache.commands += another working command;
}


linux {
    clear_cache.commands += echo unsupported;
}

ios {
    clear_cache.commands += echo unsupported;
}

Is there a way to have avoid listing all unsupported plateform in a simpler way like most language allow if if/else if statement?


Solution

  • qmake knowns about if/else: https://doc.qt.io/qt-5/qmake-language.html#scopes

    win32:xml {
        message(Building for Windows)
        SOURCES += xmlhandler_win.cpp
    } else:xml {
        SOURCES += xmlhandler.cpp
    } else {
        message("Unknown configuration")
    }