CMakePM: Use cleaned paths for CMake parameter values

FilePath::fromUserInput will "clean" the paths, which on Windows means
that \\ will be replaced by /.

This is how CMake treats the paths internally as CMake paths.

This fixes the %{buildDir} macro which will expand to \\ on Windows.
Which causes issues with qtcsettings.cmake.

This way the expanded value of CMAKE_PROJECT_INCLUDE_BEFORE is not
displayed as red on Windows in the "Current Configuration" settings
page.

Change-Id: Ic26bf437de41ff3fb1c1b98d304ae84512cb0f1a
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2023-02-28 19:43:15 +01:00
parent b80546c1d9
commit 6a41e33908
3 changed files with 21 additions and 6 deletions

View File

@@ -194,7 +194,17 @@ QString CMakeConfigItem::expandedValue(const ProjectExplorer::Kit *k) const
QString CMakeConfigItem::expandedValue(const Utils::MacroExpander *expander) const
{
return expander ? expander->expand(QString::fromUtf8(value)) : QString::fromUtf8(value);
QString expandedValue = expander ? expander->expand(QString::fromUtf8(value))
: QString::fromUtf8(value);
// Make sure we have CMake paths using / instead of \\ on Windows
// %{buildDir} returns \\ on Windows
if (type == CMakeConfigItem::FILEPATH || type == CMakeConfigItem::PATH) {
const FilePaths paths = transform(expandedValue.split(";"), &FilePath::fromUserInput);
expandedValue = transform(paths, &FilePath::path).join(";");
}
return expandedValue;
}
bool CMakeConfigItem::less(const CMakeConfigItem &a, const CMakeConfigItem &b)
@@ -424,9 +434,7 @@ QString CMakeConfigItem::toString(const Utils::MacroExpander *expander) const
break;
}
const QString expandedValue
= expander ? expander->expand(QString::fromUtf8(value)) : QString::fromUtf8(value);
return QString::fromUtf8(key) + QLatin1Char(':') + typeStr + QLatin1Char('=') + expandedValue;
return QString("%1:%2=%3").arg(QString::fromUtf8(key), typeStr, expandedValue(expander));
}
QString CMakeConfigItem::toArgument() const