Commit 24a45907 authored by dt's avatar dt
Browse files

Cmake: Let the generator determine the toolchain

Otherwise we need to parse the cbp file, which happens only if the
buildconfiguration gets active. Also try to decouple a few internals a
little bit by using signals. The CMakeProject still handles a few things
directly instead of via signals, more to come eventually.
parent 1e46cb42
......@@ -110,8 +110,6 @@ QString CMakeBuildConfiguration::buildDirectory() const
QString CMakeBuildConfiguration::buildParser() const
{
// TODO this is actually slightly wrong, but do i care?
// this should call toolchain(configuration)
if (!m_toolChain)
return QString::null;
if (m_toolChain->type() == ProjectExplorer::ToolChain::GCC
......@@ -134,22 +132,21 @@ ProjectExplorer::ToolChain::ToolChainType CMakeBuildConfiguration::toolChainType
ProjectExplorer::ToolChain *CMakeBuildConfiguration::toolChain() const
{
updateToolChain();
return m_toolChain;
}
void CMakeBuildConfiguration::updateToolChain(const QString &compiler)
void CMakeBuildConfiguration::updateToolChain() const
{
//qDebug()<<"CodeBlocks Compilername"<<compiler
ProjectExplorer::ToolChain *newToolChain = 0;
if (compiler == "gcc") {
if (msvcVersion().isEmpty()) {
#ifdef Q_OS_WIN
newToolChain = ProjectExplorer::ToolChain::createMinGWToolChain("gcc", QString());
#else
newToolChain = ProjectExplorer::ToolChain::createGccToolChain("gcc");
#endif
} else if (compiler == "msvc8") {
} else { // msvc
newToolChain = ProjectExplorer::ToolChain::createMSVCToolChain(value("msvcVersion").toString(), false);
} else {
}
if (ProjectExplorer::ToolChain::equals(newToolChain, m_toolChain)) {
......@@ -161,5 +158,26 @@ void CMakeBuildConfiguration::updateToolChain(const QString &compiler)
}
}
void CMakeBuildConfiguration::setBuildDirectory(const QString &buildDirectory)
{
if (value("buildDirectory") == buildDirectory)
return;
setValue("buildDirectory", buildDirectory);
emit buildDirectoryChanged();
}
QString CMakeBuildConfiguration::msvcVersion() const
{
return value("msvcVersion").toString();
}
void CMakeBuildConfiguration::setMsvcVersion(const QString &msvcVersion)
{
if (value("msvcVersion").toString() == msvcVersion)
return;
setValue("msvcVersion", msvcVersion);
updateToolChain();
emit msvcVersionChanged();
}
......@@ -61,9 +61,18 @@ public:
ProjectExplorer::ToolChain::ToolChainType toolChainType() const;
ProjectExplorer::ToolChain *toolChain() const;
void updateToolChain(const QString &compiler);
void setBuildDirectory(const QString &buildDirectory);
QString msvcVersion() const;
void setMsvcVersion(const QString &msvcVersion);
signals:
void msvcVersionChanged();
private:
ProjectExplorer::ToolChain *m_toolChain;
void updateToolChain() const;
mutable ProjectExplorer::ToolChain *m_toolChain;
};
......
......@@ -52,13 +52,12 @@ CMakeBuildEnvironmentWidget::CMakeBuildEnvironmentWidget(CMakeProject *project)
m_buildEnvironmentWidget = new ProjectExplorer::EnvironmentWidget(this, m_clearSystemEnvironmentCheckBox);
vbox->addWidget(m_buildEnvironmentWidget);
connect(m_buildEnvironmentWidget, SIGNAL(userChangesUpdated()),
this, SLOT(environmentModelUserChangesUpdated()));
connect(m_buildEnvironmentWidget, SIGNAL(userChangesChanged()),
this, SLOT(environmentModelUserChangesChanged()));
connect(m_clearSystemEnvironmentCheckBox, SIGNAL(toggled(bool)),
this, SLOT(clearSystemEnvironmentCheckBoxClicked(bool)));
}
QString CMakeBuildEnvironmentWidget::displayName() const
{
return tr("Build Environment");
......@@ -77,7 +76,7 @@ void CMakeBuildEnvironmentWidget::init(ProjectExplorer::BuildConfiguration *bc)
m_buildEnvironmentWidget->updateButtons();
}
void CMakeBuildEnvironmentWidget::environmentModelUserChangesUpdated()
void CMakeBuildEnvironmentWidget::environmentModelUserChangesChanged()
{
m_buildConfiguration->setUserEnvironmentChanges(m_buildEnvironmentWidget->userChanges());
}
......
......@@ -55,7 +55,7 @@ public:
void init(ProjectExplorer::BuildConfiguration *bc);
private slots:
void environmentModelUserChangesUpdated();
void environmentModelUserChangesChanged();
void clearSystemEnvironmentCheckBoxClicked(bool checked);
private:
......
......@@ -213,7 +213,8 @@ InSourceBuildPage::InSourceBuildPage(CMakeOpenProjectWizard *cmakeWizard)
label->setWordWrap(true);
label->setText(tr("Qt Creator has detected an <b>in-source-build in %1</b> "
"which prevents shadow builds. Qt Creator will not allow you to change the build directory. "
"If you want a shadow build, clean your source directory and re-open the project.").arg(m_cmakeWizard->buildDirectory()));
"If you want a shadow build, clean your source directory and re-open the project.")
.arg(m_cmakeWizard->buildDirectory()));
layout()->addWidget(label);
}
......@@ -381,12 +382,16 @@ void CMakeRunPage::initializePage()
m_generatorComboBox->addItem(tr("NMake Generator (%1)").arg(msvcVersion), msvcVersion);
}
if (cachedGenerator == "NMake Makefiles" && !msvcVersions.isEmpty())
if (cachedGenerator == "NMake Makefiles" && !msvcVersions.isEmpty()) {
m_generatorComboBox->setCurrentIndex(0);
m_cmakeWizard->setMsvcVersion(msvcVersions.first());
}
m_generatorComboBox->addItem(tr("MinGW Generator"), "mingw");
if (cachedGenerator == "MinGW Makefiles")
if (cachedGenerator == "MinGW Makefiles") {
m_generatorComboBox->setCurrentIndex(m_generatorComboBox->count() - 1);
m_cmakeWizard->setMsvcVersion("");
}
} else {
// No new enough cmake, simply hide the combo box
m_generatorComboBox->setVisible(false);
......@@ -411,6 +416,8 @@ void CMakeRunPage::runCMake()
if (version != "mingw") {
generator = "-GCodeBlocks - NMake Makefiles";
m_cmakeWizard->setMsvcVersion(version);
} else {
m_cmakeWizard->setMsvcVersion("");
}
}
}
......
......@@ -104,7 +104,7 @@ BuildConfiguration *CMakeBuildConfigurationFactory::create(const QString &type)
&ok);
if (!ok || buildConfigurationName.isEmpty())
return false;
BuildConfiguration *bc = new CMakeBuildConfiguration(m_project);
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(m_project);
bc->setDisplayName(buildConfigurationName);
MakeStep *makeStep = new MakeStep(bc);
......@@ -124,8 +124,8 @@ BuildConfiguration *CMakeBuildConfigurationFactory::create(const QString &type)
}
m_project->addBuildConfiguration(bc); // this also makes the name unique
bc->setValue("buildDirectory", copw.buildDirectory());
bc->setValue("msvcVersion", copw.msvcVersion());
bc->setBuildDirectory(copw.buildDirectory());
bc->setMsvcVersion(copw.msvcVersion());
m_project->parseCMakeLists();
// Default to all
......@@ -155,7 +155,8 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName)
m_fileName(fileName),
m_buildConfigurationFactory(new CMakeBuildConfigurationFactory(this)),
m_rootNode(new CMakeProjectNode(m_fileName)),
m_insideFileChanged(false)
m_insideFileChanged(false),
m_lastActiveBuildConfiguration(0)
{
m_file = new CMakeFile(this, fileName);
}
......@@ -177,7 +178,13 @@ IBuildConfigurationFactory *CMakeProject::buildConfigurationFactory() const
void CMakeProject::slotActiveBuildConfiguration()
{
BuildConfiguration *activeBC = activeBuildConfiguration();
if (m_lastActiveBuildConfiguration)
disconnect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()),
this, SIGNAL(environmentChanged()));
CMakeBuildConfiguration *activeBC = activeCMakeBuildConfiguration();
connect(activeBC, SIGNAL(environmentChanged()),
this, SIGNAL(environmentChanged()));
// Pop up a dialog asking the user to rerun cmake
QFileInfo sourceFileInfo(m_fileName);
......@@ -202,10 +209,11 @@ void CMakeProject::slotActiveBuildConfiguration()
mode,
activeBC->environment());
copw.exec();
activeBC->setValue("msvcVersion", copw.msvcVersion());
activeBC->setMsvcVersion(copw.msvcVersion());
}
// reparse
parseCMakeLists();
emit environmentChanged();
}
void CMakeProject::fileChanged(const QString &fileName)
......@@ -218,9 +226,9 @@ void CMakeProject::fileChanged(const QString &fileName)
m_insideFileChanged = false;
}
void CMakeProject::changeBuildDirectory(BuildConfiguration *configuration, const QString &newBuildDirectory)
void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory)
{
configuration->setValue("buildDirectory", newBuildDirectory);
bc->setBuildDirectory(newBuildDirectory);
parseCMakeLists();
}
......@@ -242,16 +250,14 @@ bool CMakeProject::parseCMakeLists()
//qDebug()<<"Parsing file "<<cbpFile;
if (cbpparser.parseCbpFile(cbpFile)) {
// ToolChain
activeBC->updateToolChain(cbpparser.compilerName());
// activeBC->updateToolChain(cbpparser.compilerName());
m_projectName = cbpparser.projectName();
m_rootNode->setFolderName(cbpparser.projectName());
//qDebug()<<"Building Tree";
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
QSet<QString> projectFiles;
if (cbpparser.hasCMakeFiles()) {
fileList.append(cbpparser.cmakeFileList());
......@@ -264,7 +270,6 @@ bool CMakeProject::parseCMakeLists()
projectFiles.insert(cmakeListTxt);
}
QSet<QString> added = projectFiles;
added.subtract(m_watchedFiles);
foreach(const QString &add, added)
......@@ -280,7 +285,6 @@ bool CMakeProject::parseCMakeLists()
buildTree(m_rootNode, fileList);
//qDebug()<<"Adding Targets";
m_targets = cbpparser.targets();
// qDebug()<<"Printing targets";
......@@ -306,7 +310,8 @@ bool CMakeProject::parseCMakeLists()
allIncludePaths.append(sourceDirectory());
allIncludePaths.append(cbpparser.includeFiles());
CppTools::CppModelManagerInterface *modelmanager = ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
CppTools::CppModelManagerInterface *modelmanager =
ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
if (modelmanager) {
CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
if (pinfo.includePaths != allIncludePaths
......@@ -374,9 +379,11 @@ bool CMakeProject::parseCMakeLists()
} else {
// TODO report error
qDebug()<<"Parsing failed";
activeBC->updateToolChain(QString::null);
// activeBC->updateToolChain(QString::null);
emit targetsChanged();
return false;
}
emit targetsChanged();
return true;
}
......@@ -615,6 +622,11 @@ bool CMakeProject::restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader
if (!hasUserFile && targets().contains("all"))
makeStep->setBuildTarget("all", true);
m_lastActiveBuildConfiguration = activeCMakeBuildConfiguration();
if (m_lastActiveBuildConfiguration)
connect(m_lastActiveBuildConfiguration, SIGNAL(environmentChanged()),
this, SIGNAL(environmentChanged()));
connect(this, SIGNAL(activeBuildConfigurationChanged()),
this, SLOT(slotActiveBuildConfiguration()));
return true;
......@@ -694,10 +706,6 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeProject *project)
setLayout(fl);
m_pathLineEdit = new QLineEdit(this);
m_pathLineEdit->setReadOnly(true);
// TODO currently doesn't work
// since creating the cbp file also creates makefiles
// and then cmake builds in that directory instead of shadow building
// We need our own generator for that to work
QHBoxLayout *hbox = new QHBoxLayout();
hbox->addWidget(m_pathLineEdit);
......
......@@ -114,12 +114,19 @@ public:
QString sourceDirectory() const;
signals:
/// convenience signal emitted if the activeBuildConfiguration emits environmentChanged
/// or if the activeBuildConfiguration changes
void environmentChanged();
/// emitted after parsing
void targetsChanged();
protected:
virtual void saveSettingsImpl(ProjectExplorer::PersistentSettingsWriter &writer);
virtual bool restoreSettingsImpl(ProjectExplorer::PersistentSettingsReader &reader);
// called by CMakeBuildSettingsWidget
void changeBuildDirectory(ProjectExplorer::BuildConfiguration *configuration, const QString &newBuildDirectory);
void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
private slots:
void fileChanged(const QString &fileName);
......@@ -145,6 +152,7 @@ private:
ProjectExplorer::FileWatcher *m_watcher;
bool m_insideFileChanged;
QSet<QString> m_watchedFiles;
CMakeBuildConfiguration *m_lastActiveBuildConfiguration;
friend class CMakeBuildConfigurationFactory; // for parseCMakeLists
};
......
......@@ -56,12 +56,8 @@ CMakeRunConfiguration::CMakeRunConfiguration(CMakeProject *pro, const QString &t
{
setName(title);
connect(pro, SIGNAL(activeBuildConfigurationChanged()),
connect(pro, SIGNAL(environmentChanged()),
this, SIGNAL(baseEnvironmentChanged()));
// TODO
// connect(pro, SIGNAL(environmentChanged(ProjectExplorer::BuildConfiguration *)),
// this, SIGNAL(baseEnvironmentChanged()));
}
CMakeRunConfiguration::~CMakeRunConfiguration()
......@@ -317,8 +313,8 @@ CMakeRunConfigurationWidget::CMakeRunConfigurationWidget(CMakeRunConfiguration *
connect(resetButton, SIGNAL(clicked()),
this, SLOT(resetWorkingDirectory()));
connect(m_environmentWidget, SIGNAL(userChangesUpdated()),
this, SLOT(userChangesUpdated()));
connect(m_environmentWidget, SIGNAL(userChangesChanged()),
this, SLOT(userChangesChanged()));
connect(m_cmakeRunConfiguration, SIGNAL(workingDirectoryChanged(QString)),
this, SLOT(workingDirectoryChanged(QString)));
......@@ -351,7 +347,7 @@ void CMakeRunConfigurationWidget::resetWorkingDirectory()
m_cmakeRunConfiguration->setUserWorkingDirectory("");
}
void CMakeRunConfigurationWidget::userChangesUpdated()
void CMakeRunConfigurationWidget::userChangesChanged()
{
m_cmakeRunConfiguration->setUserEnvironmentChanges(m_environmentWidget->userChanges());
}
......
......@@ -112,7 +112,7 @@ private slots:
void setArguments(const QString &args);
void baseEnvironmentChanged();
void userEnvironmentChangesChanged();
void userChangesUpdated();
void userChangesChanged();
void setWorkingDirectory();
void resetWorkingDirectory();
private slots:
......
......@@ -217,6 +217,7 @@ MakeStepConfigWidget::MakeStepConfigWidget(MakeStep *makeStep)
connect(m_targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(settingsChanged()),
this, SLOT(updateDetails()));
}
void MakeStepConfigWidget::additionalArgumentsEdited()
......@@ -250,6 +251,24 @@ void MakeStepConfigWidget::init()
m_additionalArguments->setText(Environment::joinArgumentList(m_makeStep->additionalArguments()));
updateDetails();
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeProject();
connect(pro, SIGNAL(targetsChanged()),
this, SLOT(targetsChanged()));
}
void MakeStepConfigWidget::targetsChanged()
{
disconnect(m_targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
m_targetsList->clear();
CMakeProject *pro = m_makeStep->cmakeBuildConfiguration()->cmakeProject();
foreach(const QString& target, pro->targets()) {
QListWidgetItem *item = new QListWidgetItem(target, m_targetsList);
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(m_makeStep->buildsTarget(item->text()) ? Qt::Checked : Qt::Unchecked);
}
connect(m_targetsList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*)));
updateSummary();
}
void MakeStepConfigWidget::updateDetails()
......
......@@ -98,6 +98,7 @@ private slots:
void itemChanged(QListWidgetItem*);
void additionalArgumentsEdited();
void updateDetails();
void targetsChanged();
private:
MakeStep *m_makeStep;
QListWidget *m_targetsList;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment