forked from qt-creator/qt-creator
CMake: Implement cmake true/false semantics
Implement proper support for cmakes true/false value semantics. Change-Id: I127f73f62d1b7b21b2fee032f40c9cc448b876b8 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -148,6 +148,25 @@ CMakeConfigItem::Type CMakeConfigItem::typeStringToType(const QByteArray &type)
|
||||
return CMakeConfigItem::INTERNAL;
|
||||
}
|
||||
|
||||
Utils::optional<bool> CMakeConfigItem::toBool(const QByteArray &value)
|
||||
{
|
||||
// Taken from CMakes if(<constant>) documentation:
|
||||
// "Named boolean constants are case-insensitive."
|
||||
const QString v = QString::fromUtf8(value).toUpper();
|
||||
|
||||
bool isInt = false;
|
||||
v.toInt(&isInt);
|
||||
|
||||
// "False if the constant is 0, OFF, NO, FALSE, N, IGNORE, NOTFOUND, the empty string, or ends in the suffix -NOTFOUND."
|
||||
if (v == "0" || v == "OFF" || v == "NO" || v == "FALSE" || v == "N" || v == "IGNORE" || v == "NOTFOUND" || v == "" || v.endsWith("-NOTFOUND"))
|
||||
return false;
|
||||
// "True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number."
|
||||
if (v == "1" || v == "ON" || v == "YES" || v == "TRUE" || v == "Y" || isInt)
|
||||
return true;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
QString CMakeConfigItem::expandedValue(const ProjectExplorer::Kit *k) const
|
||||
{
|
||||
return expandedValue(k->macroExpander());
|
||||
|
||||
Reference in New Issue
Block a user