From 014a7b332b1761a4fb8d05f034dd897c40145b31 Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Thu, 10 Sep 2015 16:17:38 +0200 Subject: [PATCH] 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 --- .../cmakebuildconfiguration.cpp | 80 ++++++-- .../cmakebuildconfiguration.h | 16 +- .../cmakeprojectmanager/cmakebuildinfo.h | 2 + .../cmakebuildsettingswidget.cpp | 8 +- .../cmakelocatorfilter.cpp | 6 + .../cmakeopenprojectwizard.cpp | 174 ++++++------------ .../cmakeopenprojectwizard.h | 19 +- .../cmakeprojectmanager/cmakeproject.cpp | 56 +++--- .../cmakeprojectmanager/cmakeproject.h | 4 + .../cmakeprojectmanager.cpp | 3 +- 10 files changed, 189 insertions(+), 179 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 36a9c9eb065..b8cd3a10b31 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -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 CMakeBuildConfigurationFactory::availableBui { QList 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 CMakeBuildConfigurationFactory::availableSet { QList 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(info)); CMakeProject *project = static_cast(parent->project()); - CMakeManager *manager = static_cast(project->projectManager()); if (copy.buildDirectory.isEmpty()) { copy.buildDirectory = shadowBuildDirectory(project->projectFilePath(), parent->kit(), copy.displayName); } - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), manager, CMakeOpenProjectWizard::ChangeDirectory, ©); - 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; } diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h index cfe3f3968a5..d928320727d 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h @@ -64,6 +64,9 @@ public: void emitBuildTypeChanged(); + void setInitialArguments(const QString &arguments); + QString initialArguments() const; + signals: void useNinjaChanged(bool); @@ -74,6 +77,7 @@ protected: private: QString m_msvcVersion; bool m_useNinja; + QString m_initialArguments; friend class CMakeProjectManager::CMakeProject; }; @@ -101,7 +105,17 @@ public: private: bool canHandle(const ProjectExplorer::Target *t) const; - CMakeBuildInfo *createBuildInfo(const ProjectExplorer::Kit *k, const QString &sourceDir) const; + + enum BuildType { BuildTypeNone = 0, + BuildTypeDebug = 1, + BuildTypeRelease = 2, + BuildTypeRelWithDebInfo = 3, + BuildTypeMinSizeRel = 4, + BuildTypeLast = 5 }; + + CMakeBuildInfo *createBuildInfo(const ProjectExplorer::Kit *k, + const QString &sourceDir, + BuildType buildType) const; }; } // namespace Internal diff --git a/src/plugins/cmakeprojectmanager/cmakebuildinfo.h b/src/plugins/cmakeprojectmanager/cmakebuildinfo.h index c7c476d1be9..92881941342 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildinfo.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildinfo.h @@ -59,10 +59,12 @@ public: QTC_ASSERT(bc->target()->project(), return); sourceDirectory = bc->target()->project()->projectDirectory().toString(); + arguments = bc->initialArguments(); } Utils::Environment environment; QString sourceDirectory; + QString arguments; bool useNinja; }; diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp index 596d12773ca..116439647f5 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp @@ -86,7 +86,9 @@ void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog() CMakeBuildInfo info(m_buildConfiguration); CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), manager, CMakeOpenProjectWizard::ChangeDirectory, - &info); + &info, + project->activeTarget()->displayName(), + project->activeTarget()->activeBuildConfiguration()->displayName()); if (copw.exec() == QDialog::Accepted) { project->changeBuildDirectory(m_buildConfiguration, copw.buildDirectory()); m_buildConfiguration->setUseNinja(copw.useNinja()); @@ -103,7 +105,9 @@ void CMakeBuildSettingsWidget::runCMake() CMakeBuildInfo info(m_buildConfiguration); CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), manager, - CMakeOpenProjectWizard::WantToUpdate, &info); + CMakeOpenProjectWizard::WantToUpdate, &info, + project->activeTarget()->displayName(), + project->activeTarget()->activeBuildConfiguration()->displayName()); if (copw.exec() == QDialog::Accepted) project->parseCMakeLists(); } diff --git a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp index a5d909b6832..d340b3ed2af 100644 --- a/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakelocatorfilter.cpp @@ -104,6 +104,12 @@ void CMakeLocatorFilter::accept(Core::LocatorFilterEntry selection) const if (!cmakeProject) return; + if (!cmakeProject->activeTarget()) + return; + + if (!cmakeProject->activeTarget()->activeBuildConfiguration()) + return; + // Find the make step MakeStep *makeStep = 0; ProjectExplorer::BuildStepList *buildStepList = cmakeProject->activeTarget()->activeBuildConfiguration() diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp index 63998bd9af0..507fa1363e4 100644 --- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp @@ -80,36 +80,11 @@ using namespace CMakeProjectManager::Internal; ////////////// /// CMakeOpenProjectWizard ////////////// - -CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, const QString &sourceDirectory, Utils::Environment env) - : Utils::Wizard(parent), - m_cmakeManager(cmakeManager), - m_sourceDirectory(sourceDirectory), - m_environment(env), - m_useNinja(false), - m_kit(0) -{ - if (CMakeToolManager::cmakeTools().isEmpty()) - addPage(new NoCMakePage(this)); - - if (!compatibleKitExist()) - addPage(new NoKitPage(this)); - - if (hasInSourceBuild()) { - m_buildDirectory = m_sourceDirectory; - addPage(new InSourceBuildPage(this)); - } else { - m_buildDirectory = m_sourceDirectory + QLatin1String("-build"); - addPage(new ShadowBuildPage(this)); - } - - addPage(new CMakeRunPage(this)); - - init(); -} - -CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, CMakeOpenProjectWizard::Mode mode, - const CMakeBuildInfo *info) +CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, + CMakeOpenProjectWizard::Mode mode, + const CMakeBuildInfo *info, + const QString &kitName, + const QString &buildConfigurationName) : Utils::Wizard(parent), m_cmakeManager(cmakeManager), m_sourceDirectory(info->sourceDirectory), @@ -137,7 +112,8 @@ CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cm if (CMakeToolManager::cmakeTools().isEmpty()) addPage(new NoCMakePage(this)); - addPage(new CMakeRunPage(this, rmode, info->buildDirectory.toString())); + addPage(new CMakeRunPage(this, rmode, info->buildDirectory.toString(), info->arguments, + kitName, buildConfigurationName)); init(); } @@ -409,14 +385,19 @@ void NoCMakePage::showOptions() Core::ICore::showOptionsDialog(Constants::CMAKE_SETTINGSPAGE_ID, this); } -CMakeRunPage::CMakeRunPage(CMakeOpenProjectWizard *cmakeWizard, Mode mode, const QString &buildDirectory) +CMakeRunPage::CMakeRunPage(CMakeOpenProjectWizard *cmakeWizard, Mode mode, + const QString &buildDirectory, const QString &initialArguments, + const QString &kitName, const QString &buildConfigurationName) : QWizardPage(cmakeWizard), m_cmakeWizard(cmakeWizard), m_haveCbpFile(false), m_mode(mode), - m_buildDirectory(buildDirectory) + m_buildDirectory(buildDirectory), + m_kitName(kitName), + m_buildConfigurationName(buildConfigurationName) { initWidgets(); + m_argumentsLineEdit->setText(initialArguments); } void CMakeRunPage::initWidgets() @@ -507,41 +488,37 @@ QByteArray CMakeRunPage::cachedGeneratorFromFile(const QString &cache) void CMakeRunPage::initializePage() { - if (m_mode == Initial) { - bool upToDateXmlFile = m_cmakeWizard->existsUpToDateXmlFile(); - m_buildDirectory = m_cmakeWizard->buildDirectory(); - - if (upToDateXmlFile) { - m_descriptionLabel->setText( - tr("The directory %1 already contains a cbp file, which is recent enough. " - "You can pass special arguments and rerun CMake. " - "Or simply finish the wizard directly.").arg(m_buildDirectory)); - m_haveCbpFile = true; - } else { - m_descriptionLabel->setText( - tr("The directory %1 does not contain a cbp file. Qt Creator needs to create this file by running CMake. " - "Some projects require command line arguments to the initial CMake call.").arg(m_buildDirectory)); - } - } else if (m_mode == CMakeRunPage::NeedToUpdate) { - m_descriptionLabel->setText(tr("The directory %1 contains an outdated .cbp file. Qt " + if (m_mode == CMakeRunPage::NeedToUpdate) { + m_descriptionLabel->setText(tr("The build directory \"%1\" for the buildconfiguration \"%2\" " + "for target \"%3\" contains an outdated .cbp file. Qt " "Creator needs to update this file by running CMake. " "If you want to add additional command line arguments, " "add them below. Note that CMake remembers command " - "line arguments from the previous runs.").arg(m_buildDirectory)); + "line arguments from the previous runs.") + .arg(m_buildDirectory) + .arg(m_buildConfigurationName) + .arg(m_kitName)); } else if (m_mode == CMakeRunPage::Recreate) { - m_descriptionLabel->setText(tr("The directory %1 specified in a build-configuration, " - "does not contain a cbp file. Qt Creator needs to " - "recreate this file, by running CMake. " + m_descriptionLabel->setText(tr("The directory \"%1\" specified in the build-configuration \"%2\", " + "for target \"%3\" does not contain a cbp file. " + "Qt Creator needs to recreate this file, by running CMake. " "Some projects require command line arguments to " "the initial CMake call. Note that CMake remembers command " - "line arguments from the previous runs.").arg(m_buildDirectory)); + "line arguments from the previous runs.") + .arg(m_buildDirectory) + .arg(m_buildConfigurationName) + .arg(m_kitName)); } else if (m_mode == CMakeRunPage::ChangeDirectory) { m_buildDirectory = m_cmakeWizard->buildDirectory(); m_descriptionLabel->setText(tr("Qt Creator needs to run CMake in the new build directory. " "Some projects require command line arguments to the " "initial CMake call.")); } else if (m_mode == CMakeRunPage::WantToUpdate) { - m_descriptionLabel->setText(tr("Refreshing cbp file in %1.").arg(m_buildDirectory)); + m_descriptionLabel->setText(tr("Refreshing cbp file in \"%1\" for buildconfiguration \"%2\" " + "for target \"%3\".") + .arg(m_buildDirectory) + .arg(m_buildConfigurationName) + .arg(m_kitName)); } // Build the list of generators/toolchains we want to offer @@ -549,69 +526,29 @@ void CMakeRunPage::initializePage() bool preferNinja = m_cmakeWizard->cmakeManager()->preferNinja(); - if (m_mode == Initial) { - // Try figuring out generator and toolchain from CMakeCache.txt - QByteArray cachedGenerator = cachedGeneratorFromFile(m_buildDirectory + QLatin1String("/CMakeCache.txt")); - - m_generatorComboBox->show(); - QList kitList = ProjectExplorer::KitManager::kits(); - int defaultIndex = 0; - - foreach (ProjectExplorer::Kit *k, kitList) { - CMakeTool *cmake = CMakeKitInformation::cmakeTool(k); - if (!cmake) - continue; - - bool hasCodeBlocksGenerator = cmake->hasCodeBlocksMsvcGenerator(); - bool hasNinjaGenerator = cmake->hasCodeBlocksNinjaGenerator(); - - QList infos = GeneratorInfo::generatorInfosFor(k, - hasNinjaGenerator ? GeneratorInfo::OfferNinja : GeneratorInfo::NoNinja, - preferNinja, - hasCodeBlocksGenerator); - - if (k == ProjectExplorer::KitManager::defaultKit()) - defaultIndex = m_generatorComboBox->count(); - - foreach (const GeneratorInfo &info, infos) - if (cachedGenerator.isEmpty() || info.generator() == cachedGenerator) - m_generatorComboBox->addItem(info.displayName(), qVariantFromValue(info)); + QList infos; + CMakeTool *cmake = CMakeKitInformation::cmakeTool(m_cmakeWizard->kit()); + if (cmake) { + // Note: We don't compare the actually cached generator to what is set in the buildconfiguration + // We assume that the buildconfiguration is correct + GeneratorInfo::Ninja ninja; + if (m_mode == CMakeRunPage::NeedToUpdate || m_mode == CMakeRunPage::WantToUpdate) { + ninja = m_cmakeWizard->useNinja() ? GeneratorInfo::ForceNinja : GeneratorInfo::NoNinja; + } else { // Recreate, ChangeDirectory + // Note: ReCreate is technically just a removed .cbp file, we assume the cache + // got removed too. If the cache still exists the error message from cmake should + // be a good hint to change the generator + ninja = cmake->hasCodeBlocksNinjaGenerator() ? GeneratorInfo::OfferNinja : GeneratorInfo::NoNinja; } - - if (!m_generatorComboBox->count()) { - m_generatorExtraText->setVisible(true); - m_generatorExtraText->setText(tr("The cached generator %1 is incompatible with the configured kits.") - .arg(QString::fromLatin1(cachedGenerator))); - } else { - m_generatorExtraText->setVisible(false); - } - - m_generatorComboBox->setCurrentIndex(defaultIndex); - } else { - QList infos; - CMakeTool *cmake = CMakeKitInformation::cmakeTool(m_cmakeWizard->kit()); - if (cmake) { - // Note: We don't compare the actually cached generator to what is set in the buildconfiguration - // We assume that the buildconfiguration is correct - GeneratorInfo::Ninja ninja; - if (m_mode == CMakeRunPage::NeedToUpdate || m_mode == CMakeRunPage::WantToUpdate) { - ninja = m_cmakeWizard->useNinja() ? GeneratorInfo::ForceNinja : GeneratorInfo::NoNinja; - } else { // Recreate, ChangeDirectory - // Note: ReCreate is technically just a removed .cbp file, we assume the cache - // got removed too. If the cache still exists the error message from cmake should - // be a good hint to change the generator - ninja = cmake->hasCodeBlocksNinjaGenerator() ? GeneratorInfo::OfferNinja : GeneratorInfo::NoNinja; - } - - infos = GeneratorInfo::generatorInfosFor(m_cmakeWizard->kit(), - ninja, - preferNinja, - true); - } - foreach (const GeneratorInfo &info, infos) - m_generatorComboBox->addItem(info.displayName(), qVariantFromValue(info)); + infos = GeneratorInfo::generatorInfosFor(m_cmakeWizard->kit(), + ninja, + preferNinja, + true); } + foreach (const GeneratorInfo &info, infos) + m_generatorComboBox->addItem(info.displayName(), qVariantFromValue(info)); + } bool CMakeRunPage::validatePage() @@ -640,11 +577,6 @@ void CMakeRunPage::runCMake() m_cmakeWizard->setKit(generatorInfo.kit()); m_cmakeWizard->setUseNinja(generatorInfo.isNinja()); - // If mode is initial the user chooses the kit, otherwise it's already chosen - // and the environment already contains the kit - if (m_mode == Initial) - generatorInfo.kit()->addToEnvironment(env); - m_runCMake->setEnabled(false); m_argumentsLineEdit->setEnabled(false); m_generatorComboBox->setEnabled(false); diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h index 613e2866753..1953b837f6d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h +++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h @@ -74,13 +74,14 @@ public: ChangeDirectory }; - /// used at importing a project without a .user file - CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, const QString &sourceDirectory, Utils::Environment env); - /// used to update if we have already a .user file /// recreates or updates the cbp file /// Also used to change the build directory of one buildconfiguration or create a new buildconfiguration - CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, Mode mode, const CMakeBuildInfo *info); + CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, + Mode mode, + const CMakeBuildInfo *info, + const QString &kitName, + const QString &buildConfigurationName); QString buildDirectory() const; QString sourceDirectory() const; @@ -163,8 +164,12 @@ class CMakeRunPage : public QWizardPage { Q_OBJECT public: - enum Mode { Initial, NeedToUpdate, Recreate, ChangeDirectory, WantToUpdate }; - explicit CMakeRunPage(CMakeOpenProjectWizard *cmakeWizard, Mode mode = Initial, const QString &buildDirectory = QString()); + enum Mode { NeedToUpdate, Recreate, ChangeDirectory, WantToUpdate }; + explicit CMakeRunPage(CMakeOpenProjectWizard *cmakeWizard, Mode mode, + const QString &buildDirectory, + const QString &initialArguments, + const QString &kitName, + const QString &buildConfigurationName); virtual void initializePage(); virtual bool validatePage(); @@ -191,6 +196,8 @@ private: bool m_haveCbpFile; Mode m_mode; QString m_buildDirectory; + QString m_kitName; + QString m_buildConfigurationName; }; } diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index aa231d5e303..343b9066515 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -144,9 +144,12 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur if (mode != CMakeOpenProjectWizard::Nothing) { CMakeBuildInfo info(cmakebc); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info); - if (copw.exec() == QDialog::Accepted) + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info, + bc->target()->displayName(), bc->displayName()); + if (copw.exec() == QDialog::Accepted) { cmakebc->setUseNinja(copw.useNinja()); // NeedToCreate can change the Ninja setting + cmakebc->setInitialArguments(QString()); + } } // reparse @@ -379,6 +382,16 @@ bool CMakeProject::parseCMakeLists() return true; } +bool CMakeProject::needsConfiguration() const +{ + return targets().isEmpty(); +} + +bool CMakeProject::requiresTargetPanel() const +{ + return false; +} + bool CMakeProject::isProjectFile(const FileName &fileName) { return m_watchedFiles.contains(fileName); @@ -529,31 +542,7 @@ Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *er bool hasUserFile = activeTarget(); if (!hasUserFile) { - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, projectDirectory().toString(), Environment::systemEnvironment()); - if (copw.exec() != QDialog::Accepted) - return RestoreResult::UserAbort; - Kit *k = copw.kit(); - Target *t = new Target(this, k); - CMakeBuildConfiguration *bc(new CMakeBuildConfiguration(t)); - bc->setDefaultDisplayName(QLatin1String("all")); - bc->setUseNinja(copw.useNinja()); - bc->setBuildDirectory(FileName::fromString(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(QLatin1String("clean")); - cleanMakeStep->setClean(true); - - t->addBuildConfiguration(bc); - - t->updateDefaultDeployConfigurations(); - - addTarget(t); + // Nothing to do, the target setup page will show up } else { // We have a user file, but we could still be missing the cbp file // or simply run createXml with the saved settings @@ -573,11 +562,14 @@ Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *er if (mode != CMakeOpenProjectWizard::Nothing) { CMakeBuildInfo info(activeBC); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info); - if (copw.exec() != QDialog::Accepted) + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info, + activeBC->target()->displayName(), activeBC->displayName()); + if (copw.exec() != QDialog::Accepted) { return RestoreResult::UserAbort; - else + } else { activeBC->setUseNinja(copw.useNinja()); + activeBC->setInitialArguments(QString()); + } } } @@ -614,6 +606,8 @@ CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title) QString CMakeProject::uiHeaderFile(const QString &uiFile) { + if (!activeTarget()) + return QString(); QFileInfo fi(uiFile); FileName project = projectDirectory(); FileName baseDirectory = FileName::fromString(fi.absolutePath()); @@ -684,6 +678,8 @@ void CMakeProject::updateRunConfigurations(Target *t) void CMakeProject::updateApplicationAndDeploymentTargets() { Target *t = activeTarget(); + if (!t) + return; QFile deploymentFile; QTextStream deploymentStream; diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index 304413cdc49..d61585ce7e9 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -113,6 +113,10 @@ public: bool parseCMakeLists(); + bool needsConfiguration() const; + + bool requiresTargetPanel() const; + signals: /// emitted after parsing void buildTargetsChanged(); diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index a50d483d24d..397c769d04e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -112,7 +112,8 @@ void CMakeManager::runCMake(ProjectExplorer::Project *project) CMakeBuildInfo info(bc); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), this, CMakeOpenProjectWizard::WantToUpdate, &info); + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), this, CMakeOpenProjectWizard::WantToUpdate, + &info, project->activeTarget()->displayName(), bc->displayName()); if (copw.exec() == QDialog::Accepted) cmakeProject->parseCMakeLists(); }