From 3ef279450bd026c9bbfde9d32321cd857655cea3 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Wed, 25 Nov 2020 17:56:03 +0100 Subject: [PATCH] CMake: Don't overwrite existing builds when changing build dir When changing a build configuration's build directory to a directory with an existing build (i.e. CMakeCache.txt), do not overwrite it, but just parse it (running CMake as needed to generate the fileapi response). Do not ask funny questions in that case. This solves the pattern that you want to use some preconfigured build but configured the right kit already with the default parameters. Switching to a different build directory should simply never "kill" an existing build in any case (and running CMake with the "initial arguments" basically kills the existing build in the not-so-uncommon case). Change-Id: I54ca1f14d72a11a3bfe5b09ce340b28be321f80e Reviewed-by: Cristian Adam --- .../cmakebuildconfiguration.cpp | 2 +- .../cmakeprojectmanager/cmakebuildsystem.cpp | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 1dcf14f3970..6b396a2aadb 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -111,7 +111,7 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *target, Utils::Id id) if (oldDir.isEmpty()) return newDir; - if (QDir(oldDir).exists("CMakeCache.txt")) { + if (QDir(oldDir).exists("CMakeCache.txt") && !QDir(newDir).exists("CMakeCache.txt")) { if (QMessageBox::information(nullptr, tr("Changing Build Directory"), tr("Change the build directory and start with a " diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index c890f3f4227..2f332dc7e9a 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -766,14 +766,23 @@ void CMakeBuildSystem::wireUpConnections() setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()), CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN); }); - connect(cmakeBuildConfiguration(), &CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() { - // The build directory of our BC has changed: - // Run with initial arguments! - qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change"; - setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()), - CMakeBuildSystem::REPARSE_FORCE_INITIAL_CONFIGURATION - | CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN); - }); + connect(cmakeBuildConfiguration(), + &CMakeBuildConfiguration::buildDirectoryChanged, + this, + [this]() { + // The build directory of our BC has changed: + // Does the directory contain a CMakeCache ? Existing build, just parse + // No CMakeCache? Run with initial arguments! + qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change"; + const BuildDirParameters parameters(cmakeBuildConfiguration()); + const bool hasCMakeCache = QFile::exists( + (parameters.buildDirectory / "CMakeCache.txt").toString()); + const auto options = ReparseParameters( + hasCMakeCache + ? REPARSE_DEFAULT + : (REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN)); + setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()), options); + }); connect(project(), &Project::projectFileIsDirty, this, [this]() { if (cmakeBuildConfiguration()->isActive() && !isParsing()) {