aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2023-03-10 20:11:59 +0100
committerCristian Adam <cristian.adam@qt.io>2023-03-11 08:56:06 +0000
commit05d9742a96abafbd07007319cc35167d8975b070 (patch)
tree7fef4d5aa2dafc88b25307a94e88ed2b842e6b36
parentd154388f27c0e0fe2176a8f4a2517f2dd409d493 (diff)
CMakePM: Expand CMake preset macros also for environment vars
This fixes the case when a CMake variable (CMAKE_PREFIX_PATH) would reference an environment variable (qt_path) that would contain a CMake preset macro (${sourceDir}/../qt_install). Fixes: QTCREATORBUG-28606 Change-Id: Ib6239b13782b2ea854969547af46c3fe82a061f4 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
-rw-r--r--src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp17
-rw-r--r--src/plugins/cmakeprojectmanager/presetsmacros.cpp9
2 files changed, 21 insertions, 5 deletions
diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
index ce01fcdc6b..3d5b4c02c1 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp
@@ -154,7 +154,9 @@ FilePaths CMakeProjectImporter::importCandidates()
}
static CMakeConfig configurationFromPresetProbe(
- const FilePath &importPath, const PresetsDetails::ConfigurePreset &configurePreset)
+ const FilePath &importPath,
+ const FilePath &sourceDirectory,
+ const PresetsDetails::ConfigurePreset &configurePreset)
{
const FilePath cmakeListTxt = importPath / "CMakeLists.txt";
cmakeListTxt.writeFileContents(QByteArray("cmake_minimum_required(VERSION 3.15)\n"
@@ -169,7 +171,7 @@ static CMakeConfig configurationFromPresetProbe(
const FilePath cmakeExecutable = FilePath::fromString(configurePreset.cmakeExecutable.value());
Environment env = cmakeExecutable.deviceEnvironment();
- CMakePresets::Macros::expand(configurePreset, env, importPath);
+ CMakePresets::Macros::expand(configurePreset, env, sourceDirectory);
env.setupEnglishOutput();
cmake.setEnvironment(env);
@@ -208,9 +210,14 @@ static CMakeConfig configurationFromPresetProbe(
: CMakeConfig();
auto expandCacheValue =
- [configurePreset, env, importPath, cache](const QString &key) -> QString {
+ [configurePreset, env, sourceDirectory, cache](const QString &key) -> QString {
QString result = cache.stringValueOf(key.toUtf8());
- CMakePresets::Macros::expand(configurePreset, env, importPath, result);
+ CMakePresets::Macros::expand(configurePreset, env, sourceDirectory, result);
+
+ // all usages involve file paths, so make sure they are cleaned up
+ const FilePaths paths = transform(result.split(";"), &FilePath::fromUserInput);
+ result = transform(paths, &FilePath::path).join(";");
+
return result;
};
@@ -665,7 +672,7 @@ QList<void *> CMakeProjectImporter::examineDirectory(const FilePath &importPath,
if (cache.valueOf("CMAKE_C_COMPILER").isEmpty()
&& cache.valueOf("CMAKE_CXX_COMPILER").isEmpty()) {
QApplication::setOverrideCursor(Qt::WaitCursor);
- config = configurationFromPresetProbe(importPath, configurePreset);
+ config = configurationFromPresetProbe(importPath, projectDirectory(), configurePreset);
QApplication::restoreOverrideCursor();
if (!configurePreset.generator) {
diff --git a/src/plugins/cmakeprojectmanager/presetsmacros.cpp b/src/plugins/cmakeprojectmanager/presetsmacros.cpp
index 4dd25c3b1d..71cff64e1b 100644
--- a/src/plugins/cmakeprojectmanager/presetsmacros.cpp
+++ b/src/plugins/cmakeprojectmanager/presetsmacros.cpp
@@ -144,6 +144,9 @@ void expand(const PresetType &preset,
return env.value(macroName);
});
+ // Make sure to expand the CMake macros also for environment variables
+ expandAllButEnv(preset, sourceDirectory, value);
+
if (append)
env.appendOrSet(key, value, sep);
else
@@ -182,6 +185,9 @@ void expand(const PresetType &preset,
return QString("${%1}").arg(macroName);
});
+ // Make sure to expand the CMake macros also for environment variables
+ expandAllButEnv(preset, sourceDirectory, value);
+
envItems.emplace_back(Utils::EnvironmentItem(key, value, operation));
}
}
@@ -202,6 +208,9 @@ void expand(const PresetType &preset,
value = expandMacroEnv("penv", value, [env](const QString &macroName) {
return env.value(macroName);
});
+
+ // Make sure to expand the CMake macros also for environment variables
+ expandAllButEnv(preset, sourceDirectory, value);
}
void updateToolchainFile(