aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2023-03-31 21:14:38 +0200
committerCristian Adam <cristian.adam@qt.io>2023-04-17 15:03:59 +0000
commitbbe61a965d23ff627f476f3fda8613373c9a52b8 (patch)
tree5157678c24b53d34876cd2d815fe26e4600909f8
parent45faec05e555fec99c6cf75b3fc8844b37084919 (diff)
CMakePM: sanitize preset initial configuration values
The task-number below has a sample where CMAKE_C|XX_COMPILER was set to "cl.exe" and the CMAKE_PREFIX_PATH was set to "C:/Qt//6.5.0/ msvc2019_64". These values would cause "red" values in the CMake configuration, which is not that nice. This patchset will make sure that everything is nicely configured. Task-number: QTCREATORBUG-28982 Change-Id: I21289d1936ef075ce02364fc675709c52c76c3ed Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp
index fb3a098e54..9113c40700 100644
--- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp
@@ -1255,6 +1255,12 @@ static void addCMakeConfigurePresetToInitialArguments(QStringList &initialArgume
const QString presetItemArg = presetItem.toArgument();
const QString presetItemArgNoType = presetItemArg.left(presetItemArg.indexOf(":"));
+ static QSet<QByteArray> defaultKitMacroValues{"CMAKE_C_COMPILER",
+ "CMAKE_CXX_COMPILER",
+ "QT_QMAKE_EXECUTABLE",
+ "QT_HOST_PATH",
+ "CMAKE_PROJECT_INCLUDE_BEFORE"};
+
auto it = std::find_if(initialArguments.begin(),
initialArguments.end(),
[presetItemArgNoType](const QString &arg) {
@@ -1265,6 +1271,11 @@ static void addCMakeConfigurePresetToInitialArguments(QStringList &initialArgume
QString &arg = *it;
CMakeConfigItem argItem = CMakeConfigItem::fromString(arg.mid(2)); // skip -D
+ // These values have Qt Creator macro names pointing to the Kit values
+ // which are preset expanded values used when the Kit was created
+ if (defaultKitMacroValues.contains(argItem.key) && argItem.value.startsWith("%{"))
+ continue;
+
// For multi value path variables append the non Qt path
if (argItem.key == "CMAKE_PREFIX_PATH" || argItem.key == "CMAKE_FIND_ROOT_PATH") {
QStringList presetValueList = presetItem.expandedValue(k).split(";");
@@ -1275,7 +1286,7 @@ static void addCMakeConfigurePresetToInitialArguments(QStringList &initialArgume
QStringList argItemPaths = argItemExpandedValue.split(";");
for (const QString &argPath : argItemPaths) {
const FilePath argFilePath = FilePath::fromString(argPath);
- const FilePath presetFilePath = FilePath::fromString(presetPath);
+ const FilePath presetFilePath = FilePath::fromUserInput(presetPath);
if (argFilePath == presetFilePath)
return true;
@@ -1290,12 +1301,10 @@ static void addCMakeConfigurePresetToInitialArguments(QStringList &initialArgume
}
arg = argItem.toArgument();
- } else if (argItem.key == "CMAKE_C_COMPILER" || argItem.key == "CMAKE_CXX_COMPILER"
- || argItem.key == "QT_QMAKE_EXECUTABLE" || argItem.key == "QT_HOST_PATH"
- || argItem.key == "CMAKE_PROJECT_INCLUDE_BEFORE"
- || argItem.key == "CMAKE_TOOLCHAIN_FILE") {
+ } else if (argItem.key == "CMAKE_TOOLCHAIN_FILE") {
const FilePath argFilePath = FilePath::fromString(argItem.expandedValue(k));
- const FilePath presetFilePath = FilePath::fromUtf8(presetItem.value);
+ const FilePath presetFilePath = FilePath::fromUserInput(
+ QString::fromUtf8(presetItem.value));
if (argFilePath != presetFilePath)
arg = presetItem.toArgument();