cmake-gui: Add option to specify generator toolset

The -T parameter to CMake may now be specified through cmake-gui via a
new text field in the first-time configure wizard (below the generator
chooser).

The generator factories specify whether or not they support toolsets.
This information is propagated to the Qt code and used to determine if
the selected generator should also display the optional Toolset widgets.
This commit is contained in:
Robert Dailey 2015-02-15 13:17:54 -06:00 committed by Brad King
parent 30b0db7bb5
commit 2b958a2027
21 changed files with 203 additions and 26 deletions

View File

@ -0,0 +1,6 @@
cmake-gui-select-toolset
------------------------
* The :manual:`cmake-gui(1)` learned an option to set the toolset
to be used with VS IDE and Xcode generators, much like the
existing ``-T`` option to :manual:`cmake(1)`.

View File

@ -734,6 +734,7 @@ bool CMakeSetupDialog::setupFirstConfigure()
{ {
dialog.saveToSettings(); dialog.saveToSettings();
this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator()); this->CMakeThread->cmakeInstance()->setGenerator(dialog.getGenerator());
this->CMakeThread->cmakeInstance()->setToolset(dialog.getToolset());
QCMakeCacheModel* m = this->CacheValues->cacheModel(); QCMakeCacheModel* m = this->CacheValues->cacheModel();

View File

@ -15,6 +15,11 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
l->addWidget(new QLabel(tr("Specify the generator for this project"))); l->addWidget(new QLabel(tr("Specify the generator for this project")));
this->GeneratorOptions = new QComboBox(this); this->GeneratorOptions = new QComboBox(this);
l->addWidget(this->GeneratorOptions); l->addWidget(this->GeneratorOptions);
// Add the ability to specify toolset (-T parameter)
ToolsetFrame = CreateToolsetWidgets();
l->addWidget(ToolsetFrame);
l->addSpacing(6); l->addSpacing(6);
this->CompilerSetupOptions[0] = new QRadioButton(tr("Use default native compilers"), this); this->CompilerSetupOptions[0] = new QRadioButton(tr("Use default native compilers"), this);
@ -36,17 +41,51 @@ StartCompilerSetup::StartCompilerSetup(QWidget* p)
this, SLOT(onSelectionChanged(bool))); this, SLOT(onSelectionChanged(bool)));
QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)), QObject::connect(this->CompilerSetupOptions[3], SIGNAL(toggled(bool)),
this, SLOT(onSelectionChanged(bool))); this, SLOT(onSelectionChanged(bool)));
QObject::connect(GeneratorOptions,
SIGNAL(currentIndexChanged(QString const&)),
this, SLOT(onGeneratorChanged(QString const&)));
}
QFrame* StartCompilerSetup::CreateToolsetWidgets()
{
QFrame* frame = new QFrame(this);
QVBoxLayout* l = new QVBoxLayout(frame);
l->setContentsMargins(0, 0, 0, 0);
ToolsetLabel = new QLabel(tr("Optional toolset to use (-T parameter)"));
l->addWidget(ToolsetLabel);
Toolset = new QLineEdit(frame);
l->addWidget(Toolset);
return frame;
} }
StartCompilerSetup::~StartCompilerSetup() StartCompilerSetup::~StartCompilerSetup()
{ {
} }
void StartCompilerSetup::setGenerators(const QStringList& gens) void StartCompilerSetup::setGenerators(
std::vector<cmake::GeneratorInfo> const& gens)
{ {
this->GeneratorOptions->clear(); this->GeneratorOptions->clear();
this->GeneratorOptions->addItems(gens);
}; QStringList generator_list;
std::vector<cmake::GeneratorInfo>::const_iterator it;
for (it = gens.begin(); it != gens.end(); ++it)
{
generator_list.append(QString::fromLocal8Bit(it->name.c_str()));
if (it->supportsToolset)
{
this->GeneratorsSupportingToolset.append(
QString::fromLocal8Bit(it->name.c_str()));
}
}
this->GeneratorOptions->addItems(generator_list);
}
void StartCompilerSetup::setCurrentGenerator(const QString& gen) void StartCompilerSetup::setCurrentGenerator(const QString& gen)
{ {
@ -62,6 +101,11 @@ QString StartCompilerSetup::getGenerator() const
return this->GeneratorOptions->currentText(); return this->GeneratorOptions->currentText();
}; };
QString StartCompilerSetup::getToolset() const
{
return this->Toolset->text();
};
bool StartCompilerSetup::defaultSetup() const bool StartCompilerSetup::defaultSetup() const
{ {
return this->CompilerSetupOptions[0]->isChecked(); return this->CompilerSetupOptions[0]->isChecked();
@ -88,6 +132,18 @@ void StartCompilerSetup::onSelectionChanged(bool on)
selectionChanged(); selectionChanged();
} }
void StartCompilerSetup::onGeneratorChanged(QString const& name)
{
if (GeneratorsSupportingToolset.contains(name))
{
ToolsetFrame->show();
}
else
{
ToolsetFrame->hide();
}
}
int StartCompilerSetup::nextId() const int StartCompilerSetup::nextId() const
{ {
if(compilerSetup()) if(compilerSetup())
@ -325,7 +381,8 @@ FirstConfigure::~FirstConfigure()
{ {
} }
void FirstConfigure::setGenerators(const QStringList& gens) void FirstConfigure::setGenerators(
std::vector<cmake::GeneratorInfo> const& gens)
{ {
this->mStartCompilerSetupPage->setGenerators(gens); this->mStartCompilerSetupPage->setGenerators(gens);
} }
@ -335,6 +392,11 @@ QString FirstConfigure::getGenerator() const
return this->mStartCompilerSetupPage->getGenerator(); return this->mStartCompilerSetupPage->getGenerator();
} }
QString FirstConfigure::getToolset() const
{
return this->mStartCompilerSetupPage->getToolset();
}
void FirstConfigure::loadFromSettings() void FirstConfigure::loadFromSettings()
{ {
QSettings settings; QSettings settings;

View File

@ -4,6 +4,7 @@
#include <QWizard> #include <QWizard>
#include <QWizardPage> #include <QWizardPage>
#include "cmake.h"
#include "ui_Compilers.h" #include "ui_Compilers.h"
#include "ui_CrossCompiler.h" #include "ui_CrossCompiler.h"
@ -27,9 +28,10 @@ class StartCompilerSetup : public QWizardPage
public: public:
StartCompilerSetup(QWidget* p); StartCompilerSetup(QWidget* p);
~StartCompilerSetup(); ~StartCompilerSetup();
void setGenerators(const QStringList& gens); void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
void setCurrentGenerator(const QString& gen); void setCurrentGenerator(const QString& gen);
QString getGenerator() const; QString getGenerator() const;
QString getToolset() const;
bool defaultSetup() const; bool defaultSetup() const;
bool compilerSetup() const; bool compilerSetup() const;
@ -43,10 +45,18 @@ class StartCompilerSetup : public QWizardPage
protected slots: protected slots:
void onSelectionChanged(bool); void onSelectionChanged(bool);
void onGeneratorChanged(QString const& name);
protected: protected:
QComboBox* GeneratorOptions; QComboBox* GeneratorOptions;
QRadioButton* CompilerSetupOptions[4]; QRadioButton* CompilerSetupOptions[4];
QFrame* ToolsetFrame;
QLineEdit* Toolset;
QLabel* ToolsetLabel;
QStringList GeneratorsSupportingToolset;
private:
QFrame* CreateToolsetWidgets();
}; };
//! the page that gives basic options for native compilers //! the page that gives basic options for native compilers
@ -140,8 +150,9 @@ public:
FirstConfigure(); FirstConfigure();
~FirstConfigure(); ~FirstConfigure();
void setGenerators(const QStringList& gens); void setGenerators(std::vector<cmake::GeneratorInfo> const& gens);
QString getGenerator() const; QString getGenerator() const;
QString getToolset() const;
bool defaultSetup() const; bool defaultSetup() const;
bool compilerSetup() const; bool compilerSetup() const;

View File

@ -15,7 +15,6 @@
#include <QDir> #include <QDir>
#include <QCoreApplication> #include <QCoreApplication>
#include "cmake.h"
#include "cmState.h" #include "cmState.h"
#include "cmSystemTools.h" #include "cmSystemTools.h"
#include "cmExternalMakefileProjectGenerator.h" #include "cmExternalMakefileProjectGenerator.h"
@ -46,21 +45,23 @@ QCMake::QCMake(QObject* p)
cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this); cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
std::vector<std::string> generators; std::vector<cmake::GeneratorInfo> generators;
this->CMakeInstance->GetRegisteredGenerators(generators); this->CMakeInstance->GetRegisteredGenerators(generators);
std::vector<std::string>::iterator iter;
for(iter = generators.begin(); iter != generators.end(); ++iter) std::vector<cmake::GeneratorInfo>::const_iterator it;
for(it = generators.begin(); it != generators.end(); ++it)
{ {
// Skip the generator "KDevelop3", since there is also // Skip the generator "KDevelop3", since there is also
// "KDevelop3 - Unix Makefiles", which is the full and official name. // "KDevelop3 - Unix Makefiles", which is the full and official name.
// The short name is actually only still there since this was the name // The short name is actually only still there since this was the name
// in CMake 2.4, to keep "command line argument compatibility", but // in CMake 2.4, to keep "command line argument compatibility", but
// this is not necessary in the GUI. // this is not necessary in the GUI.
if (*iter == "KDevelop3") if (it->name == "KDevelop3")
{ {
continue; continue;
} }
this->AvailableGenerators.append(QString::fromLocal8Bit(iter->c_str()));
this->AvailableGenerators.push_back(*it);
} }
} }
@ -96,6 +97,7 @@ void QCMake::setBinaryDirectory(const QString& _dir)
emit this->binaryDirChanged(this->BinaryDirectory); emit this->binaryDirChanged(this->BinaryDirectory);
cmState* state = this->CMakeInstance->GetState(); cmState* state = this->CMakeInstance->GetState();
this->setGenerator(QString()); this->setGenerator(QString());
this->setToolset(QString());
if(!this->CMakeInstance->LoadCache( if(!this->CMakeInstance->LoadCache(
this->BinaryDirectory.toLocal8Bit().data())) this->BinaryDirectory.toLocal8Bit().data()))
{ {
@ -124,6 +126,12 @@ void QCMake::setBinaryDirectory(const QString& _dir)
CreateFullGeneratorName(gen, extraGen? extraGen : ""); CreateFullGeneratorName(gen, extraGen? extraGen : "");
this->setGenerator(QString::fromLocal8Bit(curGen.c_str())); this->setGenerator(QString::fromLocal8Bit(curGen.c_str()));
} }
const char* toolset = state->GetCacheEntryValue("CMAKE_GENERATOR_TOOLSET");
if (toolset)
{
this->setToolset(QString::fromLocal8Bit(toolset));
}
} }
} }
@ -137,6 +145,15 @@ void QCMake::setGenerator(const QString& gen)
} }
} }
void QCMake::setToolset(const QString& toolset)
{
if(this->Toolset != toolset)
{
this->Toolset = toolset;
emit this->toolsetChanged(this->Toolset);
}
}
void QCMake::configure() void QCMake::configure()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -148,7 +165,7 @@ void QCMake::configure()
this->CMakeInstance->SetGlobalGenerator( this->CMakeInstance->SetGlobalGenerator(
this->CMakeInstance->CreateGlobalGenerator(this->Generator.toLocal8Bit().data())); this->CMakeInstance->CreateGlobalGenerator(this->Generator.toLocal8Bit().data()));
this->CMakeInstance->SetGeneratorPlatform(""); this->CMakeInstance->SetGeneratorPlatform("");
this->CMakeInstance->SetGeneratorToolset(""); this->CMakeInstance->SetGeneratorToolset(this->Toolset.toLocal8Bit().data());
this->CMakeInstance->LoadCache(); this->CMakeInstance->LoadCache();
this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings); this->CMakeInstance->SetSuppressDevWarnings(this->SuppressDevWarnings);
this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode); this->CMakeInstance->SetWarnUninitialized(this->WarnUninitializedMode);
@ -396,9 +413,9 @@ QString QCMake::generator() const
return this->Generator; return this->Generator;
} }
QStringList QCMake::availableGenerators() const std::vector<cmake::GeneratorInfo> const& QCMake::availableGenerators() const
{ {
return this->AvailableGenerators; return AvailableGenerators;
} }
void QCMake::deleteCache() void QCMake::deleteCache()
@ -409,6 +426,7 @@ void QCMake::deleteCache()
this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data()); this->CMakeInstance->LoadCache(this->BinaryDirectory.toLocal8Bit().data());
// emit no generator and no properties // emit no generator and no properties
this->setGenerator(QString()); this->setGenerator(QString());
this->setToolset(QString());
QCMakePropertyList props = this->properties(); QCMakePropertyList props = this->properties();
emit this->propertiesChanged(props); emit this->propertiesChanged(props);
} }

View File

@ -17,6 +17,8 @@
#pragma warning ( disable : 4512 ) #pragma warning ( disable : 4512 )
#endif #endif
#include <vector>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QVariant> #include <QVariant>
@ -25,7 +27,7 @@
#include <QMetaType> #include <QMetaType>
#include <QAtomicInt> #include <QAtomicInt>
class cmake; #include "cmake.h"
/// struct to represent cmake properties in Qt /// struct to represent cmake properties in Qt
/// Value is of type String or Bool /// Value is of type String or Bool
@ -73,6 +75,8 @@ public slots:
void setBinaryDirectory(const QString& dir); void setBinaryDirectory(const QString& dir);
/// set the desired generator to use /// set the desired generator to use
void setGenerator(const QString& generator); void setGenerator(const QString& generator);
/// set the desired generator to use
void setToolset(const QString& toolset);
/// do the configure step /// do the configure step
void configure(); void configure();
/// generate the files /// generate the files
@ -104,7 +108,7 @@ public:
/// get the current generator /// get the current generator
QString generator() const; QString generator() const;
/// get the available generators /// get the available generators
QStringList availableGenerators() const; std::vector<cmake::GeneratorInfo> const& availableGenerators() const;
/// get whether to do debug output /// get whether to do debug output
bool getDebugOutput() const; bool getDebugOutput() const;
@ -130,6 +134,8 @@ signals:
void errorMessage(const QString& msg); void errorMessage(const QString& msg);
/// signal when debug output changes /// signal when debug output changes
void debugOutputChanged(bool); void debugOutputChanged(bool);
/// signal when the toolset changes
void toolsetChanged(const QString& toolset);
protected: protected:
cmake* CMakeInstance; cmake* CMakeInstance;
@ -147,7 +153,8 @@ protected:
QString SourceDirectory; QString SourceDirectory;
QString BinaryDirectory; QString BinaryDirectory;
QString Generator; QString Generator;
QStringList AvailableGenerators; QString Toolset;
std::vector<cmake::GeneratorInfo> AvailableGenerators;
QString CMakeExecutable; QString CMakeExecutable;
QAtomicInt InterruptFlag; QAtomicInt InterruptFlag;
}; };

View File

@ -38,6 +38,9 @@ public:
/** Get the names of the current registered generators */ /** Get the names of the current registered generators */
virtual void GetGenerators(std::vector<std::string>& names) const = 0; virtual void GetGenerators(std::vector<std::string>& names) const = 0;
/** Determine whether or not this generator supports toolsets */
virtual bool SupportsToolset() const = 0;
}; };
template<class T> template<class T>
@ -57,6 +60,9 @@ public:
/** Get the names of the current registered generators */ /** Get the names of the current registered generators */
virtual void GetGenerators(std::vector<std::string>& names) const { virtual void GetGenerators(std::vector<std::string>& names) const {
names.push_back(T::GetActualName()); } names.push_back(T::GetActualName()); }
/** Determine whether or not this generator supports toolsets */
virtual bool SupportsToolset() const { return T::SupportsToolset(); }
}; };
#endif #endif

View File

@ -35,12 +35,19 @@ public:
/// @return the name of this generator. /// @return the name of this generator.
static std::string GetActualName() { return "Green Hills MULTI"; } static std::string GetActualName() { return "Green Hills MULTI"; }
///! Get the name for this generator ///! Get the name for this generator
virtual std::string GetName() const { return this->GetActualName(); } virtual std::string GetName() const { return this->GetActualName(); }
/// Overloaded methods. @see cmGlobalGenerator::GetDocumentation() /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation()
static void GetDocumentation(cmDocumentationEntry &entry); static void GetDocumentation(cmDocumentationEntry &entry);
/**
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
static bool SupportsToolset() { return false; }
/** /**
* Try to determine system information such as shared library * Try to determine system information such as shared library
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.

View File

@ -73,6 +73,12 @@ public:
*/ */
static void WriteComment(std::ostream& os, const std::string& comment); static void WriteComment(std::ostream& os, const std::string& comment);
/**
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
static bool SupportsToolset() { return false; }
/** /**
* Write a build statement to @a os with the @a comment using * Write a build statement to @a os with the @a comment using
* the @a rule the list of @a outputs files and inputs. * the @a rule the list of @a outputs files and inputs.

View File

@ -64,6 +64,12 @@ public:
return cmGlobalUnixMakefileGenerator3::GetActualName();} return cmGlobalUnixMakefileGenerator3::GetActualName();}
static std::string GetActualName() {return "Unix Makefiles";} static std::string GetActualName() {return "Unix Makefiles";}
/**
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
static bool SupportsToolset() { return false; }
/** Get the documentation entry for this generator. */ /** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry); static void GetDocumentation(cmDocumentationEntry& entry);

View File

@ -81,6 +81,8 @@ public:
names.push_back(vs10generatorName + std::string(" IA64")); names.push_back(vs10generatorName + std::string(" IA64"));
names.push_back(vs10generatorName + std::string(" Win64")); names.push_back(vs10generatorName + std::string(" Win64"));
} }
virtual bool SupportsToolset() const { return true; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -96,6 +96,8 @@ public:
names.push_back(std::string(vs11generatorName) + " " + *i); names.push_back(std::string(vs11generatorName) + " " + *i);
} }
} }
virtual bool SupportsToolset() const { return true; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -76,6 +76,8 @@ public:
names.push_back(vs12generatorName + std::string(" ARM")); names.push_back(vs12generatorName + std::string(" ARM"));
names.push_back(vs12generatorName + std::string(" Win64")); names.push_back(vs12generatorName + std::string(" Win64"));
} }
virtual bool SupportsToolset() const { return true; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -76,6 +76,8 @@ public:
names.push_back(vs14generatorName + std::string(" ARM")); names.push_back(vs14generatorName + std::string(" ARM"));
names.push_back(vs14generatorName + std::string(" Win64")); names.push_back(vs14generatorName + std::string(" Win64"));
} }
virtual bool SupportsToolset() const { return true; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -36,6 +36,12 @@ public:
/** Get the documentation entry for this generator. */ /** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry); static void GetDocumentation(cmDocumentationEntry& entry);
/**
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
static bool SupportsToolset() { return false; }
///! Create a local generator appropriate to this Global Generator ///! Create a local generator appropriate to this Global Generator
virtual cmLocalGenerator *CreateLocalGenerator(cmMakefile* mf); virtual cmLocalGenerator *CreateLocalGenerator(cmMakefile* mf);

View File

@ -52,6 +52,12 @@ public:
/** Get the documentation entry for this generator. */ /** Get the documentation entry for this generator. */
static void GetDocumentation(cmDocumentationEntry& entry); static void GetDocumentation(cmDocumentationEntry& entry);
/**
* Utilized by the generator factory to determine if this generator
* supports toolsets.
*/
static bool SupportsToolset() { return false; }
/** /**
* Try to determine system information such as shared library * Try to determine system information such as shared library
* extension, pthreads, byte order etc. * extension, pthreads, byte order etc.

View File

@ -84,6 +84,8 @@ public:
names.push_back("Visual Studio 8 2005 " + *i); names.push_back("Visual Studio 8 2005 " + *i);
} }
} }
virtual bool SupportsToolset() const { return false; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -88,6 +88,8 @@ public:
names.push_back("Visual Studio 9 2008 " + *i); names.push_back("Visual Studio 9 2008 " + *i);
} }
} }
virtual bool SupportsToolset() const { return false; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -125,6 +125,8 @@ public:
virtual void GetGenerators(std::vector<std::string>& names) const { virtual void GetGenerators(std::vector<std::string>& names) const {
names.push_back(cmGlobalXCodeGenerator::GetActualName()); } names.push_back(cmGlobalXCodeGenerator::GetActualName()); }
virtual bool SupportsToolset() const { return true; }
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -957,18 +957,32 @@ void cmake::AddDefaultExtraGenerators()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmake::GetRegisteredGenerators(std::vector<std::string>& names) void cmake::GetRegisteredGenerators(std::vector<GeneratorInfo>& generators)
{ {
for(RegisteredGeneratorsVector::const_iterator i = this->Generators.begin(); for (RegisteredGeneratorsVector::const_iterator
i != this->Generators.end(); ++i) i = this->Generators.begin(), e = this->Generators.end();
i != e; ++i)
{ {
std::vector<std::string> names;
(*i)->GetGenerators(names); (*i)->GetGenerators(names);
for (size_t j = 0; j < names.size(); ++j)
{
GeneratorInfo info;
info.supportsToolset = (*i)->SupportsToolset();
info.name = names[j];
generators.push_back(info);
}
} }
for(RegisteredExtraGeneratorsMap::const_iterator
i = this->ExtraGenerators.begin(); for (RegisteredExtraGeneratorsMap::const_iterator
i != this->ExtraGenerators.end(); ++i) i = this->ExtraGenerators.begin(), e = this->ExtraGenerators.end();
i != e; ++i)
{ {
names.push_back(i->first); GeneratorInfo info;
info.name = i->first;
info.supportsToolset = false;
generators.push_back(info);
} }
} }

View File

@ -89,6 +89,13 @@ class cmake
*/ */
FIND_PACKAGE_MODE FIND_PACKAGE_MODE
}; };
struct GeneratorInfo
{
std::string name;
bool supportsToolset;
};
typedef std::map<std::string, cmInstalledFile> InstalledFilesMap; typedef std::map<std::string, cmInstalledFile> InstalledFilesMap;
/// Default constructor /// Default constructor
@ -161,7 +168,7 @@ class cmake
void SetGlobalGenerator(cmGlobalGenerator *); void SetGlobalGenerator(cmGlobalGenerator *);
///! Get the names of the current registered generators ///! Get the names of the current registered generators
void GetRegisteredGenerators(std::vector<std::string>& names); void GetRegisteredGenerators(std::vector<GeneratorInfo>& generators);
///! Set the name of the selected generator-specific platform. ///! Set the name of the selected generator-specific platform.
void SetGeneratorPlatform(std::string const& ts) void SetGeneratorPlatform(std::string const& ts)