CMakePM: Do not display duplicated build paths for presets

If we configure a project with presets, build all the configurations,
then delete the CMakeLists.txt.user file to re-configure the presets, we
shouldn't get two entries in the initial configuration dialog.

Change-Id: I9bb234aa54fcce193dbd07dd3aa77e91f639b179
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2022-10-05 21:08:54 +02:00
parent e54fb7ab64
commit 05acf3e6f4

View File

@@ -131,6 +131,20 @@ FilePaths CMakeProjectImporter::importCandidates()
const FilePath configPresetDir = m_presetsTempDir.filePath(configPreset.name);
configPresetDir.createDir();
candidates << configPresetDir;
// If the binaryFilePath exists, do not try to import the existing build, so that
// we don't have duplicates, one from the preset and one from the previous configuration.
if (configPreset.binaryDir) {
Environment env = Environment::systemEnvironment();
CMakePresets::Macros::expand(configPreset, env, projectDirectory());
QString binaryDir = configPreset.binaryDir.value();
CMakePresets::Macros::expand(configPreset, env, projectDirectory(), binaryDir);
const FilePath binaryFilePath = FilePath::fromString(binaryDir);
candidates.removeIf(
[&binaryFilePath] (const FilePath &path) { return path == binaryFilePath; });
}
}
const FilePaths finalists = Utils::filteredUnique(candidates);