forked from qt-creator/qt-creator
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 <cristian.adam@qt.io>
This commit is contained in:
@@ -111,7 +111,7 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *target, Utils::Id id)
|
|||||||
if (oldDir.isEmpty())
|
if (oldDir.isEmpty())
|
||||||
return newDir;
|
return newDir;
|
||||||
|
|
||||||
if (QDir(oldDir).exists("CMakeCache.txt")) {
|
if (QDir(oldDir).exists("CMakeCache.txt") && !QDir(newDir).exists("CMakeCache.txt")) {
|
||||||
if (QMessageBox::information(nullptr,
|
if (QMessageBox::information(nullptr,
|
||||||
tr("Changing Build Directory"),
|
tr("Changing Build Directory"),
|
||||||
tr("Change the build directory and start with a "
|
tr("Change the build directory and start with a "
|
||||||
|
@@ -766,13 +766,22 @@ void CMakeBuildSystem::wireUpConnections()
|
|||||||
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
||||||
CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
||||||
});
|
});
|
||||||
connect(cmakeBuildConfiguration(), &CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() {
|
connect(cmakeBuildConfiguration(),
|
||||||
|
&CMakeBuildConfiguration::buildDirectoryChanged,
|
||||||
|
this,
|
||||||
|
[this]() {
|
||||||
// The build directory of our BC has changed:
|
// The build directory of our BC has changed:
|
||||||
// Run with initial arguments!
|
// 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";
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change";
|
||||||
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
const BuildDirParameters parameters(cmakeBuildConfiguration());
|
||||||
CMakeBuildSystem::REPARSE_FORCE_INITIAL_CONFIGURATION
|
const bool hasCMakeCache = QFile::exists(
|
||||||
| CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
(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]() {
|
connect(project(), &Project::projectFileIsDirty, this, [this]() {
|
||||||
|
Reference in New Issue
Block a user