From 70b33886843cde31ee4d6a46cad010e81885ae70 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Fri, 16 Dec 2022 14:32:54 +0100 Subject: [PATCH] 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 Reviewed-by: Qt CI Bot --- .../cmakeprojectimporter.cpp | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index f8f536e22db..fe9487bbaf6 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -441,6 +441,28 @@ static QString extractVisualStudioPlatformFromConfig(const CMakeConfig &config) 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 CMakeProjectImporter::examineDirectory(const FilePath &importPath, QString *warningMessage) const { @@ -518,6 +540,7 @@ QList CMakeProjectImporter::examineDirectory(const FilePath &importPath, } } else { config = cache; + updateCompilerPaths(config, env); config << CMakeConfigItem("CMAKE_COMMAND", CMakeConfigItem::PATH, configurePreset.cmakeExecutable.value().toUtf8());