CMake: Rewrite logic for kit selection

Some time ago the all the wizards for the Plain C++ were coalesced into one wizard.

Since then the wizard asks first for the targets via a targetsetuppage and then
in the CMakeOpenProjectWizard asked for the kit again.

This patch clean thats up, by always using the TargetSetupPage for kit
selection and removing code from the CMakeOpenProjectWizard for kit selection.

It also adds more types of buildconfigurations

Offer: Debug, Release, ReleaseWithDebugInfo, MinSizeRelease with the
corresponding -DCMAKE_BUILD_TYPE parameters. That argument is saved
in the build configuration and used once for the first cmake run. (Subsequent
runs of cmake don't require passing that to cmake again.)

Also do not require running cmake on creating the buildconfiguraiton, instead
postpone that until the buildconfiguration is made active. With the current
cmake wizard, selecting multiple kits would show a dialog per buildconfiguration.

Change-Id: I3bb806113f4f529f8e291830647d2515a6c4df8a
Task-number: QTCREATORBUG-12219
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Daniel Teske
2015-09-10 16:17:38 +02:00
parent 798fa669bf
commit 014a7b332b
10 changed files with 189 additions and 179 deletions

View File

@@ -59,6 +59,7 @@ namespace CMakeProjectManager {
namespace Internal {
const char USE_NINJA_KEY[] = "CMakeProjectManager.CMakeBuildConfiguration.UseNinja";
const char INITIAL_ARGUMENTS[] = "CMakeProjectManager.CMakeBuildConfiguration.InitialArgument";
static FileName shadowBuildDirectory(const FileName &projectFilePath, const Kit *k, const QString &bcName)
{
@@ -85,7 +86,8 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(ProjectExplorer::Target *parent
CMakeBuildConfiguration *source) :
BuildConfiguration(parent, source),
m_msvcVersion(source->m_msvcVersion),
m_useNinja(source->m_useNinja)
m_useNinja(source->m_useNinja),
m_initialArguments(source->m_initialArguments)
{
Q_ASSERT(parent);
cloneSteps(source);
@@ -95,6 +97,7 @@ QVariantMap CMakeBuildConfiguration::toMap() const
{
QVariantMap map(ProjectExplorer::BuildConfiguration::toMap());
map.insert(QLatin1String(USE_NINJA_KEY), m_useNinja);
map.insert(QLatin1String(INITIAL_ARGUMENTS), m_initialArguments);
return map;
}
@@ -104,6 +107,7 @@ bool CMakeBuildConfiguration::fromMap(const QVariantMap &map)
return false;
m_useNinja = map.value(QLatin1String(USE_NINJA_KEY), false).toBool();
m_initialArguments = map.value(QLatin1String(INITIAL_ARGUMENTS)).toString();
return true;
}
@@ -126,6 +130,16 @@ void CMakeBuildConfiguration::emitBuildTypeChanged()
emit buildTypeChanged();
}
void CMakeBuildConfiguration::setInitialArguments(const QString &arguments)
{
m_initialArguments = arguments;
}
QString CMakeBuildConfiguration::initialArguments() const
{
return m_initialArguments;
}
CMakeBuildConfiguration::~CMakeBuildConfiguration()
{ }
@@ -156,9 +170,12 @@ QList<ProjectExplorer::BuildInfo *> CMakeBuildConfigurationFactory::availableBui
{
QList<ProjectExplorer::BuildInfo *> result;
CMakeBuildInfo *info = createBuildInfo(parent->kit(),
parent->project()->projectDirectory().toString());
result << info;
for (int type = BuildTypeNone; type != BuildTypeLast; ++type) {
CMakeBuildInfo *info = createBuildInfo(parent->kit(),
parent->project()->projectDirectory().toString(),
BuildType(type));
result << info;
}
return result;
}
@@ -175,11 +192,19 @@ QList<ProjectExplorer::BuildInfo *> CMakeBuildConfigurationFactory::availableSet
{
QList<ProjectExplorer::BuildInfo *> result;
const FileName projectPathName = FileName::fromString(projectPath);
CMakeBuildInfo *info = createBuildInfo(k, ProjectExplorer::Project::projectDirectory(projectPathName).toString());
//: The name of the build configuration created by default for a cmake project.
info->displayName = tr("Default");
info->buildDirectory = shadowBuildDirectory(projectPathName, k, info->displayName);
result << info;
for (int type = BuildTypeNone; type != BuildTypeLast; ++type) {
CMakeBuildInfo *info = createBuildInfo(k,
ProjectExplorer::Project::projectDirectory(projectPathName).toString(),
BuildType(type));
if (type == BuildTypeNone) {
//: The name of the build configuration created by default for a cmake project.
info->displayName = tr("Default");
} else {
info->displayName = info->typeName;
}
info->buildDirectory = shadowBuildDirectory(projectPathName, k, info->displayName);
result << info;
}
return result;
}
@@ -192,17 +217,12 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(Proj
CMakeBuildInfo copy(*static_cast<const CMakeBuildInfo *>(info));
CMakeProject *project = static_cast<CMakeProject *>(parent->project());
CMakeManager *manager = static_cast<CMakeManager *>(project->projectManager());
if (copy.buildDirectory.isEmpty()) {
copy.buildDirectory = shadowBuildDirectory(project->projectFilePath(), parent->kit(),
copy.displayName);
}
CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), manager, CMakeOpenProjectWizard::ChangeDirectory, &copy);
if (copw.exec() != QDialog::Accepted)
return 0;
CMakeBuildConfiguration *bc = new CMakeBuildConfiguration(parent);
bc->setDisplayName(copy.displayName);
bc->setDefaultDisplayName(copy.displayName);
@@ -218,8 +238,8 @@ ProjectExplorer::BuildConfiguration *CMakeBuildConfigurationFactory::create(Proj
cleanMakeStep->setAdditionalArguments(QLatin1String("clean"));
cleanMakeStep->setClean(true);
bc->setBuildDirectory(FileName::fromString(copw.buildDirectory()));
bc->setUseNinja(copw.useNinja());
bc->setBuildDirectory(copy.buildDirectory);
bc->setInitialArguments(copy.arguments);
// Default to all
if (project->hasBuildTarget(QLatin1String("all")))
@@ -270,15 +290,39 @@ bool CMakeBuildConfigurationFactory::canHandle(const ProjectExplorer::Target *t)
}
CMakeBuildInfo *CMakeBuildConfigurationFactory::createBuildInfo(const ProjectExplorer::Kit *k,
const QString &sourceDir) const
const QString &sourceDir,
BuildType buildType) const
{
CMakeBuildInfo *info = new CMakeBuildInfo(this);
info->typeName = tr("Build");
info->kitId = k->id();
info->environment = Environment::systemEnvironment();
k->addToEnvironment(info->environment);
info->useNinja = false;
info->sourceDirectory = sourceDir;
switch (buildType) {
case BuildTypeNone:
info->typeName = tr("Build");
break;
case BuildTypeDebug:
info->arguments = QLatin1String("-DCMAKE_BUILD_TYPE=Debug");
info->typeName = tr("Debug");
break;
case BuildTypeRelease:
info->arguments = QLatin1String("-DCMAKE_BUILD_TYPE=Release");
info->typeName = tr("Release");
break;
case BuildTypeMinSizeRel:
info->arguments = QLatin1String("-DCMAKE_BUILD_TYPE=MinSizeRel");
info->typeName = tr("Minimum Size Release");
break;
case BuildTypeRelWithDebInfo:
info->arguments = QLatin1String("-DCMAKE_BUILD_TYPE=RelWithDebInfo");
info->typeName = tr("Release with Debug Information");
break;
default:
QTC_CHECK(false);
break;
}
return info;
}