Merge topic 'cmake-gui-generator-platform'

67bced8a26 cmake-gui: Improve label for default platform
48ec0bc140 cmake-gui: Add field for generator platform selection
8bba458ea5 Add global generator factory method to get default platform name
818df52c48 Add global generator factory method to get list of known platforms
8144b00e32 Split global generator factory list with and without platforms
b70c0aed5c VS: Factor out helper function to compute host platform name

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !2832
This commit is contained in:
Brad King
2019-01-22 14:28:12 +00:00
committed by Kitware Robot
15 changed files with 341 additions and 29 deletions

View File

@@ -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();

View File

@@ -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,23 @@ 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("Optional platform for generator"));
l->addWidget(this->PlatformLabel);
this->PlatformOptions = new QComboBox(frame);
this->PlatformOptions->setEditable(true);
l->addWidget(this->PlatformOptions);
return frame;
}
StartCompilerSetup::~StartCompilerSetup()
{
}
@@ -80,6 +101,26 @@ 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()));
this
->GeneratorDefaultPlatform[QString::fromLocal8Bit(it->name.c_str())] =
QString::fromLocal8Bit(it->defaultPlatform.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 +143,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 +182,31 @@ void StartCompilerSetup::onSelectionChanged(bool on)
void StartCompilerSetup::onGeneratorChanged(QString const& name)
{
// Display the generator platform for the generators supporting it
if (GeneratorsSupportingPlatform.contains(name)) {
// Change the label title to include the default platform
std::string label = "Optional platform for generator";
label += "(if empty, generator uses: ";
label += this->GeneratorDefaultPlatform[name].toStdString();
label += ")";
this->PlatformLabel->setText(tr(label.c_str()));
// 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 +461,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();

View File

@@ -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,17 @@ protected:
QFrame* ToolsetFrame;
QLineEdit* Toolset;
QLabel* ToolsetLabel;
QFrame* PlatformFrame;
QComboBox* PlatformOptions;
QLabel* PlatformLabel;
QStringList GeneratorsSupportingToolset;
QStringList GeneratorsSupportingPlatform;
QMultiMap<QString, QString> GeneratorSupportedPlatforms;
QMap<QString, QString> GeneratorDefaultPlatform;
private:
QFrame* CreateToolsetWidgets();
QFrame* CreatePlatformWidgets();
};
//! the page that gives basic options for native compilers
@@ -159,6 +167,7 @@ public:
void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
QString getGenerator() const;
QString getPlatform() const;
QString getToolset() const;
bool defaultSetup() const;

View File

@@ -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);

View File

@@ -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;

View File

@@ -30,13 +30,20 @@ public:
virtual void GetDocumentation(cmDocumentationEntry& entry) const = 0;
/** Get the names of the current registered generators */
virtual void GetGenerators(std::vector<std::string>& names) const = 0;
virtual std::vector<std::string> GetGeneratorNames() const = 0;
virtual std::vector<std::string> GetGeneratorNamesWithPlatform() const = 0;
/** Determine whether or not this generator supports toolsets */
virtual bool SupportsToolset() const = 0;
/** Determine whether or not this generator supports platforms */
virtual bool SupportsPlatform() const = 0;
/** Get the list of supported platforms name for this generator */
virtual std::vector<std::string> GetKnownPlatforms() const = 0;
/** If the generator suports platforms, get its default. */
virtual std::string GetDefaultPlatformName() const = 0;
};
template <class T>
@@ -60,9 +67,15 @@ public:
}
/** Get the names of the current registered generators */
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(T::GetActualName());
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
return std::vector<std::string>();
}
/** Determine whether or not this generator supports toolsets */
@@ -70,6 +83,15 @@ public:
/** Determine whether or not this generator supports platforms */
bool SupportsPlatform() const override { return T::SupportsPlatform(); }
/** Get the list of supported platforms name for this generator */
std::vector<std::string> GetKnownPlatforms() const override
{
// default is no platform supported
return std::vector<std::string>();
}
std::string GetDefaultPlatformName() const override { return std::string(); }
};
#endif

View File

@@ -74,15 +74,34 @@ public:
"Optional [arch] can be \"Win64\" or \"IA64\".";
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs10generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
std::vector<std::string> names;
names.push_back(vs10generatorName + std::string(" IA64"));
names.push_back(vs10generatorName + std::string(" Win64"));
return names;
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("Itanium");
return platforms;
}
std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory()

View File

@@ -69,9 +69,16 @@ public:
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs11generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
std::vector<std::string> names;
names.push_back(vs11generatorName + std::string(" ARM"));
names.push_back(vs11generatorName + std::string(" Win64"));
@@ -80,10 +87,30 @@ public:
for (std::string const& i : installedSDKs) {
names.push_back(std::string(vs11generatorName) + " " + i);
}
return names;
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("ARM");
std::set<std::string> installedSDKs =
cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs();
for (std::string const& i : installedSDKs) {
platforms.emplace_back(i);
}
return platforms;
}
std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory()

View File

@@ -58,15 +58,34 @@ public:
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs12generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
std::vector<std::string> names;
names.push_back(vs12generatorName + std::string(" ARM"));
names.push_back(vs12generatorName + std::string(" Win64"));
return names;
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("ARM");
return platforms;
}
std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory()

View File

@@ -58,15 +58,34 @@ public:
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs14generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
std::vector<std::string> names;
names.push_back(vs14generatorName + std::string(" ARM"));
names.push_back(vs14generatorName + std::string(" Win64"));
return names;
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("ARM");
return platforms;
}
std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio14Generator::NewFactory()

View File

@@ -59,9 +59,16 @@ public:
"Optional [arch] can be \"Win64\" or \"IA64\".";
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs9generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
std::vector<std::string> names;
names.push_back(vs9generatorName + std::string(" Win64"));
names.push_back(vs9generatorName + std::string(" IA64"));
cmVisualStudioWCEPlatformParser parser;
@@ -71,10 +78,29 @@ public:
for (std::string const& i : availablePlatforms) {
names.push_back("Visual Studio 9 2008 " + i);
}
return names;
}
bool SupportsToolset() const override { return false; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("Itanium");
cmVisualStudioWCEPlatformParser parser;
parser.ParseVersion("9.0");
const std::vector<std::string>& availablePlatforms =
parser.GetAvailablePlatforms();
for (std::string const& i : availablePlatforms) {
platforms.emplace_back(i);
}
return platforms;
}
std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory()

View File

@@ -19,6 +19,20 @@
# include "cmsys/SystemInformation.hxx"
#endif
static std::string VSHostPlatformName()
{
#ifdef HOST_PLATFORM_NAME
return HOST_PLATFORM_NAME;
#else
cmsys::SystemInformation info;
if (info.Is64Bits()) {
return "x64";
} else {
return "Win32";
}
#endif
}
static unsigned int VSVersionToMajor(
cmGlobalVisualStudioGenerator::VSVersion v)
{
@@ -118,15 +132,35 @@ public:
"Optional [arch] can be \"Win64\" or \"ARM\".";
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs15generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
std::vector<std::string> names;
names.push_back(vs15generatorName + std::string(" ARM"));
names.push_back(vs15generatorName + std::string(" Win64"));
return names;
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("ARM");
platforms.emplace_back("ARM64");
return platforms;
}
std::string GetDefaultPlatformName() const override { return "Win32"; }
};
cmGlobalGeneratorFactory*
@@ -178,13 +212,35 @@ public:
"Use -A option to specify architecture.";
}
virtual void GetGenerators(std::vector<std::string>& names) const
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(vs16generatorName);
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
return std::vector<std::string>();
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return true; }
std::vector<std::string> GetKnownPlatforms() const override
{
std::vector<std::string> platforms;
platforms.emplace_back("x64");
platforms.emplace_back("Win32");
platforms.emplace_back("ARM");
platforms.emplace_back("ARM64");
return platforms;
}
std::string GetDefaultPlatformName() const override
{
return VSHostPlatformName();
}
};
cmGlobalGeneratorFactory*
@@ -206,16 +262,7 @@ cmGlobalVisualStudioVersionedGenerator::cmGlobalVisualStudioVersionedGenerator(
this->DefaultCSharpFlagTableName = VSVersionToToolset(this->Version);
this->DefaultLinkFlagTableName = VSVersionToToolset(this->Version);
if (this->Version >= cmGlobalVisualStudioGenerator::VS16) {
#ifdef HOST_PLATFORM_NAME
this->DefaultPlatformName = HOST_PLATFORM_NAME;
#else
cmsys::SystemInformation info;
if (info.Is64Bits()) {
this->DefaultPlatformName = "x64";
} else {
this->DefaultPlatformName = "Win32";
}
#endif
this->DefaultPlatformName = VSHostPlatformName();
}
}

View File

@@ -133,13 +133,27 @@ public:
cmGlobalXCodeGenerator::GetDocumentation(entry);
}
void GetGenerators(std::vector<std::string>& names) const override
std::vector<std::string> GetGeneratorNames() const override
{
std::vector<std::string> names;
names.push_back(cmGlobalXCodeGenerator::GetActualName());
return names;
}
std::vector<std::string> GetGeneratorNamesWithPlatform() const override
{
return std::vector<std::string>();
}
bool SupportsToolset() const override { return true; }
bool SupportsPlatform() const override { return false; }
std::vector<std::string> GetKnownPlatforms() const override
{
return std::vector<std::string>();
}
std::string GetDefaultPlatformName() const override { return std::string(); }
};
cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(

View File

@@ -959,17 +959,25 @@ void cmake::AddDefaultExtraGenerators()
#endif
}
void cmake::GetRegisteredGenerators(
std::vector<GeneratorInfo>& generators) const
void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
bool includeNamesWithPlatform) const
{
for (cmGlobalGeneratorFactory* gen : this->Generators) {
std::vector<std::string> names;
gen->GetGenerators(names);
std::vector<std::string> names = gen->GetGeneratorNames();
if (includeNamesWithPlatform) {
std::vector<std::string> namesWithPlatform =
gen->GetGeneratorNamesWithPlatform();
names.insert(names.end(), namesWithPlatform.begin(),
namesWithPlatform.end());
}
for (std::string const& name : names) {
GeneratorInfo info;
info.supportsToolset = gen->SupportsToolset();
info.supportsPlatform = gen->SupportsPlatform();
info.supportedPlatforms = gen->GetKnownPlatforms();
info.defaultPlatform = gen->GetDefaultPlatformName();
info.name = name;
info.baseName = name;
info.isAlias = false;

View File

@@ -104,6 +104,8 @@ public:
std::string extraName;
bool supportsToolset;
bool supportsPlatform;
std::vector<std::string> supportedPlatforms;
std::string defaultPlatform;
bool isAlias;
};
@@ -196,7 +198,8 @@ public:
void SetGlobalGenerator(cmGlobalGenerator*);
///! Get the names of the current registered generators
void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators) const;
void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators,
bool includeNamesWithPlatform = true) const;
///! Set the name of the selected generator-specific instance.
void SetGeneratorInstance(std::string const& instance)