From ce43f6fbb4e6c652f822efba6679c5ea796c96a4 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 20 Dec 2018 18:51:12 +0100 Subject: [PATCH] Cmake: Move some code from project to build configuration Less use of activeBuildConfiguration and activeTarget. Change-Id: I9fa77a0084c5701e86530e4f9845c47baddaed4e Reviewed-by: Tobias Hunger --- .../cmakebuildconfiguration.cpp | 60 ++++++++++++++++- .../cmakebuildconfiguration.h | 6 +- .../cmakeprojectmanager/cmakeproject.cpp | 65 ++----------------- .../cmakeprojectmanager/cmakeproject.h | 3 - 4 files changed, 68 insertions(+), 66 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index c4ad0150f94..c286e63ea8c 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -143,9 +143,65 @@ bool CMakeBuildConfiguration::isParsing() const return project()->isParsing() && isActive(); } -QList CMakeBuildConfiguration::buildTargets() const +BuildTargetInfoList CMakeBuildConfiguration::appTargets() const { - return m_buildTargets; + BuildTargetInfoList appTargetList; + + for (const CMakeBuildTarget &ct : m_buildTargets) { + if (ct.targetType == UtilityType) + continue; + + if (ct.targetType == ExecutableType) { + BuildTargetInfo bti; + bti.displayName = ct.title; + bti.targetFilePath = ct.executable; + bti.projectFilePath = ct.sourceDirectory; + bti.projectFilePath.appendString('/'); + bti.workingDirectory = ct.workingDirectory; + bti.buildKey = ct.title + QChar('\n') + bti.projectFilePath.toString(); + appTargetList.list.append(bti); + } + } + + return appTargetList; +} + +DeploymentData CMakeBuildConfiguration::deploymentData() const +{ + DeploymentData result; + + QDir sourceDir = target()->project()->projectDirectory().toString(); + QDir buildDir = buildDirectory().toString(); + + QString deploymentPrefix; + QString deploymentFilePath = sourceDir.filePath("QtCreatorDeployment.txt"); + + bool hasDeploymentFile = QFileInfo::exists(deploymentFilePath); + if (!hasDeploymentFile) { + deploymentFilePath = buildDir.filePath("QtCreatorDeployment.txt"); + hasDeploymentFile = QFileInfo::exists(deploymentFilePath); + } + if (hasDeploymentFile) { + deploymentPrefix = result.addFilesFromDeploymentFile(deploymentFilePath, + sourceDir.absolutePath()); + } + + for (const CMakeBuildTarget &ct : m_buildTargets) { + if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) { + if (!ct.executable.isEmpty()) { + result.addFile(ct.executable.toString(), + deploymentPrefix + buildDir.relativeFilePath(ct.executable.toFileInfo().dir().path()), + DeployableFile::TypeExecutable); + } + } + } + + return result; +} + +QStringList CMakeBuildConfiguration::buildTargetTitles() const +{ + return transform(m_buildTargets, &CMakeBuildTarget::title); } FileName CMakeBuildConfiguration::shadowBuildDirectory(const FileName &projectFilePath, diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h index a763fbc1c5a..0bee0873ea7 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.h @@ -32,6 +32,8 @@ #include #include +#include +#include namespace CMakeProjectManager { class CMakeBuildInfo; @@ -60,7 +62,9 @@ public: QString error() const; QString warning() const; - QList buildTargets() const; + QStringList buildTargetTitles() const; + ProjectExplorer::BuildTargetInfoList appTargets() const; + ProjectExplorer::DeploymentData deploymentData() const; static Utils::FileName shadowBuildDirectory(const Utils::FileName &projectFilePath, const ProjectExplorer::Kit *k, diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 85070ac85b0..e281dd2edfa 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -276,7 +276,9 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc) setRootProjectNode(std::move(newRoot)); } - updateApplicationAndDeploymentTargets(); + t->setApplicationTargets(bc->appTargets()); + t->setDeploymentData(bc->deploymentData()); + t->updateDefaultRunConfigurations(); createGeneratedCodeModelSupport(); @@ -425,13 +427,6 @@ void CMakeProject::clearCMakeCache() m_buildDirManager.clearCache(); } -QList CMakeProject::buildTargets() const -{ - CMakeBuildConfiguration *bc = activeBc(this); - - return bc ? bc->buildTargets() : QList(); -} - void CMakeProject::handleReparseRequest(int reparseParameters) { QTC_ASSERT(!(reparseParameters & BuildDirManager::REPARSE_FAIL), return); @@ -474,7 +469,8 @@ void CMakeProject::startParsing(int reparseParameters) QStringList CMakeProject::buildTargetTitles() const { - return transform(buildTargets(), &CMakeBuildTarget::title); + CMakeBuildConfiguration *bc = activeBc(this); + return bc ? bc->buildTargetTitles() : QStringList(); } Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage) @@ -589,57 +585,6 @@ QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const } } -void CMakeProject::updateApplicationAndDeploymentTargets() -{ - Target *t = activeTarget(); - if (!t) - return; - - QDir sourceDir(t->project()->projectDirectory().toString()); - QDir buildDir(t->activeBuildConfiguration()->buildDirectory().toString()); - - BuildTargetInfoList appTargetList; - DeploymentData deploymentData; - - QString deploymentPrefix; - QString deploymentFilePath = sourceDir.filePath("QtCreatorDeployment.txt"); - bool hasDeploymentFile = QFileInfo::exists(deploymentFilePath); - if (!hasDeploymentFile) { - deploymentFilePath = buildDir.filePath("QtCreatorDeployment.txt"); - hasDeploymentFile = QFileInfo::exists(deploymentFilePath); - } - if (hasDeploymentFile) { - deploymentPrefix = deploymentData.addFilesFromDeploymentFile(deploymentFilePath, - sourceDir.absolutePath()); - } - - foreach (const CMakeBuildTarget &ct, buildTargets()) { - if (ct.targetType == UtilityType) - continue; - - if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) { - if (!ct.executable.isEmpty()) { - deploymentData.addFile(ct.executable.toString(), - deploymentPrefix + buildDir.relativeFilePath(ct.executable.toFileInfo().dir().path()), - DeployableFile::TypeExecutable); - } - } - if (ct.targetType == ExecutableType) { - BuildTargetInfo bti; - bti.displayName = ct.title; - bti.targetFilePath = ct.executable; - bti.projectFilePath = ct.sourceDirectory; - bti.projectFilePath.appendString('/'); - bti.workingDirectory = ct.workingDirectory; - bti.buildKey = ct.title + QChar('\n') + bti.projectFilePath.toString(); - appTargetList.list.append(bti); - } - } - - t->setApplicationTargets(appTargetList); - t->setDeploymentData(deploymentData); -} - bool CMakeProject::mustUpdateCMakeStateBeforeBuild() { return m_delayedParsingTimer.isActive(); diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index 4210184185f..a84a1130f51 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -86,8 +86,6 @@ protected: bool setupTarget(ProjectExplorer::Target *t) final; private: - QList buildTargets() const; - void handleReparseRequest(int reparseParameters); void startParsing(int reparseParameters); @@ -104,7 +102,6 @@ private: void createGeneratedCodeModelSupport(); QStringList filesGeneratedFrom(const QString &sourceFile) const final; - void updateApplicationAndDeploymentTargets(); // TODO probably need a CMake specific node structure QList m_buildTargets;