CMakePM: Allow relative compiler paths for presets

You can have a preset with the PATH environment variable modified and
with CMAKE_C|XX_COMPILER CMake variables only as "gcc.exe" and "g++.exe"

Qt Creator now will search in PATH after the compiler file names and
work as expected.

Fixes: QTCREATORBUG-28602
Change-Id: I8520f6fcf5e542600fab08228d04d3709d3a8e8f
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Cristian Adam
2022-12-16 14:32:54 +01:00
parent 456b8b69f9
commit 70b3388684

View File

@@ -441,6 +441,28 @@ static QString extractVisualStudioPlatformFromConfig(const CMakeConfig &config)
return platform; return platform;
} }
void updateCompilerPaths(CMakeConfig &config, const Environment &env)
{
auto updateRelativePath = [&config, env](const QByteArray &key) {
FilePath pathValue = config.filePathValueOf(key);
if (pathValue.isAbsolutePath() || pathValue.isEmpty())
return;
pathValue = env.searchInPath(pathValue.fileName());
auto it = std::find_if(config.begin(), config.end(), [&key](const CMakeConfigItem &item) {
return item.key == key;
});
QTC_ASSERT(it != config.end(), return);
it->value = pathValue.path().toUtf8();
};
updateRelativePath("CMAKE_C_COMPILER");
updateRelativePath("CMAKE_CXX_COMPILER");
}
QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath, QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
QString *warningMessage) const QString *warningMessage) const
{ {
@@ -518,6 +540,7 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
} }
} else { } else {
config = cache; config = cache;
updateCompilerPaths(config, env);
config << CMakeConfigItem("CMAKE_COMMAND", config << CMakeConfigItem("CMAKE_COMMAND",
CMakeConfigItem::PATH, CMakeConfigItem::PATH,
configurePreset.cmakeExecutable.value().toUtf8()); configurePreset.cmakeExecutable.value().toUtf8());