From 6a41e3390869c41f316b336adfaa12f35171daf3 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Tue, 28 Feb 2023 19:43:15 +0100 Subject: [PATCH] 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 --- .../cmakeprojectmanager/cmakeconfigitem.cpp | 16 ++++++++++++---- src/plugins/cmakeprojectmanager/configmodel.cpp | 9 +++++++-- src/plugins/cmakeprojectmanager/configmodel.h | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp index 63810fa6e9a..e8ff40b3105 100644 --- a/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeconfigitem.cpp @@ -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 diff --git a/src/plugins/cmakeprojectmanager/configmodel.cpp b/src/plugins/cmakeprojectmanager/configmodel.cpp index e38df5d2a86..953486e2dad 100644 --- a/src/plugins/cmakeprojectmanager/configmodel.cpp +++ b/src/plugins/cmakeprojectmanager/configmodel.cpp @@ -101,6 +101,11 @@ CMakeConfigItem ConfigModel::DataItem::toCMakeConfigItem() const return cmi; } +QString ConfigModel::DataItem::expandedValue(Utils::MacroExpander *expander) +{ + return toCMakeConfigItem().expandedValue(expander); +} + // ConfigModel ConfigModel::ConfigModel(QObject *parent) : Utils::TreeModel<>(parent) @@ -165,7 +170,7 @@ void ConfigModel::appendConfiguration(const QString &key, if (m_kitConfiguration.contains(key)) internalItem.kitValue = QString::fromUtf8( isInitial ? m_kitConfiguration.value(key).value - : m_macroExpander->expand(m_kitConfiguration.value(key).value)); + : m_kitConfiguration.value(key).expandedValue(m_macroExpander).toUtf8()); m_configuration.append(internalItem); setConfiguration(m_configuration); } @@ -504,7 +509,7 @@ void ConfigModel::generateTree() for (InternalDataItem &di : m_configuration) { auto it = initialHash.find(di.key); if (it != initialHash.end()) - di.initialValue = macroExpander()->expand(it->value); + di.initialValue = it->expandedValue(macroExpander()); root->appendChild(new Internal::ConfigModelTreeItem(&di)); } diff --git a/src/plugins/cmakeprojectmanager/configmodel.h b/src/plugins/cmakeprojectmanager/configmodel.h index 95160ee1aae..e70cac3bbec 100644 --- a/src/plugins/cmakeprojectmanager/configmodel.h +++ b/src/plugins/cmakeprojectmanager/configmodel.h @@ -36,6 +36,8 @@ public: CMakeConfigItem toCMakeConfigItem() const; + QString expandedValue(Utils::MacroExpander *expander); + enum Type { BOOLEAN, FILE, DIRECTORY, STRING, UNKNOWN}; QString key;