summaryrefslogtreecommitdiffstats
path: root/Source/QtDialog
diff options
context:
space:
mode:
authorCode Smith <codesmith512@gmail.com>2020-02-05 02:34:35 (GMT)
committerBrad King <brad.king@kitware.com>2020-02-06 16:59:08 (GMT)
commit9a71fa46e7772af52f293ba32f57097f56116b20 (patch)
tree8e16dc69931fec8270b6ddc350b7e2c452c37b7b /Source/QtDialog
parentb49e5344e790507b0eebc4768d6f338d30138514 (diff)
downloadCMake-9a71fa46e7772af52f293ba32f57097f56116b20.zip
CMake-9a71fa46e7772af52f293ba32f57097f56116b20.tar.gz
CMake-9a71fa46e7772af52f293ba32f57097f56116b20.tar.bz2
cmake-gui: set generator field defaults from environment
Fixes: #20251
Diffstat (limited to 'Source/QtDialog')
-rw-r--r--Source/QtDialog/FirstConfigure.cxx49
-rw-r--r--Source/QtDialog/FirstConfigure.h5
2 files changed, 51 insertions, 3 deletions
diff --git a/Source/QtDialog/FirstConfigure.cxx b/Source/QtDialog/FirstConfigure.cxx
index ca28b19..3c24b9b 100644
--- a/Source/QtDialog/FirstConfigure.cxx
+++ b/Source/QtDialog/FirstConfigure.cxx
@@ -10,8 +10,12 @@
#include "Compilers.h"
-StartCompilerSetup::StartCompilerSetup(QWidget* p)
+StartCompilerSetup::StartCompilerSetup(QString defaultGeneratorPlatform,
+ QString defaultGeneratorToolset,
+ QWidget* p)
: QWizardPage(p)
+ , DefaultGeneratorPlatform(std::move(defaultGeneratorPlatform))
+ , DefaultGeneratorToolset(std::move(defaultGeneratorToolset))
{
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(new QLabel(tr("Specify the generator for this project")));
@@ -68,6 +72,10 @@ QFrame* StartCompilerSetup::CreateToolsetWidgets()
Toolset = new QLineEdit(frame);
l->addWidget(Toolset);
+ // Default to CMAKE_GENERATOR_TOOLSET env var if set
+ if (!DefaultGeneratorToolset.isEmpty()) {
+ this->Toolset->setText(DefaultGeneratorToolset);
+ }
return frame;
}
@@ -199,6 +207,14 @@ void StartCompilerSetup::onGeneratorChanged(QString const& name)
this->PlatformOptions->addItems(platform_list);
PlatformFrame->show();
+
+ // Default to generator platform from environment
+ if (!DefaultGeneratorPlatform.isEmpty()) {
+ int platform_index = platforms.indexOf(DefaultGeneratorPlatform);
+ if (platform_index != -1) {
+ this->PlatformOptions->setCurrentIndex(platform_index);
+ }
+ }
} else {
PlatformFrame->hide();
}
@@ -421,8 +437,26 @@ void ToolchainCompilerSetup::setToolchainFile(const QString& t)
FirstConfigure::FirstConfigure()
{
+ const char* env_generator = std::getenv("CMAKE_GENERATOR");
+ const char* env_generator_platform = nullptr;
+ const char* env_generator_toolset = nullptr;
+ if (env_generator && std::strlen(env_generator)) {
+ mDefaultGenerator = env_generator;
+ env_generator_platform = std::getenv("CMAKE_GENERATOR_PLATFORM");
+ env_generator_toolset = std::getenv("CMAKE_GENERATOR_TOOLSET");
+ }
+
+ if (!env_generator_platform) {
+ env_generator_platform = "";
+ }
+
+ if (!env_generator_toolset) {
+ env_generator_toolset = "";
+ }
+
// this->setOption(QWizard::HaveFinishButtonOnEarlyPages, true);
- this->mStartCompilerSetupPage = new StartCompilerSetup(this);
+ this->mStartCompilerSetupPage = new StartCompilerSetup(
+ env_generator_platform, env_generator_toolset, this);
this->setPage(Start, this->mStartCompilerSetupPage);
QObject::connect(this->mStartCompilerSetupPage, SIGNAL(selectionChanged()),
this, SLOT(restart()));
@@ -504,6 +538,17 @@ void FirstConfigure::loadFromSettings()
this->mCrossCompilerSetupPage->setIncludeMode(
settings.value("IncludeMode", 0).toInt());
settings.endGroup();
+
+ // environment variables take precedence over application settings because...
+ // - they're harder to set
+ // - settings always exist after the program is run once, so the environment
+ // variables would never be used otherwise
+ // - platform and toolset are populated only from environment variables, so
+ // this prevents them from being taken from environment, while the
+ // generator is taken from application settings
+ if (!mDefaultGenerator.isEmpty()) {
+ this->mStartCompilerSetupPage->setCurrentGenerator(mDefaultGenerator);
+ }
}
void FirstConfigure::saveToSettings()
diff --git a/Source/QtDialog/FirstConfigure.h b/Source/QtDialog/FirstConfigure.h
index d1db5bf..c26f489 100644
--- a/Source/QtDialog/FirstConfigure.h
+++ b/Source/QtDialog/FirstConfigure.h
@@ -29,7 +29,8 @@ class StartCompilerSetup : public QWizardPage
{
Q_OBJECT
public:
- StartCompilerSetup(QWidget* p);
+ StartCompilerSetup(QString defaultGeneratorPlatform,
+ QString defaultGeneratorToolset, QWidget* p);
~StartCompilerSetup();
void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
void setCurrentGenerator(const QString& gen);
@@ -64,6 +65,7 @@ protected:
QStringList GeneratorsSupportingPlatform;
QMultiMap<QString, QString> GeneratorSupportedPlatforms;
QMap<QString, QString> GeneratorDefaultPlatform;
+ QString DefaultGeneratorPlatform, DefaultGeneratorToolset;
private:
QFrame* CreateToolsetWidgets();
@@ -197,6 +199,7 @@ protected:
NativeCompilerSetup* mNativeCompilerSetupPage;
CrossCompilerSetup* mCrossCompilerSetupPage;
ToolchainCompilerSetup* mToolchainCompilerSetupPage;
+ QString mDefaultGenerator;
};
#endif // FirstConfigure_h