forked from qt-creator/qt-creator
CMake: Add option to auto-create build directories
Add an option to CMakeTools to force auto-creation of build directories. This does lead to cmake cluttering up the file system with directories, but does not force users to go through the oftentimes long configuration process twice (once in a temporary directory and once in the real location). Task-number: QTCREATORBUG-16794 Change-Id: I68d92fc58638ad0a0a7622b7ef1621e055c9f2a7 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QSet>
|
||||
@@ -72,12 +73,22 @@ BuildDirManager::~BuildDirManager() = default;
|
||||
const Utils::FileName BuildDirManager::workDirectory() const
|
||||
{
|
||||
const Utils::FileName bdir = m_buildConfiguration->buildDirectory();
|
||||
if (bdir.exists())
|
||||
const CMakeTool *cmake = CMakeKitInformation::cmakeTool(m_buildConfiguration->target()->kit());
|
||||
if (bdir.exists()) {
|
||||
return bdir;
|
||||
} else {
|
||||
if (cmake && cmake->autoCreateBuildDirectory()) {
|
||||
if (!QDir().mkpath(bdir.toString()))
|
||||
emitErrorOccured(tr("Failed to create build directory \"%1\".").arg(bdir.toUserOutput()));
|
||||
return bdir;
|
||||
}
|
||||
}
|
||||
if (!m_tempDir) {
|
||||
m_tempDir.reset(new Utils::TemporaryDirectory("qtc-cmake-XXXXXXXX"));
|
||||
if (!m_tempDir->isValid())
|
||||
emitErrorOccured(tr("Failed to create temporary directory \"%1\".").arg(m_tempDir->path()));
|
||||
if (!m_tempDir->isValid()) {
|
||||
emitErrorOccured(tr("Failed to create temporary directory \"%1\".")
|
||||
.arg(QDir::toNativeSeparators(m_tempDir->path())));
|
||||
}
|
||||
}
|
||||
return Utils::FileName::fromString(m_tempDir->path());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user