2019-08-06 12:41:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cmakebuildsystem.h"
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
#include "builddirparameters.h"
|
2019-08-06 12:41:46 +02:00
|
|
|
#include "cmakebuildconfiguration.h"
|
2020-06-03 11:27:37 +02:00
|
|
|
#include "cmakebuildstep.h"
|
|
|
|
|
#include "cmakebuildtarget.h"
|
2020-02-20 11:20:32 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2019-08-06 12:41:46 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
|
#include "cmakeprojectnodes.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakeprojectplugin.h"
|
|
|
|
|
#include "cmakespecificsettings.h"
|
2020-06-03 11:27:37 +02:00
|
|
|
#include "utils/algorithm.h"
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <android/androidconstants.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
|
#include <cpptools/cppprojectupdater.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <cpptools/generatedcodemodelsupport.h>
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2021-01-27 17:28:55 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2020-03-19 18:36:22 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2020-04-20 17:33:36 +02:00
|
|
|
#include <projectexplorer/session.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2020-04-24 10:29:43 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
|
|
|
|
#include <qtsupport/qtcppkitinfo.h>
|
2020-09-28 20:29:29 +03:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
#include <app/app_version.h>
|
|
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <utils/checkablemessagebox.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
#include <utils/mimetypes/mimetype.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QGuiApplication>
|
2020-06-03 11:27:37 +02:00
|
|
|
#include <QHash>
|
2020-09-28 15:10:04 +02:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <QLoggingCategory>
|
2020-04-24 10:29:43 +02:00
|
|
|
#include <QPushButton>
|
2020-11-09 12:51:36 +01:00
|
|
|
#include <QRegularExpression>
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
void copySourcePathToClipboard(Utils::optional<QString> srcPath,
|
|
|
|
|
const ProjectExplorer::ProjectNode *node)
|
|
|
|
|
{
|
|
|
|
|
QClipboard *clip = QGuiApplication::clipboard();
|
|
|
|
|
|
|
|
|
|
QDir projDir{node->filePath().toFileInfo().absoluteFilePath()};
|
|
|
|
|
clip->setText(QDir::cleanPath(projDir.relativeFilePath(srcPath.value())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::ProjectNode *node)
|
|
|
|
|
{
|
|
|
|
|
Utils::optional<QString> srcPath{};
|
|
|
|
|
|
|
|
|
|
for (const QString &file : filePaths) {
|
|
|
|
|
if (Utils::mimeTypeForFile(file).name() == CppTools::Constants::CPP_SOURCE_MIMETYPE) {
|
|
|
|
|
srcPath = file;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (srcPath) {
|
|
|
|
|
CMakeProjectManager::Internal::CMakeSpecificSettings *settings
|
|
|
|
|
= CMakeProjectManager::Internal::CMakeProjectPlugin::projectTypeSpecificSettings();
|
|
|
|
|
switch (settings->afterAddFileSetting()) {
|
|
|
|
|
case CMakeProjectManager::Internal::ASK_USER: {
|
|
|
|
|
bool checkValue{false};
|
|
|
|
|
QDialogButtonBox::StandardButton reply = Utils::CheckableMessageBox::question(
|
|
|
|
|
nullptr,
|
|
|
|
|
QMessageBox::tr("Copy to Clipboard?"),
|
|
|
|
|
QMessageBox::tr("Files are not automatically added to the "
|
|
|
|
|
"CMakeLists.txt file of the CMake project."
|
|
|
|
|
"\nCopy the path to the source files to the clipboard?"),
|
|
|
|
|
"Remember My Choice",
|
|
|
|
|
&checkValue,
|
|
|
|
|
QDialogButtonBox::Yes | QDialogButtonBox::No,
|
|
|
|
|
QDialogButtonBox::Yes);
|
|
|
|
|
if (checkValue) {
|
|
|
|
|
if (QDialogButtonBox::Yes == reply)
|
|
|
|
|
settings->setAfterAddFileSetting(
|
|
|
|
|
CMakeProjectManager::Internal::AfterAddFileAction::COPY_FILE_PATH);
|
|
|
|
|
else if (QDialogButtonBox::No == reply)
|
|
|
|
|
settings->setAfterAddFileSetting(
|
|
|
|
|
CMakeProjectManager::Internal::AfterAddFileAction::NEVER_COPY_FILE_PATH);
|
|
|
|
|
|
|
|
|
|
settings->toSettings(Core::ICore::settings());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (QDialogButtonBox::Yes == reply) {
|
|
|
|
|
copySourcePathToClipboard(srcPath, node);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CMakeProjectManager::Internal::COPY_FILE_PATH: {
|
|
|
|
|
copySourcePathToClipboard(srcPath, node);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case CMakeProjectManager::Internal::NEVER_COPY_FILE_PATH:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
namespace CMakeProjectManager {
|
2019-10-25 09:55:32 +02:00
|
|
|
namespace Internal {
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2020-01-15 14:39:23 +01:00
|
|
|
static Q_LOGGING_CATEGORY(cmakeBuildSystemLog, "qtc.cmake.buildsystem", QtWarningMsg);
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
// CMakeBuildSystem:
|
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
CMakeBuildSystem::CMakeBuildSystem(CMakeBuildConfiguration *bc)
|
|
|
|
|
: BuildSystem(bc)
|
2019-08-06 12:41:46 +02:00
|
|
|
, m_cppCodeModelUpdater(new CppTools::CppProjectUpdater)
|
|
|
|
|
{
|
|
|
|
|
// TreeScanner:
|
2019-10-25 09:55:32 +02:00
|
|
|
connect(&m_treeScanner, &TreeScanner::finished,
|
|
|
|
|
this, &CMakeBuildSystem::handleTreeScanningFinished);
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2019-10-23 08:47:05 +02:00
|
|
|
m_treeScanner.setFilter([this](const MimeType &mimeType, const FilePath &fn) {
|
2019-08-06 12:41:46 +02:00
|
|
|
// Mime checks requires more resources, so keep it last in check list
|
2019-10-23 08:47:05 +02:00
|
|
|
auto isIgnored = fn.toString().startsWith(projectFilePath().toString() + ".user")
|
2019-08-06 12:41:46 +02:00
|
|
|
|| TreeScanner::isWellKnownBinary(mimeType, fn);
|
|
|
|
|
|
|
|
|
|
// Cache mime check result for speed up
|
|
|
|
|
if (!isIgnored) {
|
|
|
|
|
auto it = m_mimeBinaryCache.find(mimeType.name());
|
|
|
|
|
if (it != m_mimeBinaryCache.end()) {
|
|
|
|
|
isIgnored = *it;
|
|
|
|
|
} else {
|
|
|
|
|
isIgnored = TreeScanner::isMimeBinary(mimeType, fn);
|
|
|
|
|
m_mimeBinaryCache[mimeType.name()] = isIgnored;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isIgnored;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
m_treeScanner.setTypeFactory([](const Utils::MimeType &mimeType, const Utils::FilePath &fn) {
|
|
|
|
|
auto type = TreeScanner::genericFileType(mimeType, fn);
|
|
|
|
|
if (type == FileType::Unknown) {
|
|
|
|
|
if (mimeType.isValid()) {
|
|
|
|
|
const QString mt = mimeType.name();
|
2020-04-07 14:44:22 +02:00
|
|
|
if (mt == CMakeProjectManager::Constants::CMAKE_PROJECT_MIMETYPE
|
|
|
|
|
|| mt == CMakeProjectManager::Constants::CMAKE_MIMETYPE)
|
2019-08-06 12:41:46 +02:00
|
|
|
type = FileType::Project;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
});
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
connect(&m_reader, &FileApiReader::configurationStarted, this, [this]() {
|
2020-03-19 18:24:23 +01:00
|
|
|
cmakeBuildConfiguration()->clearError(CMakeBuildConfiguration::ForceEnabledChanged::True);
|
2019-10-25 09:55:32 +02:00
|
|
|
});
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
connect(&m_reader,
|
|
|
|
|
&FileApiReader::dataAvailable,
|
|
|
|
|
this,
|
|
|
|
|
&CMakeBuildSystem::handleParsingSucceeded);
|
|
|
|
|
connect(&m_reader, &FileApiReader::errorOccurred, this, &CMakeBuildSystem::handleParsingFailed);
|
|
|
|
|
connect(&m_reader, &FileApiReader::dirty, this, &CMakeBuildSystem::becameDirty);
|
|
|
|
|
|
2020-08-11 16:36:24 +02:00
|
|
|
wireUpConnections();
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeBuildSystem::~CMakeBuildSystem()
|
|
|
|
|
{
|
|
|
|
|
if (!m_treeScanner.isFinished()) {
|
|
|
|
|
auto future = m_treeScanner.future();
|
|
|
|
|
future.cancel();
|
|
|
|
|
future.waitForFinished();
|
|
|
|
|
}
|
2020-06-15 12:31:44 +02:00
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
delete m_cppCodeModelUpdater;
|
|
|
|
|
qDeleteAll(m_extraCompilers);
|
|
|
|
|
qDeleteAll(m_allFiles);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::triggerParsing()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2020-06-15 12:31:44 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << cmakeBuildConfiguration()->displayName() << "Parsing has been triggered";
|
|
|
|
|
|
|
|
|
|
if (!cmakeBuildConfiguration()->isActive()) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "Parsing has been triggered: SKIPPING since BC is not active -- clearing state.";
|
|
|
|
|
stopParsingAndClearState();
|
|
|
|
|
return; // ignore request, this build configuration is not active!
|
|
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2020-02-27 14:46:16 +01:00
|
|
|
auto guard = guardParsingRun();
|
|
|
|
|
|
|
|
|
|
if (!guard.guardsProject()) {
|
|
|
|
|
// This can legitimately trigger if e.g. Build->Run CMake
|
|
|
|
|
// is selected while this here is already running.
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
// Stop old parse run and keep that ParseGuard!
|
2020-04-02 14:49:05 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Stopping current parsing run!";
|
2020-04-24 10:29:43 +02:00
|
|
|
stopParsingAndClearState();
|
|
|
|
|
} else {
|
|
|
|
|
// Use new ParseGuard
|
|
|
|
|
m_currentGuard = std::move(guard);
|
2020-02-27 14:46:16 +01:00
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
QTC_ASSERT(!m_reader.isParsing(), return );
|
2020-02-27 14:46:16 +01:00
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "ParseGuard acquired.";
|
2019-12-06 11:29:36 +01:00
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
if (m_allFiles.isEmpty()) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "No treescanner information available, forcing treescanner run.";
|
2020-04-24 10:29:43 +02:00
|
|
|
updateReparseParameters(REPARSE_SCAN);
|
2020-04-02 14:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int reparseParameters = takeReparseParameters();
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
m_waitingForScan = (reparseParameters & REPARSE_SCAN) != 0;
|
2019-08-06 12:41:46 +02:00
|
|
|
m_waitingForParse = true;
|
|
|
|
|
m_combinedScanAndParseResult = true;
|
|
|
|
|
|
|
|
|
|
if (m_waitingForScan) {
|
2020-04-24 10:29:43 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Starting TreeScanner";
|
2019-08-06 12:41:46 +02:00
|
|
|
QTC_CHECK(m_treeScanner.isFinished());
|
2019-10-25 09:55:32 +02:00
|
|
|
m_treeScanner.asyncScanForFiles(projectDirectory());
|
2019-08-06 12:41:46 +02:00
|
|
|
Core::ProgressManager::addTask(m_treeScanner.future(),
|
|
|
|
|
tr("Scan \"%1\" project tree")
|
2019-10-25 09:55:32 +02:00
|
|
|
.arg(project()->displayName()),
|
2019-08-06 12:41:46 +02:00
|
|
|
"CMake.Scan.Tree");
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
QTC_ASSERT(m_parameters.isValid(), return );
|
|
|
|
|
|
|
|
|
|
TaskHub::clearTasks(ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Parse called with flags:"
|
|
|
|
|
<< reparseParametersString(reparseParameters);
|
|
|
|
|
|
|
|
|
|
const QString cache = m_parameters.workDirectory.pathAppended("CMakeCache.txt").toString();
|
|
|
|
|
if (!QFileInfo::exists(cache)) {
|
2020-04-02 14:49:05 +02:00
|
|
|
reparseParameters |= REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN;
|
2020-04-24 10:29:43 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "No" << cache
|
|
|
|
|
<< "file found, new flags:" << reparseParametersString(reparseParameters);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
if ((0 == (reparseParameters & REPARSE_FORCE_EXTRA_CONFIGURATION))
|
|
|
|
|
&& !m_parameters.extraCMakeArguments.isEmpty()) {
|
|
|
|
|
if (mustApplyExtraArguments())
|
|
|
|
|
reparseParameters |= REPARSE_FORCE_CMAKE_RUN | REPARSE_FORCE_EXTRA_CONFIGURATION;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Asking reader to parse";
|
|
|
|
|
m_reader.parse(reparseParameters & REPARSE_FORCE_CMAKE_RUN,
|
2020-04-02 14:49:05 +02:00
|
|
|
reparseParameters & REPARSE_FORCE_INITIAL_CONFIGURATION,
|
|
|
|
|
reparseParameters & REPARSE_FORCE_EXTRA_CONFIGURATION);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
bool CMakeBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
|
|
|
|
|
{
|
|
|
|
|
if (dynamic_cast<CMakeTargetNode *>(context))
|
|
|
|
|
return action == ProjectAction::AddNewFile;
|
|
|
|
|
|
|
|
|
|
if (dynamic_cast<CMakeListsNode *>(context))
|
|
|
|
|
return action == ProjectAction::AddNewFile;
|
|
|
|
|
|
|
|
|
|
return BuildSystem::supportsAction(context, action, node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildSystem::addFiles(Node *context, const QStringList &filePaths, QStringList *notAdded)
|
|
|
|
|
{
|
|
|
|
|
if (auto n = dynamic_cast<CMakeProjectNode *>(context)) {
|
|
|
|
|
noAutoAdditionNotify(filePaths, n);
|
|
|
|
|
return true; // Return always true as autoadd is not supported!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
|
|
|
|
|
noAutoAdditionNotify(filePaths, n);
|
|
|
|
|
return true; // Return always true as autoadd is not supported!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BuildSystem::addFiles(context, filePaths, notAdded);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList CMakeBuildSystem::filesGeneratedFrom(const QString &sourceFile) const
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fi(sourceFile);
|
|
|
|
|
FilePath project = projectDirectory();
|
|
|
|
|
FilePath baseDirectory = FilePath::fromString(fi.absolutePath());
|
|
|
|
|
|
|
|
|
|
while (baseDirectory.isChildOf(project)) {
|
|
|
|
|
const FilePath cmakeListsTxt = baseDirectory.pathAppended("CMakeLists.txt");
|
|
|
|
|
if (cmakeListsTxt.exists())
|
|
|
|
|
break;
|
|
|
|
|
baseDirectory = baseDirectory.parentDir();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDir srcDirRoot = QDir(project.toString());
|
|
|
|
|
QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString());
|
2020-03-19 18:24:23 +01:00
|
|
|
QDir buildDir = QDir(cmakeBuildConfiguration()->buildDirectory().toString());
|
2019-10-25 09:55:32 +02:00
|
|
|
QString generatedFilePath = buildDir.absoluteFilePath(relativePath);
|
|
|
|
|
|
|
|
|
|
if (fi.suffix() == "ui") {
|
|
|
|
|
generatedFilePath += "/ui_";
|
|
|
|
|
generatedFilePath += fi.completeBaseName();
|
|
|
|
|
generatedFilePath += ".h";
|
|
|
|
|
return {QDir::cleanPath(generatedFilePath)};
|
|
|
|
|
}
|
|
|
|
|
if (fi.suffix() == "scxml") {
|
|
|
|
|
generatedFilePath += "/";
|
|
|
|
|
generatedFilePath += QDir::cleanPath(fi.completeBaseName());
|
|
|
|
|
return {generatedFilePath + ".h", generatedFilePath + ".cpp"};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Other types will be added when adapters for their compilers become available.
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
QString CMakeBuildSystem::reparseParametersString(int reparseFlags)
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
if (reparseFlags == REPARSE_DEFAULT) {
|
|
|
|
|
result = "<NONE>";
|
|
|
|
|
} else {
|
|
|
|
|
if (reparseFlags & REPARSE_URGENT)
|
|
|
|
|
result += " URGENT";
|
|
|
|
|
if (reparseFlags & REPARSE_FORCE_CMAKE_RUN)
|
|
|
|
|
result += " FORCE_CMAKE_RUN";
|
2020-04-02 14:49:05 +02:00
|
|
|
if (reparseFlags & REPARSE_FORCE_INITIAL_CONFIGURATION)
|
2020-04-24 10:29:43 +02:00
|
|
|
result += " FORCE_CONFIG";
|
|
|
|
|
if (reparseFlags & REPARSE_SCAN)
|
|
|
|
|
result += " SCAN";
|
|
|
|
|
}
|
|
|
|
|
return result.trimmed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::setParametersAndRequestParse(const BuildDirParameters ¶meters,
|
|
|
|
|
const int reparseParameters)
|
|
|
|
|
{
|
2020-06-15 12:31:44 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << cmakeBuildConfiguration()->displayName()
|
|
|
|
|
<< "setting parameters and requesting reparse"
|
2020-04-02 14:49:05 +02:00
|
|
|
<< reparseParametersString(reparseParameters);
|
2020-06-15 12:31:44 +02:00
|
|
|
|
|
|
|
|
if (!cmakeBuildConfiguration()->isActive()) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "setting parameters and requesting reparse: SKIPPING since BC is not active -- clearing state.";
|
|
|
|
|
stopParsingAndClearState();
|
|
|
|
|
return; // ignore request, this build configuration is not active!
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
if (!parameters.cmakeTool()) {
|
|
|
|
|
TaskHub::addTask(
|
|
|
|
|
BuildSystemTask(Task::Error,
|
|
|
|
|
tr("The kit needs to define a CMake tool to parse this project.")));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-19 09:45:55 +01:00
|
|
|
if (!parameters.cmakeTool()->hasFileApi()) {
|
|
|
|
|
TaskHub::addTask(BuildSystemTask(Task::Error,
|
|
|
|
|
CMakeKitAspect::msgUnsupportedVersion(
|
|
|
|
|
parameters.cmakeTool()->version().fullVersion)));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
QTC_ASSERT(parameters.isValid(), return );
|
|
|
|
|
|
|
|
|
|
m_parameters = parameters;
|
|
|
|
|
m_parameters.workDirectory = workDirectory(parameters);
|
|
|
|
|
updateReparseParameters(reparseParameters);
|
|
|
|
|
|
|
|
|
|
m_reader.setParameters(m_parameters);
|
|
|
|
|
|
|
|
|
|
if (reparseParameters & REPARSE_URGENT) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "calling requestReparse";
|
|
|
|
|
requestParse();
|
|
|
|
|
} else {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "calling requestDelayedReparse";
|
|
|
|
|
requestDelayedParse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
bool CMakeBuildSystem::mustApplyExtraArguments() const
|
2020-04-24 10:29:43 +02:00
|
|
|
{
|
2020-04-02 14:49:05 +02:00
|
|
|
if (m_parameters.extraCMakeArguments.isEmpty())
|
|
|
|
|
return false;
|
2020-04-24 10:29:43 +02:00
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
auto answer = QMessageBox::question(Core::ICore::mainWindow(),
|
|
|
|
|
tr("Apply configuration changes?"),
|
|
|
|
|
tr("Run CMake with \"%1\"?")
|
|
|
|
|
.arg(m_parameters.extraCMakeArguments.join(" ")),
|
|
|
|
|
QMessageBox::Apply | QMessageBox::Discard,
|
|
|
|
|
QMessageBox::Apply);
|
|
|
|
|
return answer == QMessageBox::Apply;
|
2020-04-24 10:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::runCMake()
|
|
|
|
|
{
|
2020-03-19 18:24:23 +01:00
|
|
|
BuildDirParameters parameters(cmakeBuildConfiguration());
|
2019-12-06 11:29:36 +01:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due \"Run CMake\" command";
|
2020-04-02 14:49:05 +02:00
|
|
|
setParametersAndRequestParse(parameters, REPARSE_FORCE_CMAKE_RUN | REPARSE_URGENT);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::runCMakeAndScanProjectTree()
|
|
|
|
|
{
|
2020-03-19 18:24:23 +01:00
|
|
|
BuildDirParameters parameters(cmakeBuildConfiguration());
|
2019-12-06 11:29:36 +01:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to \"Rescan Project\" command";
|
2020-04-02 14:49:05 +02:00
|
|
|
setParametersAndRequestParse(parameters,
|
|
|
|
|
REPARSE_FORCE_CMAKE_RUN | REPARSE_SCAN | REPARSE_URGENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::runCMakeWithExtraArguments()
|
|
|
|
|
{
|
|
|
|
|
BuildDirParameters parameters(cmakeBuildConfiguration());
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to \"Rescan Project\" command";
|
|
|
|
|
setParametersAndRequestParse(parameters,
|
|
|
|
|
REPARSE_FORCE_CMAKE_RUN | REPARSE_FORCE_EXTRA_CONFIGURATION
|
|
|
|
|
| REPARSE_URGENT);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::buildCMakeTarget(const QString &buildTarget)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!buildTarget.isEmpty(), return);
|
2021-01-27 17:28:55 +01:00
|
|
|
if (ProjectExplorerPlugin::saveModifiedFiles())
|
|
|
|
|
cmakeBuildConfiguration()->buildTarget(buildTarget);
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::handleTreeScanningFinished()
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(m_waitingForScan);
|
|
|
|
|
|
|
|
|
|
qDeleteAll(m_allFiles);
|
|
|
|
|
m_allFiles = Utils::transform(m_treeScanner.release(), [](const FileNode *fn) { return fn; });
|
|
|
|
|
|
|
|
|
|
m_waitingForScan = false;
|
|
|
|
|
|
|
|
|
|
combineScanAndParse();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
bool CMakeBuildSystem::persistCMakeState()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2020-04-02 14:49:05 +02:00
|
|
|
BuildDirParameters parameters(cmakeBuildConfiguration());
|
|
|
|
|
QTC_ASSERT(parameters.isValid(), return false);
|
|
|
|
|
|
|
|
|
|
parameters.workDirectory = workDirectory(parameters);
|
|
|
|
|
|
|
|
|
|
int reparseFlags = REPARSE_DEFAULT;
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Checking whether build system needs to be persisted:"
|
|
|
|
|
<< "workdir:" << parameters.workDirectory
|
|
|
|
|
<< "buildDir:" << parameters.buildDirectory
|
|
|
|
|
<< "Has extraargs:" << !parameters.extraCMakeArguments.isEmpty()
|
|
|
|
|
<< "must apply extra Args:"
|
|
|
|
|
<< mustApplyExtraArguments();
|
|
|
|
|
|
|
|
|
|
if (parameters.workDirectory == parameters.buildDirectory
|
|
|
|
|
&& !parameters.extraCMakeArguments.isEmpty() && mustApplyExtraArguments()) {
|
|
|
|
|
reparseFlags = REPARSE_FORCE_EXTRA_CONFIGURATION;
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << " -> must run CMake with extra arguments.";
|
|
|
|
|
}
|
|
|
|
|
if (parameters.workDirectory != parameters.buildDirectory
|
|
|
|
|
&& buildConfiguration()->createBuildDirectory()) {
|
|
|
|
|
reparseFlags = REPARSE_FORCE_INITIAL_CONFIGURATION;
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << " -> must run CMake with initial arguments.";
|
|
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
if (reparseFlags == REPARSE_DEFAULT)
|
2020-04-24 10:29:43 +02:00
|
|
|
return false;
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
if (reparseFlags == REPARSE_FORCE_INITIAL_CONFIGURATION)
|
|
|
|
|
parameters.workDirectory.clear();
|
2020-04-24 10:29:43 +02:00
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse to persist CMake State";
|
|
|
|
|
setParametersAndRequestParse(parameters,
|
|
|
|
|
REPARSE_URGENT | REPARSE_FORCE_CMAKE_RUN | reparseFlags);
|
2020-04-24 10:29:43 +02:00
|
|
|
return true;
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::clearCMakeCache()
|
|
|
|
|
{
|
2020-04-24 10:29:43 +02:00
|
|
|
QTC_ASSERT(m_parameters.isValid(), return );
|
|
|
|
|
QTC_ASSERT(!m_isHandlingError, return );
|
|
|
|
|
|
|
|
|
|
stopParsingAndClearState();
|
|
|
|
|
|
|
|
|
|
const FilePath cmakeCache = m_parameters.workDirectory / "CMakeCache.txt";
|
|
|
|
|
const FilePath cmakeFiles = m_parameters.workDirectory / "CMakeFiles";
|
|
|
|
|
|
|
|
|
|
if (cmakeCache.exists())
|
|
|
|
|
Utils::FileUtils::removeRecursively(cmakeCache);
|
|
|
|
|
if (cmakeFiles.exists())
|
|
|
|
|
Utils::FileUtils::removeRecursively(cmakeFiles);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2020-10-26 15:36:59 +01:00
|
|
|
std::unique_ptr<CMakeProjectNode> CMakeBuildSystem::generateProjectTree(
|
|
|
|
|
const QList<const FileNode *> &allFiles, bool includeHeaderNodes)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
2020-10-26 15:36:59 +01:00
|
|
|
auto root = m_reader.generateProjectTree(allFiles, errorMessage, includeHeaderNodes);
|
2019-10-25 09:55:32 +02:00
|
|
|
checkAndReportError(errorMessage);
|
|
|
|
|
return root;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
void CMakeBuildSystem::combineScanAndParse()
|
|
|
|
|
{
|
2020-03-19 18:24:23 +01:00
|
|
|
if (cmakeBuildConfiguration()->isActive()) {
|
2019-08-06 12:41:46 +02:00
|
|
|
if (m_waitingForParse || m_waitingForScan)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_combinedScanAndParseResult) {
|
2019-10-25 09:55:32 +02:00
|
|
|
updateProjectData();
|
|
|
|
|
m_currentGuard.markAsSuccess();
|
2020-10-26 15:36:59 +01:00
|
|
|
} else {
|
|
|
|
|
updateFallbackProjectData();
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
m_reader.resetData();
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
m_currentGuard = {};
|
2020-09-28 15:10:04 +02:00
|
|
|
m_testNames.clear();
|
2019-11-15 15:44:45 +01:00
|
|
|
|
|
|
|
|
emitBuildSystemUpdated();
|
2020-09-28 15:10:04 +02:00
|
|
|
|
|
|
|
|
QTimer::singleShot(0, this, &CMakeBuildSystem::runCTest);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::checkAndReportError(QString &errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (!errorMessage.isEmpty()) {
|
2020-03-19 18:24:23 +01:00
|
|
|
cmakeBuildConfiguration()->setError(errorMessage);
|
2019-10-25 09:55:32 +02:00
|
|
|
errorMessage.clear();
|
|
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::updateProjectData()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Updating CMake project data";
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
QTC_ASSERT(m_treeScanner.isFinished() && !m_reader.isParsing(), return );
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
cmakeBuildConfiguration()->project()->setExtraProjectFiles(m_reader.projectFilesToWatch());
|
2019-08-15 12:22:09 +02:00
|
|
|
|
2020-03-19 18:24:23 +01:00
|
|
|
CMakeConfig patchedConfig = cmakeBuildConfiguration()->configurationFromCMake();
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
QSet<QString> res;
|
|
|
|
|
QStringList apps;
|
2021-02-15 10:03:57 +01:00
|
|
|
for (const auto &target : qAsConst(m_buildTargets)) {
|
2019-08-06 12:41:46 +02:00
|
|
|
if (target.targetType == CMakeProjectManager::DynamicLibraryType) {
|
|
|
|
|
res.insert(target.executable.parentDir().toString());
|
|
|
|
|
apps.push_back(target.executable.toUserOutput());
|
|
|
|
|
}
|
|
|
|
|
// ### shall we add also the ExecutableType ?
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
CMakeConfigItem paths;
|
2021-02-09 21:37:21 +01:00
|
|
|
paths.key = Android::Constants::ANDROID_SO_LIBS_PATHS;
|
2019-08-06 12:41:46 +02:00
|
|
|
paths.values = Utils::toList(res);
|
|
|
|
|
patchedConfig.append(paths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apps.sort();
|
|
|
|
|
{
|
|
|
|
|
CMakeConfigItem appsPaths;
|
|
|
|
|
appsPaths.key = "TARGETS_BUILD_PATH";
|
|
|
|
|
appsPaths.values = apps;
|
|
|
|
|
patchedConfig.append(appsPaths);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Project *p = project();
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2020-10-26 15:36:59 +01:00
|
|
|
auto newRoot = generateProjectTree(m_allFiles, true);
|
2019-08-06 12:41:46 +02:00
|
|
|
if (newRoot) {
|
2019-11-20 15:21:54 +01:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
2020-09-28 20:29:29 +03:00
|
|
|
|
|
|
|
|
const FilePath buildDir = cmakeBuildConfiguration()->buildDirectory();
|
|
|
|
|
if (p->rootProjectNode()) {
|
|
|
|
|
const QString nodeName = p->rootProjectNode()->displayName();
|
|
|
|
|
p->setDisplayName(nodeName);
|
|
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2021-02-15 10:03:57 +01:00
|
|
|
for (const CMakeBuildTarget &bt : qAsConst(m_buildTargets)) {
|
2019-08-06 12:41:46 +02:00
|
|
|
const QString buildKey = bt.title;
|
|
|
|
|
if (ProjectNode *node = p->findNodeForBuildKey(buildKey)) {
|
|
|
|
|
if (auto targetNode = dynamic_cast<CMakeTargetNode *>(node))
|
|
|
|
|
targetNode->setConfig(patchedConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_extraCompilers);
|
2019-10-25 09:55:32 +02:00
|
|
|
m_extraCompilers = findExtraCompilers();
|
2019-08-06 12:41:46 +02:00
|
|
|
CppTools::GeneratedCodeModelSupport::update(m_extraCompilers);
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Extra compilers updated.";
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-20 12:12:53 +01:00
|
|
|
QtSupport::CppKitInfo kitInfo(kit());
|
2019-08-06 12:41:46 +02:00
|
|
|
QTC_ASSERT(kitInfo.isValid(), return );
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QString errorMessage;
|
2020-04-24 10:29:43 +02:00
|
|
|
RawProjectParts rpps = m_reader.createRawProjectParts(errorMessage);
|
2019-08-06 12:41:46 +02:00
|
|
|
if (!errorMessage.isEmpty())
|
2020-03-19 18:24:23 +01:00
|
|
|
cmakeBuildConfiguration()->setError(errorMessage);
|
2019-08-06 12:41:46 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Raw project parts created." << errorMessage;
|
|
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
for (RawProjectPart &rpp : rpps) {
|
2019-08-06 12:41:46 +02:00
|
|
|
rpp.setQtVersion(
|
|
|
|
|
kitInfo.projectPartQtVersion); // TODO: Check if project actually uses Qt.
|
2018-06-11 12:52:04 +02:00
|
|
|
const QString includeFileBaseDir = buildConfiguration()->buildDirectory().toString();
|
|
|
|
|
if (kitInfo.cxxToolChain) {
|
|
|
|
|
rpp.setFlagsForCxx({kitInfo.cxxToolChain, rpp.flagsForCxx.commandLineFlags,
|
|
|
|
|
includeFileBaseDir});
|
|
|
|
|
}
|
|
|
|
|
if (kitInfo.cToolChain) {
|
|
|
|
|
rpp.setFlagsForC({kitInfo.cToolChain, rpp.flagsForC.commandLineFlags,
|
|
|
|
|
includeFileBaseDir});
|
|
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-19 18:24:23 +01:00
|
|
|
m_cppCodeModelUpdater->update({p, kitInfo, cmakeBuildConfiguration()->environment(), rpps});
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
{
|
2019-10-25 09:55:32 +02:00
|
|
|
updateQmlJSCodeModel();
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
2020-03-19 18:24:23 +01:00
|
|
|
emit cmakeBuildConfiguration()->buildTypeChanged();
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "All CMake project data up to date.";
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 15:36:59 +01:00
|
|
|
void CMakeBuildSystem::updateFallbackProjectData()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Updating fallback CMake project data";
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(m_treeScanner.isFinished() && !m_reader.isParsing(), return );
|
|
|
|
|
|
|
|
|
|
auto newRoot = generateProjectTree(m_allFiles, false);
|
|
|
|
|
setRootProjectNode(std::move(newRoot));
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "All fallback CMake project data up to date.";
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 16:22:40 +01:00
|
|
|
void CMakeBuildSystem::updateCMakeConfiguration(QString &errorMessage)
|
|
|
|
|
{
|
|
|
|
|
CMakeConfig cmakeConfig = m_reader.takeParsedConfiguration(errorMessage);
|
|
|
|
|
for (auto &ci : cmakeConfig)
|
|
|
|
|
ci.inCMakeCache = true;
|
|
|
|
|
if (!errorMessage.isEmpty()) {
|
|
|
|
|
const CMakeConfig changes = cmakeBuildConfiguration()->configurationChanges();
|
|
|
|
|
for (const auto &ci : changes) {
|
|
|
|
|
const bool haveConfigItem = Utils::contains(cmakeConfig, [ci](const CMakeConfigItem& i) {
|
|
|
|
|
return i.key == ci.key;
|
|
|
|
|
});
|
|
|
|
|
if (!haveConfigItem)
|
|
|
|
|
cmakeConfig.append(ci);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cmakeBuildConfiguration()->setConfigurationFromCMake(cmakeConfig);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::handleParsingSucceeded()
|
|
|
|
|
{
|
2020-03-19 18:24:23 +01:00
|
|
|
if (!cmakeBuildConfiguration()->isActive()) {
|
2020-04-24 10:29:43 +02:00
|
|
|
stopParsingAndClearState();
|
2019-10-25 09:55:32 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-19 18:24:23 +01:00
|
|
|
cmakeBuildConfiguration()->clearError();
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
|
QString errorMessage;
|
|
|
|
|
{
|
2021-01-14 16:38:55 +01:00
|
|
|
m_buildTargets = Utils::transform(CMakeBuildStep::specialTargets(m_reader.usesAllCapsTargets()), [this](const QString &t) {
|
2020-06-03 11:27:37 +02:00
|
|
|
CMakeBuildTarget result;
|
|
|
|
|
result.title = t;
|
|
|
|
|
result.workingDirectory = m_parameters.workDirectory;
|
|
|
|
|
result.sourceDirectory = m_parameters.sourceDirectory;
|
|
|
|
|
return result;
|
|
|
|
|
});
|
|
|
|
|
m_buildTargets += m_reader.takeBuildTargets(errorMessage);
|
2019-10-25 09:55:32 +02:00
|
|
|
checkAndReportError(errorMessage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2021-02-04 16:22:40 +01:00
|
|
|
updateCMakeConfiguration(errorMessage);
|
2020-04-24 10:29:43 +02:00
|
|
|
checkAndReportError(errorMessage);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 15:10:04 +02:00
|
|
|
m_ctestPath = m_reader.ctestPath();
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
setApplicationTargets(appTargets());
|
|
|
|
|
setDeploymentData(deploymentData());
|
|
|
|
|
|
2020-04-23 18:29:27 +02:00
|
|
|
QTC_ASSERT(m_waitingForParse, return );
|
|
|
|
|
m_waitingForParse = false;
|
|
|
|
|
|
|
|
|
|
combineScanAndParse();
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::handleParsingFailed(const QString &msg)
|
|
|
|
|
{
|
2020-03-19 18:24:23 +01:00
|
|
|
cmakeBuildConfiguration()->setError(msg);
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
|
QString errorMessage;
|
2021-02-04 16:22:40 +01:00
|
|
|
updateCMakeConfiguration(errorMessage);
|
2019-10-25 09:55:32 +02:00
|
|
|
// ignore errorMessage here, we already got one.
|
|
|
|
|
|
2020-09-28 15:10:04 +02:00
|
|
|
m_ctestPath.clear();
|
|
|
|
|
|
2020-04-23 18:29:27 +02:00
|
|
|
QTC_CHECK(m_waitingForParse);
|
|
|
|
|
m_waitingForParse = false;
|
|
|
|
|
m_combinedScanAndParseResult = false;
|
|
|
|
|
|
|
|
|
|
combineScanAndParse();
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-11 16:36:24 +02:00
|
|
|
void CMakeBuildSystem::wireUpConnections()
|
2020-04-20 17:33:36 +02:00
|
|
|
{
|
|
|
|
|
// At this point the entire project will be fully configured, so let's connect everything and
|
|
|
|
|
// trigger an initial parser run
|
|
|
|
|
|
|
|
|
|
// Kit changed:
|
|
|
|
|
connect(KitManager::instance(), &KitManager::kitUpdated, this, [this](Kit *k) {
|
|
|
|
|
if (k != kit())
|
|
|
|
|
return; // not for us...
|
2020-04-02 14:49:05 +02:00
|
|
|
// FIXME: This is no longer correct: QtC now needs to update the initial parameters
|
|
|
|
|
// FIXME: and then ask to reconfigure.
|
2020-04-20 17:33:36 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to kit being updated";
|
2020-04-24 10:29:43 +02:00
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
2020-04-02 14:49:05 +02:00
|
|
|
CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
2020-04-20 17:33:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Became active/inactive:
|
2020-06-22 13:39:56 -05:00
|
|
|
connect(target(), &Target::activeBuildConfigurationChanged, this, [this]() {
|
2020-06-15 12:31:44 +02:00
|
|
|
// Build configuration has changed:
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to active BC changed";
|
|
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
|
|
|
|
CMakeBuildSystem::REPARSE_DEFAULT);
|
2020-04-20 17:33:36 +02:00
|
|
|
});
|
2020-08-11 16:36:24 +02:00
|
|
|
connect(project(), &Project::activeTargetChanged, this, [this]() {
|
|
|
|
|
// Build configuration has changed:
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to active target changed";
|
|
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
|
|
|
|
CMakeBuildSystem::REPARSE_DEFAULT);
|
|
|
|
|
});
|
2020-04-20 17:33:36 +02:00
|
|
|
|
|
|
|
|
// BuildConfiguration changed:
|
|
|
|
|
connect(cmakeBuildConfiguration(), &CMakeBuildConfiguration::environmentChanged, this, [this]() {
|
2020-06-15 12:31:44 +02:00
|
|
|
// The environment on our BC has changed, force CMake run to catch up with possible changes
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to environment change";
|
|
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
|
|
|
|
CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
2020-04-20 17:33:36 +02:00
|
|
|
});
|
2020-11-25 17:56:03 +01:00
|
|
|
connect(cmakeBuildConfiguration(),
|
|
|
|
|
&CMakeBuildConfiguration::buildDirectoryChanged,
|
|
|
|
|
this,
|
|
|
|
|
[this]() {
|
|
|
|
|
// The build directory of our BC has changed:
|
|
|
|
|
// Does the directory contain a CMakeCache ? Existing build, just parse
|
|
|
|
|
// No CMakeCache? Run with initial arguments!
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to build directory change";
|
|
|
|
|
const BuildDirParameters parameters(cmakeBuildConfiguration());
|
|
|
|
|
const bool hasCMakeCache = QFile::exists(
|
|
|
|
|
(parameters.buildDirectory / "CMakeCache.txt").toString());
|
|
|
|
|
const auto options = ReparseParameters(
|
|
|
|
|
hasCMakeCache
|
|
|
|
|
? REPARSE_DEFAULT
|
|
|
|
|
: (REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN));
|
|
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()), options);
|
|
|
|
|
});
|
2020-04-20 17:33:36 +02:00
|
|
|
|
|
|
|
|
connect(project(), &Project::projectFileIsDirty, this, [this]() {
|
|
|
|
|
if (cmakeBuildConfiguration()->isActive() && !isParsing()) {
|
2020-09-07 15:56:18 +02:00
|
|
|
const auto cmake = CMakeKitAspect::cmakeTool(cmakeBuildConfiguration()->kit());
|
2020-04-20 17:33:36 +02:00
|
|
|
if (cmake && cmake->isAutoRun()) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to dirty project file";
|
2020-04-24 10:29:43 +02:00
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
2020-11-25 14:21:02 +01:00
|
|
|
CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
2020-04-20 17:33:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Force initial parsing run:
|
2020-04-02 14:49:05 +02:00
|
|
|
if (cmakeBuildConfiguration()->isActive()) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Initial run:";
|
2020-04-24 10:29:43 +02:00
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()),
|
2020-04-02 14:49:05 +02:00
|
|
|
CMakeBuildSystem::REPARSE_DEFAULT);
|
|
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FilePath CMakeBuildSystem::workDirectory(const BuildDirParameters ¶meters)
|
|
|
|
|
{
|
|
|
|
|
const Utils::FilePath bdir = parameters.buildDirectory;
|
|
|
|
|
const CMakeTool *cmake = parameters.cmakeTool();
|
2020-11-26 09:27:00 +01:00
|
|
|
|
|
|
|
|
// use the build directory if it already exists anyhow
|
2020-04-24 10:29:43 +02:00
|
|
|
if (bdir.exists()) {
|
|
|
|
|
m_buildDirToTempDir.erase(bdir);
|
|
|
|
|
return bdir;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 09:27:00 +01:00
|
|
|
// use the build directory if the cmake tool settings are set to automatically create them,
|
|
|
|
|
// or if the configuration was changed by the user
|
|
|
|
|
if ((cmake && cmake->autoCreateBuildDirectory()) || !parameters.extraCMakeArguments.isEmpty()) {
|
2020-04-24 10:29:43 +02:00
|
|
|
if (!cmakeBuildConfiguration()->createBuildDirectory())
|
|
|
|
|
handleParsingFailed(
|
|
|
|
|
tr("Failed to create build directory \"%1\".").arg(bdir.toUserOutput()));
|
|
|
|
|
return bdir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto tmpDirIt = m_buildDirToTempDir.find(bdir);
|
|
|
|
|
if (tmpDirIt == m_buildDirToTempDir.end()) {
|
|
|
|
|
auto ret = m_buildDirToTempDir.emplace(
|
|
|
|
|
std::make_pair(bdir, std::make_unique<Utils::TemporaryDirectory>("qtc-cmake-XXXXXXXX")));
|
|
|
|
|
QTC_ASSERT(ret.second, return bdir);
|
|
|
|
|
tmpDirIt = ret.first;
|
|
|
|
|
|
|
|
|
|
if (!tmpDirIt->second->isValid()) {
|
|
|
|
|
handleParsingFailed(tr("Failed to create temporary directory \"%1\".")
|
|
|
|
|
.arg(QDir::toNativeSeparators(tmpDirIt->second->path())));
|
|
|
|
|
return bdir;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Utils::FilePath::fromString(tmpDirIt->second->path());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::stopParsingAndClearState()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "stopping parsing run!";
|
|
|
|
|
m_reader.stop();
|
|
|
|
|
m_reader.resetData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::becameDirty()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "CMakeBuildSystem: becameDirty was triggered.";
|
|
|
|
|
if (isParsing())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const CMakeTool *tool = m_parameters.cmakeTool();
|
|
|
|
|
if (!tool->isAutoRun())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-04-02 14:49:05 +02:00
|
|
|
setParametersAndRequestParse(BuildDirParameters(cmakeBuildConfiguration()), REPARSE_SCAN);
|
2020-04-24 10:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::updateReparseParameters(const int parameters)
|
|
|
|
|
{
|
|
|
|
|
m_reparseParameters |= parameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CMakeBuildSystem::takeReparseParameters()
|
|
|
|
|
{
|
|
|
|
|
int result = m_reparseParameters;
|
|
|
|
|
m_reparseParameters = REPARSE_DEFAULT;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 15:10:04 +02:00
|
|
|
void CMakeBuildSystem::runCTest()
|
|
|
|
|
{
|
|
|
|
|
if (!cmakeBuildConfiguration()->error().isEmpty() || m_ctestPath.isEmpty()) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Cancel ctest run after failed cmake run";
|
|
|
|
|
emit testInformationUpdated();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting ctest run after cmake run";
|
|
|
|
|
|
2021-01-11 07:55:53 +01:00
|
|
|
BuildDirParameters parameters(cmakeBuildConfiguration());
|
|
|
|
|
QTC_ASSERT(parameters.isValid(), return);
|
|
|
|
|
|
|
|
|
|
FilePath workingDirectory = workDirectory(parameters);
|
2020-09-28 15:10:04 +02:00
|
|
|
CommandLine cmd{m_ctestPath, {"-N", "--show-only=json-v1"}};
|
|
|
|
|
SynchronousProcess ctest;
|
|
|
|
|
ctest.setTimeoutS(1);
|
|
|
|
|
ctest.setEnvironment(cmakeBuildConfiguration()->environment().toStringList());
|
2021-01-11 07:55:53 +01:00
|
|
|
ctest.setWorkingDirectory(workingDirectory.toString());
|
2020-09-28 15:10:04 +02:00
|
|
|
|
|
|
|
|
const SynchronousProcessResponse response = ctest.run(cmd);
|
|
|
|
|
if (response.result == SynchronousProcessResponse::Finished) {
|
|
|
|
|
const QJsonDocument json = QJsonDocument::fromJson(response.allRawOutput());
|
|
|
|
|
if (!json.isEmpty() && json.isObject()) {
|
|
|
|
|
const QJsonObject jsonObj = json.object();
|
|
|
|
|
const QJsonObject btGraph = jsonObj.value("backtraceGraph").toObject();
|
|
|
|
|
const QJsonArray cmakelists = btGraph.value("files").toArray();
|
|
|
|
|
const QJsonArray nodes = btGraph.value("nodes").toArray();
|
|
|
|
|
const QJsonArray tests = jsonObj.value("tests").toArray();
|
|
|
|
|
for (const QJsonValue &testVal : tests) {
|
|
|
|
|
const QJsonObject test = testVal.toObject();
|
|
|
|
|
QTC_ASSERT(!test.isEmpty(), continue);
|
|
|
|
|
const int bt = test.value("backtrace").toInt(-1);
|
|
|
|
|
QTC_ASSERT(bt != -1, continue);
|
|
|
|
|
const QJsonObject btRef = nodes.at(bt).toObject();
|
|
|
|
|
int file = btRef.value("file").toInt(-1);
|
|
|
|
|
int line = btRef.value("line").toInt(-1);
|
|
|
|
|
QTC_ASSERT(file != -1 && line != -1, continue);
|
|
|
|
|
m_testNames.append({test.value("name").toString(),
|
|
|
|
|
FilePath::fromString(cmakelists.at(file).toString()),
|
|
|
|
|
line
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
emit testInformationUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
CMakeBuildConfiguration *CMakeBuildSystem::cmakeBuildConfiguration() const
|
|
|
|
|
{
|
2020-03-19 18:36:22 +01:00
|
|
|
return static_cast<CMakeBuildConfiguration *>(BuildSystem::buildConfiguration());
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-21 14:00:56 +01:00
|
|
|
static Utils::FilePaths librarySearchPaths(const CMakeBuildSystem *bs, const QString &buildKey)
|
|
|
|
|
{
|
|
|
|
|
const CMakeBuildTarget cmakeBuildTarget
|
|
|
|
|
= Utils::findOrDefault(bs->buildTargets(), Utils::equal(&CMakeBuildTarget::title, buildKey));
|
|
|
|
|
|
|
|
|
|
return cmakeBuildTarget.libraryDirectories;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
const QList<BuildTargetInfo> CMakeBuildSystem::appTargets() const
|
|
|
|
|
{
|
|
|
|
|
QList<BuildTargetInfo> appTargetList;
|
2020-03-19 18:24:23 +01:00
|
|
|
const bool forAndroid = DeviceTypeKitAspect::deviceTypeId(kit())
|
|
|
|
|
== Android::Constants::ANDROID_DEVICE_TYPE;
|
2019-10-25 09:55:32 +02:00
|
|
|
for (const CMakeBuildTarget &ct : m_buildTargets) {
|
|
|
|
|
if (ct.targetType == UtilityType)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (ct.targetType == ExecutableType || (forAndroid && ct.targetType == DynamicLibraryType)) {
|
2020-01-21 14:00:56 +01:00
|
|
|
const QString buildKey = ct.title;
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
BuildTargetInfo bti;
|
|
|
|
|
bti.displayName = ct.title;
|
|
|
|
|
bti.targetFilePath = ct.executable;
|
|
|
|
|
bti.projectFilePath = ct.sourceDirectory.stringAppended("/");
|
|
|
|
|
bti.workingDirectory = ct.workingDirectory;
|
2020-01-21 14:00:56 +01:00
|
|
|
bti.buildKey = buildKey;
|
2019-12-12 11:15:36 +01:00
|
|
|
bti.usesTerminal = !ct.linksToQtGui;
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
|
// Workaround for QTCREATORBUG-19354:
|
2020-01-21 14:00:56 +01:00
|
|
|
bti.runEnvModifier = [this, buildKey](Environment &env, bool enabled) {
|
|
|
|
|
if (enabled) {
|
|
|
|
|
const Utils::FilePaths paths = librarySearchPaths(this, buildKey);
|
|
|
|
|
env.prependOrSetLibrarySearchPaths(Utils::transform(paths, &FilePath::toString));
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
appTargetList.append(bti);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return appTargetList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList CMakeBuildSystem::buildTargetTitles() const
|
|
|
|
|
{
|
|
|
|
|
return transform(m_buildTargets, &CMakeBuildTarget::title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<CMakeBuildTarget> &CMakeBuildSystem::buildTargets() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargets;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
CMakeConfig CMakeBuildSystem::parseCMakeCacheDotTxt(const Utils::FilePath &cacheFile,
|
|
|
|
|
QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (!cacheFile.exists()) {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("CMakeCache.txt file not found.");
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
CMakeConfig result = CMakeConfigItem::itemsFromFile(cacheFile, errorMessage);
|
|
|
|
|
if (!errorMessage->isEmpty())
|
|
|
|
|
return {};
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 16:38:55 +01:00
|
|
|
bool CMakeBuildSystem::isMultiConfig() const
|
|
|
|
|
{
|
|
|
|
|
return m_reader.isMultiConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildSystem::usesAllCapsTargets() const
|
|
|
|
|
{
|
|
|
|
|
return m_reader.usesAllCapsTargets();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 15:10:04 +02:00
|
|
|
const QList<TestCaseInfo> CMakeBuildSystem::testcasesInfo() const
|
|
|
|
|
{
|
|
|
|
|
return m_testNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandLine CMakeBuildSystem::commandLineForTests(const QList<QString> &tests,
|
|
|
|
|
const QStringList &options) const
|
|
|
|
|
{
|
|
|
|
|
QStringList args = options;
|
|
|
|
|
auto current = Utils::transform<QSet<QString>>(m_testNames, &TestCaseInfo::name);
|
|
|
|
|
if (tests.isEmpty() || current == Utils::toSet(tests))
|
|
|
|
|
return {m_ctestPath, args};
|
|
|
|
|
|
|
|
|
|
const QString regex = Utils::transform(tests, [](const QString ¤t) {
|
|
|
|
|
return QRegularExpression::escape(current);
|
|
|
|
|
}).join('|');
|
|
|
|
|
args << "-R" << QString('(' + regex + ')');
|
|
|
|
|
return {m_ctestPath, args};
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
DeploymentData CMakeBuildSystem::deploymentData() const
|
|
|
|
|
{
|
|
|
|
|
DeploymentData result;
|
|
|
|
|
|
2020-03-19 18:24:23 +01:00
|
|
|
QDir sourceDir = project()->projectDirectory().toString();
|
|
|
|
|
QDir buildDir = cmakeBuildConfiguration()->buildDirectory().toString();
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
deploymentPrefix = result.addFilesFromDeploymentFile(deploymentFilePath,
|
|
|
|
|
sourceDir.absolutePath());
|
|
|
|
|
for (const CMakeBuildTarget &ct : m_buildTargets) {
|
|
|
|
|
if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) {
|
|
|
|
|
if (!ct.executable.isEmpty()
|
|
|
|
|
&& result.deployableForLocalFile(ct.executable).localFilePath() != ct.executable) {
|
|
|
|
|
result.addFile(ct.executable.toString(),
|
|
|
|
|
deploymentPrefix + buildDir.relativeFilePath(ct.executable.toFileInfo().dir().path()),
|
|
|
|
|
DeployableFile::TypeExecutable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ExtraCompiler *> CMakeBuildSystem::findExtraCompilers()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: start.";
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ExtraCompiler *> extraCompilers;
|
|
|
|
|
const QList<ExtraCompilerFactory *> factories = ExtraCompilerFactory::extraCompilerFactories();
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: Got factories.";
|
|
|
|
|
|
|
|
|
|
const QSet<QString> fileExtensions = Utils::transform<QSet>(factories,
|
|
|
|
|
&ExtraCompilerFactory::sourceTag);
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: Got file extensions:"
|
|
|
|
|
<< fileExtensions;
|
|
|
|
|
|
|
|
|
|
// Find all files generated by any of the extra compilers, in a rather crude way.
|
2019-10-25 09:55:32 +02:00
|
|
|
Project *p = project();
|
2020-11-18 22:42:51 +01:00
|
|
|
const FilePaths fileList = p->files([&fileExtensions](const Node *n) {
|
|
|
|
|
if (!Project::SourceFiles(n))
|
2019-08-06 12:41:46 +02:00
|
|
|
return false;
|
|
|
|
|
const QString fp = n->filePath().toString();
|
|
|
|
|
const int pos = fp.lastIndexOf('.');
|
|
|
|
|
return pos >= 0 && fileExtensions.contains(fp.mid(pos + 1));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: Got list of files to check.";
|
|
|
|
|
|
|
|
|
|
// Generate the necessary information:
|
|
|
|
|
for (const FilePath &file : fileList) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "Finding Extra Compilers: Processing" << file.toUserOutput();
|
|
|
|
|
ExtraCompilerFactory *factory = Utils::findOrDefault(factories,
|
|
|
|
|
[&file](const ExtraCompilerFactory *f) {
|
|
|
|
|
return file.endsWith(
|
|
|
|
|
'.' + f->sourceTag());
|
|
|
|
|
});
|
|
|
|
|
QTC_ASSERT(factory, continue);
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
QStringList generated = filesGeneratedFrom(file.toString());
|
2019-08-06 12:41:46 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "Finding Extra Compilers: generated files:" << generated;
|
|
|
|
|
if (generated.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-12-17 14:07:53 +01:00
|
|
|
const FilePaths fileNames = transform(generated, [](const QString &s) {
|
2019-08-06 12:41:46 +02:00
|
|
|
return FilePath::fromString(s);
|
|
|
|
|
});
|
|
|
|
|
extraCompilers.append(factory->create(p, file, fileNames));
|
|
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "Finding Extra Compilers: done with" << file.toUserOutput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: done.";
|
|
|
|
|
|
|
|
|
|
return extraCompilers;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::updateQmlJSCodeModel()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
|
|
|
|
|
if (!modelManager)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
Project *p = project();
|
2019-08-06 12:41:46 +02:00
|
|
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo = modelManager
|
|
|
|
|
->defaultProjectInfoForProject(p);
|
|
|
|
|
|
|
|
|
|
projectInfo.importPaths.clear();
|
|
|
|
|
|
2020-03-19 18:24:23 +01:00
|
|
|
const CMakeConfig &cm = cmakeBuildConfiguration()->configurationFromCMake();
|
2019-08-06 12:41:46 +02:00
|
|
|
const QString cmakeImports = QString::fromUtf8(CMakeConfigItem::valueOf("QML_IMPORT_PATH", cm));
|
|
|
|
|
|
|
|
|
|
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
|
|
|
|
projectInfo.importPaths.maybeInsert(FilePath::fromString(cmakeImport), QmlJS::Dialect::Qml);
|
|
|
|
|
|
2020-02-05 15:16:04 +01:00
|
|
|
project()->setProjectLanguage(ProjectExplorer::Constants::QMLJS_LANGUAGE_ID,
|
|
|
|
|
!projectInfo.sourceFiles.isEmpty());
|
2019-08-06 12:41:46 +02:00
|
|
|
modelManager->updateProjectInfo(projectInfo, p);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
} // namespace Internal
|
2019-08-06 12:41:46 +02:00
|
|
|
} // namespace CMakeProjectManager
|