2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectnodes.h"
|
|
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakebuildsystem.h"
|
2016-11-07 18:20:47 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
2022-09-29 15:26:31 +02:00
|
|
|
#include "cmakeprojectmanagertr.h"
|
2019-03-06 14:17:17 +02:00
|
|
|
|
|
|
|
|
#include <android/androidconstants.h>
|
2022-09-29 15:26:31 +02:00
|
|
|
|
2021-01-29 17:01:10 +01:00
|
|
|
#include <ios/iosconstants.h>
|
2022-09-29 15:26:31 +02:00
|
|
|
|
2021-02-26 17:31:00 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2019-03-06 14:17:17 +02:00
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
2018-02-13 18:14:03 +01:00
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
using namespace ProjectExplorer;
|
2022-09-29 15:26:31 +02:00
|
|
|
using namespace Utils;
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
namespace CMakeProjectManager::Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
CMakeInputsNode::CMakeInputsNode(const FilePath &cmakeLists) :
|
2019-02-25 13:06:09 +01:00
|
|
|
ProjectExplorer::ProjectNode(cmakeLists)
|
2016-11-07 18:20:47 +01:00
|
|
|
{
|
|
|
|
|
setPriority(Node::DefaultPriority - 10); // Bottom most!
|
2022-09-29 15:26:31 +02:00
|
|
|
setDisplayName(Tr::tr("CMake Modules"));
|
2021-04-08 16:31:31 +02:00
|
|
|
setIcon(DirectoryIcon(ProjectExplorer::Constants::FILEOVERLAY_MODULES));
|
2017-11-22 13:39:53 +01:00
|
|
|
setListInProject(false);
|
2016-11-07 18:20:47 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
CMakeListsNode::CMakeListsNode(const FilePath &cmakeListPath) :
|
2016-11-07 18:20:47 +01:00
|
|
|
ProjectExplorer::ProjectNode(cmakeListPath)
|
|
|
|
|
{
|
2022-07-07 20:44:24 +02:00
|
|
|
setIcon(DirectoryIcon(Constants::Icons::FILE_OVERLAY));
|
2017-11-22 13:39:53 +01:00
|
|
|
setListInProject(false);
|
2016-11-07 18:20:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeListsNode::showInSimpleTree() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
std::optional<FilePath> CMakeListsNode::visibleAfterAddFileAction() const
|
2018-02-13 20:26:04 +01:00
|
|
|
{
|
2019-05-17 12:32:05 +02:00
|
|
|
return filePath().pathAppended("CMakeLists.txt");
|
2018-02-13 20:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
CMakeProjectNode::CMakeProjectNode(const FilePath &directory) :
|
2016-11-07 18:20:47 +01:00
|
|
|
ProjectExplorer::ProjectNode(directory)
|
|
|
|
|
{
|
|
|
|
|
setPriority(Node::DefaultProjectPriority + 1000);
|
2021-04-08 16:31:31 +02:00
|
|
|
setIcon(DirectoryIcon(ProjectExplorer::Constants::FILEOVERLAY_PRODUCT));
|
2017-11-22 13:39:53 +01:00
|
|
|
setListInProject(false);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:20:47 +01:00
|
|
|
QString CMakeProjectNode::tooltip() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
CMakeTargetNode::CMakeTargetNode(const FilePath &directory, const QString &target) :
|
2019-03-06 14:17:17 +02:00
|
|
|
ProjectExplorer::ProjectNode(directory)
|
2016-11-07 18:20:47 +01:00
|
|
|
{
|
2019-03-06 14:17:17 +02:00
|
|
|
m_target = target;
|
2016-11-07 18:20:47 +01:00
|
|
|
setPriority(Node::DefaultProjectPriority + 900);
|
2021-04-08 16:31:31 +02:00
|
|
|
setIcon(":/projectexplorer/images/build.png"); // TODO: Use proper icon!
|
2017-11-22 13:39:53 +01:00
|
|
|
setListInProject(false);
|
2019-09-24 14:39:50 +02:00
|
|
|
setProductType(ProductType::Other);
|
2016-11-07 18:20:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CMakeTargetNode::tooltip() const
|
|
|
|
|
{
|
|
|
|
|
return m_tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-18 10:10:53 +01:00
|
|
|
QString CMakeTargetNode::buildKey() const
|
|
|
|
|
{
|
2019-06-20 14:03:40 +02:00
|
|
|
return m_target;
|
2018-12-18 10:10:53 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
FilePath CMakeTargetNode::buildDirectory() const
|
2019-05-26 23:48:40 +03:00
|
|
|
{
|
|
|
|
|
return m_buildDirectory;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
void CMakeTargetNode::setBuildDirectory(const FilePath &directory)
|
2019-05-26 23:48:40 +03:00
|
|
|
{
|
|
|
|
|
m_buildDirectory = directory;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
QVariant CMakeTargetNode::data(Id role) const
|
2019-03-06 14:17:17 +02:00
|
|
|
{
|
|
|
|
|
auto value = [this](const QByteArray &key) -> QVariant {
|
|
|
|
|
for (const CMakeConfigItem &configItem : m_config) {
|
|
|
|
|
if (configItem.key == key)
|
|
|
|
|
return configItem.value;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto values = [this](const QByteArray &key) -> QVariant {
|
|
|
|
|
for (const CMakeConfigItem &configItem : m_config) {
|
|
|
|
|
if (configItem.key == key)
|
|
|
|
|
return configItem.values;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-05 18:49:26 +03:00
|
|
|
if (role == Android::Constants::AndroidAbi)
|
|
|
|
|
return value(Android::Constants::ANDROID_ABI);
|
|
|
|
|
|
|
|
|
|
if (role == Android::Constants::AndroidAbis)
|
|
|
|
|
return value(Android::Constants::ANDROID_ABIS);
|
|
|
|
|
|
|
|
|
|
// TODO: Concerns the variables below. Qt 6 uses target properties which cannot be read
|
|
|
|
|
// by the current mechanism, and the variables start with "Qt_" prefix.
|
|
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
if (role == Android::Constants::AndroidPackageSourceDir)
|
2021-02-09 21:37:21 +01:00
|
|
|
return value(Android::Constants::ANDROID_PACKAGE_SOURCE_DIR);
|
2019-03-06 14:17:17 +02:00
|
|
|
|
|
|
|
|
if (role == Android::Constants::AndroidExtraLibs)
|
2021-02-09 21:37:21 +01:00
|
|
|
return value(Android::Constants::ANDROID_EXTRA_LIBS);
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2021-09-05 18:49:26 +03:00
|
|
|
if (role == Android::Constants::AndroidDeploySettingsFile)
|
|
|
|
|
return value(Android::Constants::ANDROID_DEPLOYMENT_SETTINGS_FILE);
|
2020-08-24 09:24:22 +03:00
|
|
|
|
2021-09-05 18:49:26 +03:00
|
|
|
if (role == Android::Constants::AndroidApplicationArgs)
|
|
|
|
|
return value(Android::Constants::ANDROID_APPLICATION_ARGUMENTS);
|
2019-03-06 14:17:17 +02:00
|
|
|
|
2021-09-04 23:21:56 +03:00
|
|
|
if (role == Android::Constants::ANDROID_ABIS)
|
|
|
|
|
return value(Android::Constants::ANDROID_ABIS);
|
|
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
if (role == Android::Constants::AndroidSoLibPath)
|
2021-02-09 21:37:21 +01:00
|
|
|
return values(Android::Constants::ANDROID_SO_LIBS_PATHS);
|
2019-03-06 14:17:17 +02:00
|
|
|
|
|
|
|
|
if (role == Android::Constants::AndroidTargets)
|
|
|
|
|
return values("TARGETS_BUILD_PATH");
|
|
|
|
|
|
2021-09-05 18:49:26 +03:00
|
|
|
if (role == Android::Constants::AndroidApk)
|
|
|
|
|
return {};
|
|
|
|
|
|
2021-01-29 17:01:10 +01:00
|
|
|
if (role == Ios::Constants::IosTarget) {
|
|
|
|
|
// For some reason the artifact is e.g. "Debug/untitled.app/untitled" which is wrong.
|
|
|
|
|
// It actually is e.g. "Debug-iphonesimulator/untitled.app/untitled".
|
|
|
|
|
// Anyway, the iOS plugin is only interested in the app bundle name without .app.
|
|
|
|
|
return m_artifact.fileName();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 02:40:38 +03:00
|
|
|
if (role == Ios::Constants::IosBuildDir) {
|
|
|
|
|
// This is a path relative to root build directory.
|
|
|
|
|
// When generating Xcode project, CMake may put here a "${EFFECTIVE_PLATFORM_NAME}" macro,
|
|
|
|
|
// which is expanded by Xcode at build time.
|
|
|
|
|
// To get an actual executable path, iOS plugin replaces this macro with either "-iphoneos"
|
|
|
|
|
// or "-iphonesimulator" depending on the device type (which is unavailable here).
|
|
|
|
|
|
|
|
|
|
// dir/target.app/target -> dir
|
|
|
|
|
return m_artifact.parentDir().parentDir().toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (role == Ios::Constants::IosCmakeGenerator)
|
|
|
|
|
return value("CMAKE_GENERATOR");
|
2021-01-29 17:01:10 +01:00
|
|
|
|
|
|
|
|
QTC_ASSERT(false, qDebug() << "Unknown role" << role.toString());
|
2019-03-06 14:17:17 +02:00
|
|
|
// Better guess than "not present".
|
|
|
|
|
return value(role.toString().toUtf8());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeTargetNode::setConfig(const CMakeConfig &config)
|
|
|
|
|
{
|
|
|
|
|
m_config = config;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
std::optional<FilePath> CMakeTargetNode::visibleAfterAddFileAction() const
|
2018-02-13 20:26:04 +01:00
|
|
|
{
|
2019-05-17 12:32:05 +02:00
|
|
|
return filePath().pathAppended("CMakeLists.txt");
|
2018-02-13 20:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-06-03 17:36:02 +02:00
|
|
|
void CMakeTargetNode::build()
|
|
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
Project *p = getProject();
|
|
|
|
|
Target *t = p ? p->activeTarget() : nullptr;
|
|
|
|
|
if (t)
|
|
|
|
|
static_cast<CMakeBuildSystem *>(t->buildSystem())->buildCMakeTarget(displayName());
|
2019-06-03 17:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
void CMakeTargetNode::setTargetInformation(const QList<FilePath> &artifacts, const QString &type)
|
2016-11-07 18:20:47 +01:00
|
|
|
{
|
2022-09-29 15:26:31 +02:00
|
|
|
m_tooltip = Tr::tr("Target type: ") + type + "<br>";
|
2017-02-21 12:33:35 +01:00
|
|
|
if (artifacts.isEmpty()) {
|
2022-09-29 15:26:31 +02:00
|
|
|
m_tooltip += Tr::tr("No build artifacts");
|
2016-11-07 18:20:47 +01:00
|
|
|
} else {
|
2022-09-29 15:26:31 +02:00
|
|
|
const QStringList tmp = Utils::transform(artifacts, &FilePath::toUserOutput);
|
|
|
|
|
m_tooltip += Tr::tr("Build artifacts:") + "<br>" + tmp.join("<br>");
|
2021-01-29 17:01:10 +01:00
|
|
|
m_artifact = artifacts.first();
|
2016-11-07 18:20:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-19 15:21:54 +01:00
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
} // CMakeProjectManager::Internal
|