diff options
author | Brad King <brad.king@kitware.com> | 2024-06-06 12:40:48 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-06-06 12:41:00 (GMT) |
commit | 2f657e448b293706055e237c449591e70c542a3c (patch) | |
tree | f85353f3f624b051618629d5d27f247d3b31eb96 /Source | |
parent | 0833cf8d0a02e14f1d25c53d43843ef7c596a5de (diff) | |
parent | a872844908ed8d95a39de5596cd44212787c5863 (diff) | |
download | CMake-2f657e448b293706055e237c449591e70c542a3c.zip CMake-2f657e448b293706055e237c449591e70c542a3c.tar.gz CMake-2f657e448b293706055e237c449591e70c542a3c.tar.bz2 |
Merge topic 'gui-relative-build-path' into release-3.30
a872844908 cmake-gui: Handle relative paths in the build directory text input
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !9459
Diffstat (limited to 'Source')
-rw-r--r-- | Source/QtDialog/CMakeSetupDialog.cxx | 34 | ||||
-rw-r--r-- | Source/QtDialog/QCMake.cxx | 29 | ||||
-rw-r--r-- | Source/QtDialog/QCMake.h | 3 |
3 files changed, 60 insertions, 6 deletions
diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 2a6a831..af6cf74 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -350,8 +350,24 @@ void CMakeSetupDialog::initialize() if (!this->SourceDirectory->text().isEmpty() && !this->DeferredPreset.isNull()) { this->onSourceDirectoryChanged(this->SourceDirectory->text()); + if (!this->BinaryDirectory->lineEdit()->text().isEmpty()) { + this->onBinaryDirectoryChanged( + this->BinaryDirectory->lineEdit()->text()); + } } else if (!this->SourceDirectory->text().isEmpty() || !this->BinaryDirectory->lineEdit()->text().isEmpty()) { + if (this->SourceDirectory->text().isEmpty() && + !cmSystemTools::FileIsFullPath( + this->BinaryDirectory->lineEdit()->text().toStdString())) { + // If the binary directory is relative, load the previous source path + // from the config + QSettings settings; + settings.beginGroup("Settings/StartPath"); + QString srcDir = settings.value(QString("WhereSource")).toString(); + this->SourceDirectory->blockSignals(true); + this->SourceDirectory->setText(srcDir); + this->SourceDirectory->blockSignals(false); + } this->onSourceDirectoryChanged(this->SourceDirectory->text()); this->onBinaryDirectoryChanged(this->BinaryDirectory->lineEdit()->text()); } else { @@ -411,8 +427,13 @@ bool CMakeSetupDialog::prepareConfigure() } } - // remember path - this->addBinaryPath(dir.absolutePath()); + // remember paths + this->addBinaryPath( + this->CMakeThread->cmakeInstance()->relativeBinaryDirectory()); + QSettings settings; + settings.beginGroup("Settings/StartPath"); + settings.setValue("WhereSource", + this->CMakeThread->cmakeInstance()->sourceDirectory()); return true; } @@ -742,8 +763,15 @@ void CMakeSetupDialog::showPresetLoadError(const QString& dir, void CMakeSetupDialog::doBinaryBrowse() { + QString abs_path = this->BinaryDirectory->currentText(); + if (!cmSystemTools::FileIsFullPath(abs_path.toStdString())) { + if (!this->SourceDirectory->text().endsWith("/")) { + abs_path = "/" + abs_path; + } + abs_path = this->SourceDirectory->text() + abs_path; + } QString dir = QFileDialog::getExistingDirectory( - this, tr("Enter Path to Build"), this->BinaryDirectory->currentText(), + this, tr("Enter Path to Build"), abs_path, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!dir.isEmpty() && dir != this->BinaryDirectory->currentText()) { this->setBinaryDirectory(dir); diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 9a87416..45c4717 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -94,6 +94,10 @@ void QCMake::setSourceDirectory(const QString& _dir) emit this->sourceDirChanged(this->SourceDirectory); this->loadPresets(); this->setPreset(QString{}); + if (!cmSystemTools::FileIsFullPath( + this->MaybeRelativeBinaryDirectory.toStdString())) { + this->setBinaryDirectory(this->MaybeRelativeBinaryDirectory); + } } } @@ -101,9 +105,23 @@ void QCMake::setBinaryDirectory(const QString& _dir) { QString dir = QString::fromStdString( cmSystemTools::GetActualCaseForPath(_dir.toStdString())); - if (this->BinaryDirectory != dir) { - this->BinaryDirectory = QDir::fromNativeSeparators(dir); - emit this->binaryDirChanged(this->BinaryDirectory); + + QString absDir = dir; + + if (!cmSystemTools::FileIsFullPath(absDir.toStdString())) { + if (!this->SourceDirectory.isEmpty()) { + if (!this->SourceDirectory.endsWith("/")) { + absDir = "/" + absDir; + } + absDir = this->SourceDirectory + absDir; + } + } + + if (this->BinaryDirectory != absDir || + this->MaybeRelativeBinaryDirectory != dir) { + this->MaybeRelativeBinaryDirectory = QDir::fromNativeSeparators(dir); + this->BinaryDirectory = QDir::fromNativeSeparators(absDir); + emit this->binaryDirChanged(this->MaybeRelativeBinaryDirectory); cmState* state = this->CMakeInstance->GetState(); this->setGenerator(QString()); this->setToolset(QString()); @@ -600,6 +618,11 @@ QString QCMake::binaryDirectory() const return this->BinaryDirectory; } +QString QCMake::relativeBinaryDirectory() const +{ + return this->MaybeRelativeBinaryDirectory; +} + QString QCMake::sourceDirectory() const { return this->SourceDirectory; diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index 0890558..d42dac4 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -130,6 +130,8 @@ public: QCMakePropertyList properties() const; /// get the current binary directory QString binaryDirectory() const; + /// get the current binary directory, possibly a relative path + QString relativeBinaryDirectory() const; /// get the current source directory QString sourceDirectory() const; /// get the current generator @@ -196,6 +198,7 @@ protected: bool WarnUninitializedMode; QString SourceDirectory; QString BinaryDirectory; + QString MaybeRelativeBinaryDirectory; QString Generator; QString Platform; QString Toolset; |