From 48ec0bc1401b99e5a2d07392fb98f96d5fec9e50 Mon Sep 17 00:00:00 2001 From: Julien Jomier Date: Fri, 4 Jan 2019 12:41:01 +0100 Subject: cmake-gui: Add field for generator platform selection Extend the "first configure" dialog with a field for the user to select a value for `CMAKE_GENERATOR_PLATFORM`. Fixes: #17343 --- Source/QtDialog/CMakeSetupDialog.cxx | 1 + Source/QtDialog/FirstConfigure.cxx | 70 ++++++++++++++++++++++++++++++++++-- Source/QtDialog/FirstConfigure.h | 8 +++++ Source/QtDialog/QCMake.cxx | 21 +++++++++-- Source/QtDialog/QCMake.h | 5 +++ 5 files changed, 101 insertions(+), 4 deletions(-) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 444a980..72cce9f 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -751,6 +751,7 @@ bool CMakeSetupDialog::setupFirstConfigure() if (dialog.exec() == QDialog::Accepted) { dialog.saveToSettings(); this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator()); + this->CMakeThread->cmakeInstance()->setPlatform(dialog.getPlatform()); this->CMakeThread->cmakeInstance()->setToolset(dialog.getToolset()); QCMakeCacheModel* m = this->CacheValues->cacheModel(); diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx index 88ce7cb..66707d6 100644 --- a/Source/QtDialog/FirstConfigure.cxx +++ b/Source/QtDialog/FirstConfigure.cxx @@ -16,8 +16,12 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p) this->GeneratorOptions = new QComboBox(this); l->addWidget(this->GeneratorOptions); + // Add the generator platform + this->PlatformFrame = CreatePlatformWidgets(); + l->addWidget(PlatformFrame); + // Add the ability to specify toolset (-T parameter) - ToolsetFrame = CreateToolsetWidgets(); + this->ToolsetFrame = CreateToolsetWidgets(); l->addWidget(ToolsetFrame); l->addSpacing(6); @@ -45,7 +49,7 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p) SLOT(onSelectionChanged(bool))); QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)), this, SLOT(onSelectionChanged(bool))); - QObject::connect(GeneratorOptions, + QObject::connect(this->GeneratorOptions, SIGNAL(currentIndexChanged(QString const&)), this, SLOT(onGeneratorChanged(QString const&))); } @@ -65,6 +69,24 @@ QFrame* StartCompilerSetup::CreateToolsetWidgets() return frame; } +QFrame* StartCompilerSetup::CreatePlatformWidgets() +{ + QFrame* frame = new QFrame(this); + QVBoxLayout* l = new QVBoxLayout(frame); + l->setContentsMargins(0, 0, 0, 0); + + this->PlatformLabel = + new QLabel(tr("Specify the platform for this generator")); + l->addWidget(this->PlatformLabel); + + this->PlatformOptions = new QComboBox(frame); + this->PlatformOptions->setEditable(true); + + l->addWidget(this->PlatformOptions); + + return frame; +} + StartCompilerSetup::~StartCompilerSetup() { } @@ -80,6 +102,22 @@ void StartCompilerSetup::setGenerators( for (it = gens.begin(); it != gens.end(); ++it) { generator_list.append(QString::fromLocal8Bit(it->name.c_str())); + if (it->supportsPlatform) { + this->GeneratorsSupportingPlatform.append( + QString::fromLocal8Bit(it->name.c_str())); + + std::vector::const_iterator platformIt = + it->supportedPlatforms.cbegin(); + while (platformIt != it->supportedPlatforms.cend()) { + + this->GeneratorSupportedPlatforms.insert( + QString::fromLocal8Bit(it->name.c_str()), + QString::fromLocal8Bit((*platformIt).c_str())); + + platformIt++; + } + } + if (it->supportsToolset) { this->GeneratorsSupportingToolset.append( QString::fromLocal8Bit(it->name.c_str())); @@ -102,6 +140,11 @@ QString StartCompilerSetup::getGenerator() const return this->GeneratorOptions->currentText(); }; +QString StartCompilerSetup::getPlatform() const +{ + return this->PlatformOptions->currentText(); +}; + QString StartCompilerSetup::getToolset() const { return this->Toolset->text(); @@ -136,6 +179,24 @@ void StartCompilerSetup::onSelectionChanged(bool on) void StartCompilerSetup::onGeneratorChanged(QString const& name) { + // Display the generator platform for the generators supporting it + if (GeneratorsSupportingPlatform.contains(name)) { + + // Regenerate the list of supported platform + this->PlatformOptions->clear(); + QStringList platform_list; + platform_list.append(""); + + QList platforms = this->GeneratorSupportedPlatforms.values(name); + platform_list.append(platforms); + + this->PlatformOptions->addItems(platform_list); + PlatformFrame->show(); + } else { + PlatformFrame->hide(); + } + + // Display the toolset box for the generators supporting it if (GeneratorsSupportingToolset.contains(name)) { ToolsetFrame->show(); } else { @@ -390,6 +451,11 @@ QString FirstConfigure::getGenerator() const return this->mStartCompilerSetupPage->getGenerator(); } +QString FirstConfigure::getPlatform() const +{ + return this->mStartCompilerSetupPage->getPlatform(); +} + QString FirstConfigure::getToolset() const { return this->mStartCompilerSetupPage->getToolset(); diff --git a/Source/QtDialog/FirstConfigure.h b/Source/QtDialog/FirstConfigure.h index abfa03f..133f422 100644 --- a/Source/QtDialog/FirstConfigure.h +++ b/Source/QtDialog/FirstConfigure.h @@ -35,6 +35,7 @@ public: void setCurrentGenerator(const QString& gen); QString getGenerator() const; QString getToolset() const; + QString getPlatform() const; bool defaultSetup() const; bool compilerSetup() const; @@ -56,10 +57,16 @@ protected: QFrame* ToolsetFrame; QLineEdit* Toolset; QLabel* ToolsetLabel; + QFrame* PlatformFrame; + QComboBox* PlatformOptions; + QLabel* PlatformLabel; QStringList GeneratorsSupportingToolset; + QStringList GeneratorsSupportingPlatform; + QMultiMap GeneratorSupportedPlatforms; private: QFrame* CreateToolsetWidgets(); + QFrame* CreatePlatformWidgets(); }; //! the page that gives basic options for native compilers @@ -159,6 +166,7 @@ public: void setGenerators(std::vector const& gens); QString getGenerator() const; + QString getPlatform() const; QString getToolset() const; bool defaultSetup() const; diff --git a/Source/QtDialog/QCMake.cxx b/Source/QtDialog/QCMake.cxx index 9a6784e..2eecce6 100644 --- a/Source/QtDialog/QCMake.cxx +++ b/Source/QtDialog/QCMake.cxx @@ -35,7 +35,8 @@ QCMake::QCMake(QObject* p) cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this); std::vector generators; - this->CMakeInstance->GetRegisteredGenerators(generators); + this->CMakeInstance->GetRegisteredGenerators( + generators, /*includeNamesWithPlatform=*/false); std::vector::const_iterator it; for (it = generators.begin(); it != generators.end(); ++it) { @@ -74,6 +75,7 @@ void QCMake::setBinaryDirectory(const QString& _dir) cmState* state = this->CMakeInstance->GetState(); this->setGenerator(QString()); this->setToolset(QString()); + this->setPlatform(QString()); if (!this->CMakeInstance->LoadCache( this->BinaryDirectory.toLocal8Bit().data())) { QDir testDir(this->BinaryDirectory); @@ -102,6 +104,12 @@ void QCMake::setBinaryDirectory(const QString& _dir) this->setGenerator(QString::fromLocal8Bit(curGen.c_str())); } + const char* platform = + state->GetCacheEntryValue("CMAKE_GENERATOR_PLATFORM"); + if (platform) { + this->setPlatform(QString::fromLocal8Bit(platform)); + } + const char* toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET"); if (toolset) { this->setToolset(QString::fromLocal8Bit(toolset)); @@ -119,6 +127,14 @@ void QCMake::setGenerator(const QString& gen) } } +void QCMake::setPlatform(const QString& platform) +{ + if (this->Platform != platform) { + this->Platform = platform; + emit this->platformChanged(this->Platform); + } +} + void QCMake::setToolset(const QString& toolset) { if (this->Toolset != toolset) { @@ -140,7 +156,8 @@ void QCMake::configure() this->CMakeInstance->SetGlobalGenerator( this->CMakeInstance->CreateGlobalGenerator( this->Generator.toLocal8Bit().data())); - this->CMakeInstance->SetGeneratorPlatform(""); + this->CMakeInstance->SetGeneratorPlatform( + this->Platform.toLocal8Bit().data()); this->CMakeInstance->SetGeneratorToolset(this->Toolset.toLocal8Bit().data()); this->CMakeInstance->LoadCache(); this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode); diff --git a/Source/QtDialog/QCMake.h b/Source/QtDialog/QCMake.h index 4b3920a..c84da58 100644 --- a/Source/QtDialog/QCMake.h +++ b/Source/QtDialog/QCMake.h @@ -75,6 +75,8 @@ public slots: /// set the desired generator to use void setGenerator(const QString& generator); /// set the desired generator to use + void setPlatform(const QString& platform); + /// set the desired generator to use void setToolset(const QString& toolset); /// do the configure step void configure(); @@ -155,6 +157,8 @@ signals: void debugOutputChanged(bool); /// signal when the toolset changes void toolsetChanged(const QString& toolset); + /// signal when the platform changes + void platformChanged(const QString& platform); /// signal when open is done void openDone(bool successful); /// signal when open is done @@ -175,6 +179,7 @@ protected: QString SourceDirectory; QString BinaryDirectory; QString Generator; + QString Platform; QString Toolset; std::vector AvailableGenerators; QString CMakeExecutable; -- cgit v0.12