From 05acf3e6f42853d65372aeb3dbb4ca647e6b9e9c Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Wed, 5 Oct 2022 21:08:54 +0200 Subject: [PATCH] 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 --- .../cmakeprojectmanager/cmakeprojectimporter.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp index 4be73541a80..e870b787bc9 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectimporter.cpp @@ -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);