Просмотр исходного кода

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
Julien Jomier 6 лет назад
Родитель
Сommit
48ec0bc140

+ 1 - 0
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();

+ 68 - 2
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<std::string>::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<QString> 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();

+ 8 - 0
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<QString, QString> GeneratorSupportedPlatforms;
 
 private:
   QFrame* CreateToolsetWidgets();
+  QFrame* CreatePlatformWidgets();
 };
 
 //! the page that gives basic options for native compilers
@@ -159,6 +166,7 @@ public:
 
   void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
   QString getGenerator() const;
+  QString getPlatform() const;
   QString getToolset() const;
 
   bool defaultSetup() const;

+ 19 - 2
Source/QtDialog/QCMake.cxx

@@ -35,7 +35,8 @@ QCMake::QCMake(QObject* p)
   cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
 
   std::vector<cmake::GeneratorInfo> generators;
-  this->CMakeInstance->GetRegisteredGenerators(generators);
+  this->CMakeInstance->GetRegisteredGenerators(
+    generators, /*includeNamesWithPlatform=*/false);
 
   std::vector<cmake::GeneratorInfo>::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);

+ 5 - 0
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<cmake::GeneratorInfo> AvailableGenerators;
   QString CMakeExecutable;