Commit 9de676ce authored by Daniel Teske's avatar Daniel Teske
Browse files

CMake and Kits: Fix interaction between them



On initial run we offer the user a choice between all the kits, which
are compatible with the cached generator. After the initial run, the
user can't change kits nor generators anymore.
Except if the builds into a new directory or adds a buildconfiguration,
then the user can choose between generators but not kits.

Task-number: QTCREATORBUG-7940
Task-number: QTCREATORBUG-7928

Change-Id: I9b663435cd2e021f7fe08379c1c487a6aebe8976
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarPeter Kümmel <syntheticpp@gmx.net>
parent ffb90dff
......@@ -32,6 +32,7 @@
#include "cmakeopenprojectwizard.h"
#include "cmakeproject.h"
#include "cmakeprojectconstants.h"
#include <projectexplorer/buildsteplist.h>
#include <projectexplorer/gnumakeparser.h>
......@@ -50,12 +51,11 @@ using namespace CMakeProjectManager;
using namespace Internal;
namespace {
const char CMAKE_BC_ID[] = "CMakeProjectManager.CMakeBuildConfiguration";
const char BUILD_DIRECTORY_KEY[] = "CMakeProjectManager.CMakeBuildConfiguration.BuildDirectory";
} // namespace
CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent) :
BuildConfiguration(parent, Core::Id(CMAKE_BC_ID)), m_useNinja(false)
BuildConfiguration(parent, Core::Id(Constants::CMAKE_BC_ID)), m_useNinja(false)
{
m_buildDirectory = static_cast<CMakeProject *>(parent->project())->defaultBuildDirectory();
}
......@@ -161,12 +161,12 @@ QList<Core::Id> CMakeBuildConfigurationFactory::availableCreationIds(const Proje
{
if (!canHandle(parent))
return QList<Core::Id>();
return QList<Core::Id>() << Core::Id(CMAKE_BC_ID);
return QList<Core::Id>() << Core::Id(Constants::CMAKE_BC_ID);
}
QString CMakeBuildConfigurationFactory::displayNameForId(const Core::Id id) const
{
if (id == CMAKE_BC_ID)
if (id == Constants::CMAKE_BC_ID)
return tr("Build");
return QString();
}
......@@ -175,7 +175,7 @@ bool CMakeBuildConfigurationFactory::canCreate(const ProjectExplorer::Target *pa
{
if (!canHandle(parent))
return false;
if (id == CMAKE_BC_ID)
if (id == Constants::CMAKE_BC_ID)
return true;
return false;
}
......@@ -199,6 +199,17 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer:
if (!ok || buildConfigurationName.isEmpty())
return 0;
CMakeOpenProjectWizard::BuildInfo info;
info.sourceDirectory = project->projectDirectory();
info.environment = Utils::Environment::systemEnvironment();
info.buildDirectory = project->defaultBuildDirectory();
info.kit = parent->kit();
info.useNinja = false; // This is ignored anyway
CMakeOpenProjectWizard copw(project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory, info);
if (copw.exec() != QDialog::Accepted)
return 0;
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(parent);
bc->setDisplayName(buildConfigurationName);
......@@ -213,16 +224,8 @@ CMakeBuildConfiguration *CMakeBuildConfigurationFactory::create(ProjectExplorer:
cleanMakeStep->setAdditionalArguments("clean");
cleanMakeStep->setClean(true);
CMakeOpenProjectWizard copw(project->projectManager(),
project->projectDirectory(),
bc->buildDirectory(),
bc);
if (copw.exec() != QDialog::Accepted) {
delete bc;
return 0;
}
bc->setBuildDirectory(copw.buildDirectory());
bc->setUseNinja(copw.useNinja());
// Default to all
if (project->hasBuildTarget("all"))
......
......@@ -31,9 +31,13 @@
#ifndef CMAKEOPENPROJECTWIZARD_H
#define CMAKEOPENPROJECTWIZARD_H
#include "cmakebuildconfiguration.h"
#include <utils/environment.h>
#include <utils/wizard.h>
#include <utils/qtcprocess.h>
#include <projectexplorer/target.h>
#include <projectexplorer/project.h>
#include <QPushButton>
#include <QComboBox>
......@@ -47,14 +51,13 @@ class PathChooser;
}
namespace ProjectExplorer {
class ToolChain;
class Kit;
}
namespace CMakeProjectManager {
namespace Internal {
class CMakeManager;
class CMakeBuildConfiguration;
class CMakeOpenProjectWizard : public Utils::Wizard
{
......@@ -70,28 +73,52 @@ public:
Nothing,
NeedToCreate,
NeedToUpdate,
WantToUpdate
WantToUpdate,
ChangeDirectory
};
class BuildInfo
{
public:
BuildInfo()
{}
BuildInfo(CMakeBuildConfiguration *bc)
: sourceDirectory(bc->target()->project()->projectDirectory())
, buildDirectory(bc->buildDirectory())
, environment(bc->environment())
, useNinja(bc->useNinja())
, kit(bc->target()->kit())
{}
QString sourceDirectory;
QString buildDirectory;
Utils::Environment environment;
bool useNinja;
ProjectExplorer::Kit *kit;
};
// used at importing a project without a .user file
CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, CMakeBuildConfiguration *bc);
/// used at importing a project without a .user file
CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, Utils::Environment env);
/// used to update if we have already a .user file
/// recreates or updates the cbp file
CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, const QString &buildDirectory, Mode mode, CMakeBuildConfiguration *bc);
/// used to change the build directory of one buildconfiguration
/// shows a page for selecting a directory
/// then the run cmake page
CMakeOpenProjectWizard(CMakeManager *cmakeManager, const QString &sourceDirectory, const QString &oldBuildDirectory, CMakeBuildConfiguration *bc);
/// Also used to change the build directory of one buildconfiguration or create a new buildconfiguration
CMakeOpenProjectWizard(CMakeManager *cmakeManager, Mode mode, const BuildInfo &info);
virtual int nextId() const;
QString buildDirectory() const;
QString sourceDirectory() const;
void setBuildDirectory(const QString &directory);
bool useNinja() const;
void setUseNinja(bool b);
CMakeManager *cmakeManager() const;
QString arguments() const;
void setArguments(const QString &args);
Utils::Environment environment() const;
CMakeBuildConfiguration *buildConfiguration() const;
ProjectExplorer::Kit *kit() const;
void setKit(ProjectExplorer::Kit *kit);
bool existsUpToDateXmlFile() const;
private:
......@@ -102,7 +129,9 @@ private:
QString m_sourceDirectory;
QString m_arguments;
bool m_creatingCbpFiles;
CMakeBuildConfiguration *m_buildConfiguration;
Utils::Environment m_environment;
bool m_useNinja;
ProjectExplorer::Kit *m_kit;
};
class InSourceBuildPage : public QWizardPage
......@@ -134,6 +163,7 @@ public:
explicit CMakeRunPage(CMakeOpenProjectWizard *cmakeWizard, Mode mode = Initial, const QString &buildDirectory = QString());
virtual void initializePage();
virtual bool validatePage();
virtual void cleanupPage();
virtual bool isComplete() const;
private slots:
......@@ -143,6 +173,7 @@ private slots:
void cmakeReadyReadStandardError();
private:
void initWidgets();
QString cachedGeneratorFromFile(const QString &cache);
CMakeOpenProjectWizard *m_cmakeWizard;
QPlainTextEdit *m_output;
QPushButton *m_runCMake;
......@@ -153,6 +184,7 @@ private:
QLabel *m_descriptionLabel;
QLabel *m_exitCodeLabel;
bool m_complete;
bool m_optionalCMake;
Mode m_mode;
QString m_buildDirectory;
};
......
......@@ -49,6 +49,7 @@
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/toolchain.h>
#include <projectexplorer/target.h>
#include <projectexplorer/deployconfiguration.h>
#include <qtsupport/customexecutablerunconfiguration.h>
#include <cpptools/ModelManagerInterface.h>
#include <extensionsystem/pluginmanager.h>
......@@ -145,8 +146,6 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur
CMakeBuildConfiguration *cmakebc = static_cast<CMakeBuildConfiguration *>(bc);
// Pop up a dialog asking the user to rerun cmake
QFileInfo sourceFileInfo(m_fileName);
QString cbpFile = CMakeManager::findCbpFile(QDir(bc->buildDirectory()));
QFileInfo cbpFileFi(cbpFile);
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
......@@ -162,13 +161,12 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur
}
if (mode != CMakeOpenProjectWizard::Nothing) {
CMakeOpenProjectWizard copw(m_manager,
sourceFileInfo.absolutePath(),
cmakebc->buildDirectory(),
mode,
cmakebc);
copw.exec();
CMakeOpenProjectWizard copw(m_manager, mode,
CMakeOpenProjectWizard::BuildInfo(cmakebc));
if (copw.exec() == QDialog::Accepted)
cmakebc->setUseNinja(copw.useNinja()); // NeedToCreate can change the Ninja setting
}
// reparse
parseCMakeLists();
}
......@@ -190,7 +188,7 @@ void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QStri
QString CMakeProject::defaultBuildDirectory() const
{
return projectDirectory() + QLatin1String("/qtcreator-build");
return projectDirectory() + QLatin1String("-build");
}
bool CMakeProject::parseCMakeLists()
......@@ -531,33 +529,59 @@ bool CMakeProject::fromMap(const QVariantMap &map)
if (!Project::fromMap(map))
return false;
Kit *defaultKit = KitManager::instance()->defaultKit();
if (!activeTarget() && defaultKit)
addTarget(createTarget(defaultKit));
// We have a user file, but we could still be missing the cbp file
// or simply run createXml with the saved settings
QFileInfo sourceFileInfo(m_fileName);
CMakeBuildConfiguration *activeBC = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
if (!activeBC)
return false;
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory()));
QFileInfo cbpFileFi(cbpFile);
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
if (!cbpFileFi.exists())
mode = CMakeOpenProjectWizard::NeedToCreate;
else if (cbpFileFi.lastModified() < sourceFileInfo.lastModified())
mode = CMakeOpenProjectWizard::NeedToUpdate;
if (mode != CMakeOpenProjectWizard::Nothing) {
CMakeOpenProjectWizard copw(m_manager,
sourceFileInfo.absolutePath(),
activeBC->buildDirectory(),
mode,
activeBC);
bool hasUserFile = activeTarget();
if (!hasUserFile) {
CMakeOpenProjectWizard copw(m_manager, projectDirectory(), Utils::Environment::systemEnvironment());
if (copw.exec() != QDialog::Accepted)
return false;
Kit *k = copw.kit();
Target *t = new Target(this, k);
CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t));
bc->setDefaultDisplayName("all");
bc->setUseNinja(copw.useNinja());
bc->setBuildDirectory(copw.buildDirectory());
ProjectExplorer::BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
ProjectExplorer::BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
// Now create a standard build configuration
buildSteps->insertStep(0, new MakeStep(buildSteps));
MakeStep *cleanMakeStep = new MakeStep(cleanSteps);
cleanSteps->insertStep(0, cleanMakeStep);
cleanMakeStep->setAdditionalArguments("clean");
cleanMakeStep->setClean(true);
t->addBuildConfiguration(bc);
DeployConfigurationFactory *fac = ExtensionSystem::PluginManager::instance()->getObject<DeployConfigurationFactory>();
ProjectExplorer::DeployConfiguration *dc = fac->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID);
t->addDeployConfiguration(dc);
addTarget(t);
} else {
// We have a user file, but we could still be missing the cbp file
// or simply run createXml with the saved settings
QFileInfo sourceFileInfo(m_fileName);
CMakeBuildConfiguration *activeBC = qobject_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
if (!activeBC)
return false;
QString cbpFile = CMakeManager::findCbpFile(QDir(activeBC->buildDirectory()));
QFileInfo cbpFileFi(cbpFile);
CMakeOpenProjectWizard::Mode mode = CMakeOpenProjectWizard::Nothing;
if (!cbpFileFi.exists())
mode = CMakeOpenProjectWizard::NeedToCreate;
else if (cbpFileFi.lastModified() < sourceFileInfo.lastModified())
mode = CMakeOpenProjectWizard::NeedToUpdate;
if (mode != CMakeOpenProjectWizard::Nothing) {
CMakeOpenProjectWizard copw(m_manager, mode,
CMakeOpenProjectWizard::BuildInfo(activeBC));
if (copw.exec() != QDialog::Accepted)
return false;
else
activeBC->setUseNinja(copw.useNinja());
}
}
m_watcher = new QFileSystemWatcher(this);
......@@ -565,17 +589,13 @@ bool CMakeProject::fromMap(const QVariantMap &map)
parseCMakeLists();
if (hasBuildTarget("all")) {
if (!hasUserFile && hasBuildTarget("all")) {
MakeStep *makeStep = qobject_cast<MakeStep *>(
activeTarget()->activeBuildConfiguration()->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD)->at(0));
Q_ASSERT(makeStep);
makeStep->setBuildTarget("all", true);
}
foreach (Target *t, targets())
connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
connect(Core::EditorManager::instance(), SIGNAL(editorAboutToClose(Core::IEditor*)),
this, SLOT(editorAboutToClose(Core::IEditor*)));
......@@ -588,6 +608,22 @@ bool CMakeProject::fromMap(const QVariantMap &map)
return true;
}
bool CMakeProject::setupTarget(Target *t)
{
CMakeBuildConfigurationFactory *factory
= ExtensionSystem::PluginManager::instance()->getObject<CMakeBuildConfigurationFactory>();
CMakeBuildConfiguration *bc = factory->create(t, Constants::CMAKE_BC_ID, QLatin1String("all"));
if (!bc)
return false;
t->addBuildConfiguration(bc);
DeployConfigurationFactory *fac = ExtensionSystem::PluginManager::instance()->getObject<DeployConfigurationFactory>();
ProjectExplorer::DeployConfiguration *dc = fac->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID);
t->addDeployConfiguration(dc);
return true;
}
CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
{
foreach (const CMakeBuildTarget &ct, m_buildTargets)
......@@ -903,25 +939,21 @@ void CMakeBuildSettingsWidget::init(BuildConfiguration *bc)
void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog()
{
CMakeProject *project = static_cast<CMakeProject *>(m_buildConfiguration->target()->project());
CMakeOpenProjectWizard copw(project->projectManager(),
project->projectDirectory(),
m_buildConfiguration->buildDirectory(),
m_buildConfiguration);
CMakeOpenProjectWizard copw(project->projectManager(), CMakeOpenProjectWizard::ChangeDirectory,
CMakeOpenProjectWizard::BuildInfo(m_buildConfiguration));
if (copw.exec() == QDialog::Accepted) {
project->changeBuildDirectory(m_buildConfiguration, copw.buildDirectory());
m_buildConfiguration->setUseNinja(copw.useNinja());
m_pathLineEdit->setText(m_buildConfiguration->buildDirectory());
}
}
void CMakeBuildSettingsWidget::runCMake()
{
// TODO skip build directory
CMakeProject *project = static_cast<CMakeProject *>(m_buildConfiguration->target()->project());
CMakeOpenProjectWizard copw(project->projectManager(),
project->projectDirectory(),
m_buildConfiguration->buildDirectory(),
CMakeOpenProjectWizard::WantToUpdate,
m_buildConfiguration);
CMakeOpenProjectWizard::BuildInfo(m_buildConfiguration));
if (copw.exec() == QDialog::Accepted)
project->parseCMakeLists();
}
......
......@@ -110,6 +110,7 @@ signals:
protected:
bool fromMap(const QVariantMap &map);
bool setupTarget(ProjectExplorer::Target *t);
// called by CMakeBuildSettingsWidget
void changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory);
......
......@@ -45,6 +45,9 @@ const char RUNCMAKECONTEXTMENU[] = "CMakeProject.RunCMakeContextMenu";
// Project
const char CMAKEPROJECT_ID[] = "CMakeProjectManager.CMakeProject";
// Buildconfiguration
const char CMAKE_BC_ID[] = "CMakeProjectManager.CMakeBuildConfiguration";
// Menu
const char M_CONTEXT[] = "CMakeEditor.ContextMenu";
......
......@@ -119,11 +119,8 @@ void CMakeManager::runCMake(ProjectExplorer::Project *project)
CMakeBuildConfiguration *bc
= static_cast<CMakeBuildConfiguration *>(cmakeProject->activeTarget()->activeBuildConfiguration());
CMakeOpenProjectWizard copw(this,
cmakeProject->projectDirectory(),
bc->buildDirectory(),
CMakeOpenProjectWizard::WantToUpdate,
bc);
CMakeOpenProjectWizard copw(this, CMakeOpenProjectWizard::WantToUpdate,
CMakeOpenProjectWizard::BuildInfo(bc));
if (copw.exec() == QDialog::Accepted)
cmakeProject->parseCMakeLists();
}
......
......@@ -93,20 +93,21 @@ MakeStep::MakeStep(BuildStepList *bsl, MakeStep *bs) :
void MakeStep::ctor()
{
m_percentProgress = QRegExp("^\\[\\s*(\\d*)%\\]");
m_useNinja = false;
m_ninjaProgress = QRegExp ("^\\[\\s*(\\d*)/\\s*(\\d*)");
m_ninjaProgressString = QLatin1String("[%s/%t "); // ninja: [33/100
//: Default display name for the cmake make step.
setDefaultDisplayName(tr("Make"));
BuildConfiguration *bc = cmakeBuildConfiguration();
CMakeBuildConfiguration *bc = cmakeBuildConfiguration();
if (bc) {
m_useNinja = bc->useNinja();
m_activeConfiguration = 0;
connect(bc, SIGNAL(useNinjaChanged(bool)), this, SLOT(setUseNinja(bool)));
} else {
// That means the step is in the deploylist, so we listen to the active build config
// changed signal and react to the activeBuildConfigurationChanged() signal of the buildconfiguration
m_activeConfiguration = targetsActiveBuildConfiguration();
m_useNinja = m_activeConfiguration->useNinja();
connect (target(), SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
this, SLOT(activeBuildConfigurationChanged()));
activeBuildConfigurationChanged();
......
......@@ -250,11 +250,21 @@ Target *Project::createTarget(Kit *k)
return 0;
Target *t = new Target(this, k);
t->createDefaultSetup();
if (!setupTarget(t)) {
delete t;
return 0;
}
return t;
}
bool Project::setupTarget(Target *t)
{
t->updateDefaultBuildConfigurations();
t->updateDefaultDeployConfigurations();
t->updateDefaultRunConfigurations();
return true;
}
Target *Project::restoreTarget(const QVariantMap &data)
{
Core::Id id = idFromMap(data);
......
......@@ -147,6 +147,7 @@ signals:
protected:
virtual bool fromMap(const QVariantMap &map);
virtual bool setupTarget(Target *t);
virtual void setProjectContext(Core::Context context);
virtual void setProjectLanguage(Core::Context language);
......
......@@ -515,13 +515,6 @@ QVariantMap Target::toMap() const
return map;
}
void Target::createDefaultSetup()
{
updateDefaultBuildConfigurations();
updateDefaultDeployConfigurations();
updateDefaultRunConfigurations();
}
void Target::updateDefaultBuildConfigurations()
{
IBuildConfigurationFactory *bcFactory = IBuildConfigurationFactory::find(this);
......
......@@ -113,7 +113,6 @@ public:
QVariantMap toMap() const;
void createDefaultSetup();
void updateDefaultBuildConfigurations();
void updateDefaultDeployConfigurations();
void updateDefaultRunConfigurations();
......
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