forked from qt-creator/qt-creator
Cmake: Move some code from project to build configuration
Less use of activeBuildConfiguration and activeTarget. Change-Id: I9fa77a0084c5701e86530e4f9845c47baddaed4e Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -143,9 +143,65 @@ bool CMakeBuildConfiguration::isParsing() const
|
||||
return project()->isParsing() && isActive();
|
||||
}
|
||||
|
||||
QList<CMakeBuildTarget> 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,
|
||||
|
@@ -32,6 +32,8 @@
|
||||
#include <cpptools/cpprawprojectpart.h>
|
||||
|
||||
#include <projectexplorer/buildconfiguration.h>
|
||||
#include <projectexplorer/buildtargetinfo.h>
|
||||
#include <projectexplorer/deploymentdata.h>
|
||||
|
||||
namespace CMakeProjectManager {
|
||||
class CMakeBuildInfo;
|
||||
@@ -60,7 +62,9 @@ public:
|
||||
QString error() const;
|
||||
QString warning() const;
|
||||
|
||||
QList<CMakeBuildTarget> 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,
|
||||
|
@@ -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<CMakeBuildTarget> CMakeProject::buildTargets() const
|
||||
{
|
||||
CMakeBuildConfiguration *bc = activeBc(this);
|
||||
|
||||
return bc ? bc->buildTargets() : QList<CMakeBuildTarget>();
|
||||
}
|
||||
|
||||
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();
|
||||
|
@@ -86,8 +86,6 @@ protected:
|
||||
bool setupTarget(ProjectExplorer::Target *t) final;
|
||||
|
||||
private:
|
||||
QList<CMakeBuildTarget> 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<CMakeBuildTarget> m_buildTargets;
|
||||
|
Reference in New Issue
Block a user