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>
This commit is contained in:
Cristian Adam
2023-03-31 21:14:38 +02:00
parent 45faec05e5
commit bbe61a965d

View File

@@ -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();