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
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
#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"
|
2021-09-21 22:22:37 +02:00
|
|
|
#include "cmakeproject.h"
|
2019-08-06 12:41:46 +02:00
|
|
|
#include "cmakeprojectconstants.h"
|
2022-09-29 15:26:31 +02:00
|
|
|
#include "cmakeprojectmanagertr.h"
|
2020-04-17 15:30:05 +02:00
|
|
|
#include "cmakespecificsettings.h"
|
2021-09-27 17:26:40 +02:00
|
|
|
#include "projecttreehelper.h"
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
#include <android/androidconstants.h>
|
2022-06-10 16:41:27 +02:00
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2023-04-13 12:52:39 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2022-12-06 17:07:52 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2022-06-10 16:41:27 +02:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
|
|
|
|
#include <cppeditor/cppprojectupdater.h>
|
2022-06-10 16:41:27 +02:00
|
|
|
|
2023-01-04 13:05:36 +01:00
|
|
|
#include <projectexplorer/extracompiler.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>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2020-04-24 10:29:43 +02:00
|
|
|
#include <projectexplorer/taskhub.h>
|
2022-06-10 16:41:27 +02:00
|
|
|
|
2023-04-13 12:52:39 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
|
|
|
|
#include <texteditor/textdocument.h>
|
|
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2023-04-20 18:55:16 +02:00
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#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>
|
|
|
|
|
|
2022-06-10 16:41:27 +02:00
|
|
|
#include <utils/algorithm.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>
|
2021-03-01 18:48:24 +01:00
|
|
|
#include <utils/macroexpander.h>
|
2023-05-03 17:05:35 +02:00
|
|
|
#include <utils/process.h>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2020-04-17 15:30:05 +02:00
|
|
|
#include <QClipboard>
|
|
|
|
|
#include <QGuiApplication>
|
2020-09-28 15:10:04 +02:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2019-08-06 12:41:46 +02:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2023-04-13 12:52:39 +02:00
|
|
|
using namespace TextEditor;
|
2019-08-06 12:41:46 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
namespace CMakeProjectManager::Internal {
|
2020-04-17 15:30:05 +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)
|
2021-08-30 10:58:08 +02:00
|
|
|
, m_cppCodeModelUpdater(new CppEditor::CppProjectUpdater)
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
// 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
|
2021-09-27 17:26:40 +02:00
|
|
|
auto isIgnored = TreeScanner::isWellKnownBinary(mimeType, fn);
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-26 16:54:40 +01:00
|
|
|
m_treeScanner.setTypeFactory([](const MimeType &mimeType, const FilePath &fn) {
|
2019-08-06 12:41:46 +02:00
|
|
|
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
|
|
|
|
2022-04-25 13:40:05 +02:00
|
|
|
connect(&m_reader, &FileApiReader::configurationStarted, this, [this] {
|
|
|
|
|
clearError(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();
|
2022-05-02 16:58:26 +02:00
|
|
|
|
|
|
|
|
m_isMultiConfig = CMakeGeneratorKitAspect::isMultiConfigGenerator(bc->kit());
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::triggerParsing()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2022-04-25 13:40:05 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << buildConfiguration()->displayName() << "Parsing has been triggered";
|
2020-06-15 12:31:44 +02:00
|
|
|
|
2022-04-25 13:40:05 +02:00
|
|
|
if (!buildConfiguration()->isActive()) {
|
2020-06-15 12:31:44 +02:00
|
|
|
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
|
|
|
int reparseParameters = takeReparseParameters();
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
m_waitingForParse = true;
|
|
|
|
|
m_combinedScanAndParseResult = true;
|
|
|
|
|
|
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);
|
|
|
|
|
|
2023-06-07 08:19:20 +02:00
|
|
|
const FilePath cache = m_parameters.buildDirectory.pathAppended("CMakeCache.txt");
|
|
|
|
|
if (!cache.exists()) {
|
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))
|
2021-12-28 21:42:29 +01:00
|
|
|
&& mustApplyConfigurationChangesArguments(m_parameters)) {
|
2021-03-02 13:08:29 +01:00
|
|
|
reparseParameters |= REPARSE_FORCE_CMAKE_RUN | REPARSE_FORCE_EXTRA_CONFIGURATION;
|
2020-04-02 14:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:58:19 +02:00
|
|
|
// The code model will be updated after the CMake run. There is no need to have an
|
|
|
|
|
// active code model updater when the next one will be triggered.
|
|
|
|
|
m_cppCodeModelUpdater->cancel();
|
|
|
|
|
|
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))
|
2023-04-21 22:08:45 +02:00
|
|
|
return action == ProjectAction::AddNewFile || action == ProjectAction::AddExistingFile
|
2023-04-27 14:50:13 +02:00
|
|
|
|| action == ProjectAction::AddExistingDirectory || action == ProjectAction::Rename
|
|
|
|
|
|| action == ProjectAction::RemoveFile;
|
2020-04-17 15:30:05 +02:00
|
|
|
|
|
|
|
|
return BuildSystem::supportsAction(context, action, node);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 18:55:16 +02:00
|
|
|
static QString newFilesForFunction(const std::string &cmakeFunction,
|
|
|
|
|
const FilePaths &filePaths,
|
|
|
|
|
const FilePath &projDir)
|
|
|
|
|
{
|
|
|
|
|
auto relativeFilePaths = [projDir](const FilePaths &filePaths) {
|
|
|
|
|
return Utils::transform(filePaths, [projDir](const FilePath &path) {
|
|
|
|
|
return path.canonicalPath().relativePathFrom(projDir).cleanPath().toString();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (cmakeFunction == "qt_add_qml_module" || cmakeFunction == "qt6_add_qml_module") {
|
|
|
|
|
FilePaths sourceFiles;
|
|
|
|
|
FilePaths resourceFiles;
|
|
|
|
|
FilePaths qmlFiles;
|
|
|
|
|
|
|
|
|
|
for (const auto &file : filePaths) {
|
|
|
|
|
const auto mimeType = Utils::mimeTypeForFile(file);
|
|
|
|
|
if (mimeType.matchesName(CppEditor::Constants::CPP_SOURCE_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(CppEditor::Constants::CPP_HEADER_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(CppEditor::Constants::OBJECTIVE_C_SOURCE_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(CppEditor::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE)) {
|
|
|
|
|
sourceFiles << file;
|
|
|
|
|
} else if (mimeType.matchesName(QmlJSTools::Constants::QML_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(QmlJSTools::Constants::QMLUI_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(QmlJSTools::Constants::QMLPROJECT_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(QmlJSTools::Constants::JS_MIMETYPE)
|
|
|
|
|
|| mimeType.matchesName(QmlJSTools::Constants::JSON_MIMETYPE)) {
|
|
|
|
|
qmlFiles << file;
|
|
|
|
|
} else {
|
|
|
|
|
resourceFiles << file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList result;
|
|
|
|
|
if (!sourceFiles.isEmpty())
|
|
|
|
|
result << QString("SOURCES %1").arg(relativeFilePaths(sourceFiles).join(" "));
|
|
|
|
|
if (!resourceFiles.isEmpty())
|
|
|
|
|
result << QString("RESOURCES %1").arg(relativeFilePaths(resourceFiles).join(" "));
|
|
|
|
|
if (!qmlFiles.isEmpty())
|
|
|
|
|
result << QString("QML_FILES %1").arg(relativeFilePaths(qmlFiles).join(" "));
|
|
|
|
|
|
|
|
|
|
return result.join("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return relativeFilePaths(filePaths).join(" ");
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
bool CMakeBuildSystem::addFiles(Node *context, const FilePaths &filePaths, FilePaths *notAdded)
|
2020-04-17 15:30:05 +02:00
|
|
|
{
|
|
|
|
|
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
|
2023-04-13 12:52:39 +02:00
|
|
|
const QString targetName = n->buildKey();
|
|
|
|
|
auto target = Utils::findOrDefault(buildTargets(),
|
|
|
|
|
[targetName](const CMakeBuildTarget &target) {
|
|
|
|
|
return target.title == targetName;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (target.backtrace.isEmpty()) {
|
|
|
|
|
*notAdded = filePaths;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const FilePath targetCMakeFile = target.backtrace.last().path;
|
|
|
|
|
const int targetDefinitionLine = target.backtrace.last().line;
|
|
|
|
|
|
2023-04-26 18:09:24 +02:00
|
|
|
// Have a fresh look at the CMake file, not relying on a cached value
|
2023-09-03 12:31:25 +02:00
|
|
|
Core::DocumentManager::saveModifiedDocumentSilently(
|
|
|
|
|
Core::DocumentModel::documentForFilePath(targetCMakeFile));
|
2023-04-26 18:09:24 +02:00
|
|
|
expected_str<QByteArray> fileContent = targetCMakeFile.fileContents();
|
|
|
|
|
cmListFile cmakeListFile;
|
|
|
|
|
std::string errorString;
|
|
|
|
|
if (fileContent) {
|
|
|
|
|
fileContent = fileContent->replace("\r\n", "\n");
|
|
|
|
|
if (!cmakeListFile.ParseString(fileContent->toStdString(),
|
|
|
|
|
targetCMakeFile.fileName().toStdString(),
|
|
|
|
|
errorString)) {
|
|
|
|
|
*notAdded = filePaths;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-13 12:52:39 +02:00
|
|
|
|
|
|
|
|
auto function = std::find_if(cmakeListFile.Functions.begin(),
|
|
|
|
|
cmakeListFile.Functions.end(),
|
|
|
|
|
[targetDefinitionLine](const auto &func) {
|
|
|
|
|
return func.Line() == targetDefinitionLine;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (function == cmakeListFile.Functions.end()) {
|
|
|
|
|
*notAdded = filePaths;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 18:55:16 +02:00
|
|
|
// Special case: when qt_add_executable and qt_add_qml_module use the same target name
|
|
|
|
|
// then qt_add_qml_module function should be used
|
|
|
|
|
const std::string target_name = targetName.toStdString();
|
|
|
|
|
auto add_qml_module_func
|
|
|
|
|
= std::find_if(cmakeListFile.Functions.begin(),
|
|
|
|
|
cmakeListFile.Functions.end(),
|
|
|
|
|
[target_name](const auto &func) {
|
|
|
|
|
return (func.LowerCaseName() == "qt_add_qml_module"
|
|
|
|
|
|| func.LowerCaseName() == "qt6_add_qml_module")
|
|
|
|
|
&& func.Arguments().front().Value == target_name;
|
|
|
|
|
});
|
|
|
|
|
if (add_qml_module_func != cmakeListFile.Functions.end())
|
|
|
|
|
function = add_qml_module_func;
|
|
|
|
|
|
|
|
|
|
const QString newSourceFiles = newFilesForFunction(function->LowerCaseName(),
|
|
|
|
|
filePaths,
|
|
|
|
|
n->filePath().canonicalPath());
|
2023-04-13 12:52:39 +02:00
|
|
|
|
|
|
|
|
static QSet<std::string> knownFunctions{"add_executable",
|
|
|
|
|
"add_library",
|
|
|
|
|
"qt_add_executable",
|
|
|
|
|
"qt_add_library",
|
|
|
|
|
"qt6_add_executable",
|
2023-04-20 18:55:16 +02:00
|
|
|
"qt6_add_library",
|
|
|
|
|
"qt_add_qml_module",
|
|
|
|
|
"qt6_add_qml_module"};
|
2023-04-13 12:52:39 +02:00
|
|
|
|
|
|
|
|
int line = 0;
|
|
|
|
|
int column = 0;
|
2023-05-23 16:12:02 +02:00
|
|
|
int extraChars = 0;
|
2023-04-13 12:52:39 +02:00
|
|
|
QString snippet;
|
|
|
|
|
|
2023-05-23 16:12:02 +02:00
|
|
|
auto afterFunctionLastArgument =
|
|
|
|
|
[&line, &column, &snippet, &extraChars, newSourceFiles](const auto &f) {
|
|
|
|
|
auto lastArgument = f->Arguments().back();
|
2023-04-13 12:52:39 +02:00
|
|
|
|
2023-05-23 16:12:02 +02:00
|
|
|
line = lastArgument.Line;
|
|
|
|
|
column = lastArgument.Column + static_cast<int>(lastArgument.Value.size()) - 1;
|
|
|
|
|
snippet = QString("\n%1").arg(newSourceFiles);
|
|
|
|
|
|
|
|
|
|
// Take into consideration the quotes
|
|
|
|
|
if (lastArgument.Delim == cmListFileArgument::Quoted)
|
|
|
|
|
extraChars = 2;
|
|
|
|
|
};
|
2023-04-13 12:52:39 +02:00
|
|
|
|
|
|
|
|
if (knownFunctions.contains(function->LowerCaseName())) {
|
|
|
|
|
afterFunctionLastArgument(function);
|
|
|
|
|
} else {
|
|
|
|
|
auto targetSourcesFunc = std::find_if(cmakeListFile.Functions.begin(),
|
|
|
|
|
cmakeListFile.Functions.end(),
|
|
|
|
|
[target_name](const auto &func) {
|
|
|
|
|
return func.LowerCaseName()
|
|
|
|
|
== "target_sources"
|
|
|
|
|
&& func.Arguments().front().Value
|
|
|
|
|
== target_name;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (targetSourcesFunc == cmakeListFile.Functions.end()) {
|
|
|
|
|
line = function->LineEnd() + 1;
|
|
|
|
|
column = 0;
|
|
|
|
|
snippet = QString("\ntarget_sources(%1\n PRIVATE\n %2\n)\n")
|
|
|
|
|
.arg(targetName)
|
|
|
|
|
.arg(newSourceFiles);
|
|
|
|
|
} else {
|
|
|
|
|
afterFunctionLastArgument(targetSourcesFunc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
2023-05-23 16:12:02 +02:00
|
|
|
Core::EditorManager::openEditorAt({targetCMakeFile, line, column + extraChars},
|
2023-04-13 12:52:39 +02:00
|
|
|
Constants::CMAKE_EDITOR_ID,
|
|
|
|
|
Core::EditorManager::DoNotMakeVisible));
|
|
|
|
|
if (!editor) {
|
|
|
|
|
*notAdded = filePaths;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
editor->insert(snippet);
|
|
|
|
|
editor->editorWidget()->autoIndent();
|
2023-04-26 18:09:24 +02:00
|
|
|
if (!Core::DocumentManager::saveDocument(editor->document()))
|
|
|
|
|
return false;
|
2023-04-13 12:52:39 +02:00
|
|
|
|
|
|
|
|
return true;
|
2020-04-17 15:30:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BuildSystem::addFiles(context, filePaths, notAdded);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 20:28:10 +02:00
|
|
|
std::optional<CMakeBuildSystem::ProjectFileArgumentPosition>
|
|
|
|
|
CMakeBuildSystem::projectFileArgumentPosition(const QString &targetName, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
auto target = Utils::findOrDefault(buildTargets(), [targetName](const CMakeBuildTarget &target) {
|
|
|
|
|
return target.title == targetName;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (target.backtrace.isEmpty())
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
|
|
const FilePath targetCMakeFile = target.backtrace.last().path;
|
|
|
|
|
|
|
|
|
|
// Have a fresh look at the CMake file, not relying on a cached value
|
2023-09-03 12:31:25 +02:00
|
|
|
Core::DocumentManager::saveModifiedDocumentSilently(
|
|
|
|
|
Core::DocumentModel::documentForFilePath(targetCMakeFile));
|
2023-04-24 20:28:10 +02:00
|
|
|
expected_str<QByteArray> fileContent = targetCMakeFile.fileContents();
|
|
|
|
|
cmListFile cmakeListFile;
|
|
|
|
|
std::string errorString;
|
|
|
|
|
if (fileContent) {
|
|
|
|
|
fileContent = fileContent->replace("\r\n", "\n");
|
|
|
|
|
if (!cmakeListFile.ParseString(fileContent->toStdString(),
|
|
|
|
|
targetCMakeFile.fileName().toStdString(),
|
|
|
|
|
errorString))
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int targetDefinitionLine = target.backtrace.last().line;
|
|
|
|
|
|
|
|
|
|
auto function = std::find_if(cmakeListFile.Functions.begin(),
|
|
|
|
|
cmakeListFile.Functions.end(),
|
|
|
|
|
[targetDefinitionLine](const auto &func) {
|
|
|
|
|
return func.Line() == targetDefinitionLine;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const std::string target_name = targetName.toStdString();
|
2023-04-26 18:29:27 +02:00
|
|
|
auto targetSourcesFunc = std::find_if(cmakeListFile.Functions.begin(),
|
|
|
|
|
cmakeListFile.Functions.end(),
|
|
|
|
|
[target_name](const auto &func) {
|
|
|
|
|
return func.LowerCaseName() == "target_sources"
|
|
|
|
|
&& func.Arguments().size() > 1
|
|
|
|
|
&& func.Arguments().front().Value
|
|
|
|
|
== target_name;
|
|
|
|
|
});
|
|
|
|
|
auto addQmlModuleFunc = std::find_if(cmakeListFile.Functions.begin(),
|
|
|
|
|
cmakeListFile.Functions.end(),
|
|
|
|
|
[target_name](const auto &func) {
|
|
|
|
|
return (func.LowerCaseName() == "qt_add_qml_module"
|
|
|
|
|
|| func.LowerCaseName() == "qt6_add_qml_module")
|
|
|
|
|
&& func.Arguments().size() > 1
|
|
|
|
|
&& func.Arguments().front().Value
|
|
|
|
|
== target_name;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const auto &func : {function, targetSourcesFunc, addQmlModuleFunc}) {
|
2023-04-24 20:28:10 +02:00
|
|
|
if (func == cmakeListFile.Functions.end())
|
|
|
|
|
continue;
|
2023-05-23 14:55:52 +02:00
|
|
|
auto filePathArgument = Utils::findOrDefault(func->Arguments(),
|
|
|
|
|
[file_name = fileName.toStdString()](
|
|
|
|
|
const auto &arg) {
|
|
|
|
|
return arg.Value == file_name;
|
|
|
|
|
});
|
2023-04-24 20:28:10 +02:00
|
|
|
|
|
|
|
|
if (!filePathArgument.Value.empty()) {
|
|
|
|
|
return ProjectFileArgumentPosition{filePathArgument, targetCMakeFile, fileName};
|
|
|
|
|
} else {
|
2023-04-26 19:29:37 +02:00
|
|
|
// Check if the filename is part of globbing variable result
|
2023-04-24 20:28:10 +02:00
|
|
|
const auto globFunctions = std::get<0>(
|
|
|
|
|
Utils::partition(cmakeListFile.Functions, [](const auto &f) {
|
|
|
|
|
return f.LowerCaseName() == "file" && f.Arguments().size() > 2
|
|
|
|
|
&& (f.Arguments().front().Value == "GLOB"
|
|
|
|
|
|| f.Arguments().front().Value == "GLOB_RECURSE");
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const auto globVariables = Utils::transform<QSet>(globFunctions, [](const auto &func) {
|
|
|
|
|
return std::string("${") + func.Arguments()[1].Value + "}";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const auto haveGlobbing = Utils::anyOf(func->Arguments(),
|
|
|
|
|
[globVariables](const auto &arg) {
|
2023-05-23 14:55:52 +02:00
|
|
|
return globVariables.contains(arg.Value);
|
2023-04-24 20:28:10 +02:00
|
|
|
});
|
|
|
|
|
|
2023-04-26 19:29:37 +02:00
|
|
|
if (haveGlobbing) {
|
2023-04-24 20:28:10 +02:00
|
|
|
return ProjectFileArgumentPosition{filePathArgument,
|
|
|
|
|
targetCMakeFile,
|
|
|
|
|
fileName,
|
|
|
|
|
true};
|
2023-04-26 19:29:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the filename is part of a variable set by the user
|
|
|
|
|
const auto setFunctions = std::get<0>(
|
|
|
|
|
Utils::partition(cmakeListFile.Functions, [](const auto &f) {
|
|
|
|
|
return f.LowerCaseName() == "set" && f.Arguments().size() > 1;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
for (const auto &arg : func->Arguments()) {
|
|
|
|
|
auto matchedFunctions = Utils::filtered(setFunctions, [arg](const auto &f) {
|
|
|
|
|
return arg.Value == std::string("${") + f.Arguments()[0].Value + "}";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
for (const auto &f : matchedFunctions) {
|
2023-05-23 14:55:52 +02:00
|
|
|
filePathArgument = Utils::findOrDefault(f.Arguments(),
|
|
|
|
|
[file_name = fileName.toStdString()](
|
|
|
|
|
const auto &arg) {
|
|
|
|
|
return arg.Value == file_name;
|
|
|
|
|
});
|
2023-04-26 19:29:37 +02:00
|
|
|
|
|
|
|
|
if (!filePathArgument.Value.empty()) {
|
|
|
|
|
return ProjectFileArgumentPosition{filePathArgument,
|
|
|
|
|
targetCMakeFile,
|
|
|
|
|
fileName};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-24 20:28:10 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemovedFilesFromProject CMakeBuildSystem::removeFiles(Node *context,
|
|
|
|
|
const FilePaths &filePaths,
|
|
|
|
|
FilePaths *notRemoved)
|
|
|
|
|
{
|
|
|
|
|
FilePaths badFiles;
|
|
|
|
|
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
|
|
|
|
|
const FilePath projDir = n->filePath().canonicalPath();
|
|
|
|
|
const QString targetName = n->buildKey();
|
|
|
|
|
|
|
|
|
|
for (const auto &file : filePaths) {
|
|
|
|
|
const QString fileName
|
|
|
|
|
= file.canonicalPath().relativePathFrom(projDir).cleanPath().toString();
|
|
|
|
|
|
|
|
|
|
auto filePos = projectFileArgumentPosition(targetName, fileName);
|
|
|
|
|
if (filePos) {
|
|
|
|
|
if (!filePos.value().cmakeFile.exists()) {
|
|
|
|
|
badFiles << file;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
|
|
|
|
Core::EditorManager::openEditorAt({filePos.value().cmakeFile,
|
|
|
|
|
static_cast<int>(filePos.value().argumentPosition.Line),
|
|
|
|
|
static_cast<int>(filePos.value().argumentPosition.Column
|
|
|
|
|
- 1)},
|
|
|
|
|
Constants::CMAKE_EDITOR_ID,
|
|
|
|
|
Core::EditorManager::DoNotMakeVisible));
|
|
|
|
|
if (!editor) {
|
|
|
|
|
badFiles << file;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 16:12:02 +02:00
|
|
|
// If quotes were used for the source file, remove the quotes too
|
|
|
|
|
int extraChars = 0;
|
|
|
|
|
if (filePos->argumentPosition.Delim == cmListFileArgument::Quoted)
|
|
|
|
|
extraChars = 2;
|
|
|
|
|
|
2023-04-24 20:28:10 +02:00
|
|
|
if (!filePos.value().fromGlobbing)
|
2023-05-23 16:12:02 +02:00
|
|
|
editor->replace(filePos.value().relativeFileName.length() + extraChars, "");
|
2023-04-24 20:28:10 +02:00
|
|
|
|
|
|
|
|
editor->editorWidget()->autoIndent();
|
|
|
|
|
if (!Core::DocumentManager::saveDocument(editor->document())) {
|
|
|
|
|
badFiles << file;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
badFiles << file;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notRemoved && !badFiles.isEmpty())
|
|
|
|
|
*notRemoved = badFiles;
|
|
|
|
|
|
|
|
|
|
return badFiles.isEmpty() ? RemovedFilesFromProject::Ok : RemovedFilesFromProject::Error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RemovedFilesFromProject::Error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-21 22:08:45 +02:00
|
|
|
bool CMakeBuildSystem::canRenameFile(Node *context,
|
|
|
|
|
const FilePath &oldFilePath,
|
|
|
|
|
const FilePath &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
// "canRenameFile" will cause an actual rename after the function call.
|
|
|
|
|
// This will make the a sequence like
|
|
|
|
|
// canonicalPath().relativePathFrom(projDir).cleanPath().toString()
|
|
|
|
|
// to fail if the file doesn't exist on disk
|
|
|
|
|
// therefore cache the results for the subsequent "renameFile" call
|
|
|
|
|
// where oldFilePath has already been renamed as newFilePath.
|
|
|
|
|
|
|
|
|
|
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
|
|
|
|
|
const FilePath projDir = n->filePath().canonicalPath();
|
|
|
|
|
const QString oldRelPathName
|
|
|
|
|
= oldFilePath.canonicalPath().relativePathFrom(projDir).cleanPath().toString();
|
|
|
|
|
|
|
|
|
|
const QString targetName = n->buildKey();
|
|
|
|
|
|
2023-04-24 20:28:10 +02:00
|
|
|
const QString key
|
|
|
|
|
= QStringList{projDir.path(), targetName, oldFilePath.path(), newFilePath.path()}
|
|
|
|
|
.join(";");
|
2023-04-21 22:08:45 +02:00
|
|
|
|
2023-04-24 20:28:10 +02:00
|
|
|
auto filePos = projectFileArgumentPosition(targetName, oldRelPathName);
|
|
|
|
|
if (!filePos)
|
|
|
|
|
return false;
|
2023-04-21 22:08:45 +02:00
|
|
|
|
2023-04-24 20:28:10 +02:00
|
|
|
m_filesToBeRenamed.insert(key, filePos.value());
|
|
|
|
|
return true;
|
2023-04-21 22:08:45 +02:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildSystem::renameFile(Node *context,
|
|
|
|
|
const FilePath &oldFilePath,
|
|
|
|
|
const FilePath &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
if (auto n = dynamic_cast<CMakeTargetNode *>(context)) {
|
|
|
|
|
const FilePath projDir = n->filePath().canonicalPath();
|
|
|
|
|
const QString newRelPathName
|
|
|
|
|
= newFilePath.canonicalPath().relativePathFrom(projDir).cleanPath().toString();
|
|
|
|
|
|
|
|
|
|
const QString targetName = n->buildKey();
|
|
|
|
|
const QString key
|
|
|
|
|
= QStringList{projDir.path(), targetName, oldFilePath.path(), newFilePath.path()}.join(
|
|
|
|
|
";");
|
|
|
|
|
|
|
|
|
|
auto fileToRename = m_filesToBeRenamed.take(key);
|
|
|
|
|
if (!fileToRename.cmakeFile.exists())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
BaseTextEditor *editor = qobject_cast<BaseTextEditor *>(
|
|
|
|
|
Core::EditorManager::openEditorAt({fileToRename.cmakeFile,
|
|
|
|
|
static_cast<int>(fileToRename.argumentPosition.Line),
|
|
|
|
|
static_cast<int>(fileToRename.argumentPosition.Column
|
|
|
|
|
- 1)},
|
|
|
|
|
Constants::CMAKE_EDITOR_ID,
|
|
|
|
|
Core::EditorManager::DoNotMakeVisible));
|
|
|
|
|
if (!editor)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-05-23 16:12:02 +02:00
|
|
|
// If quotes were used for the source file, skip the starting quote
|
|
|
|
|
if (fileToRename.argumentPosition.Delim == cmListFileArgument::Quoted)
|
|
|
|
|
editor->setCursorPosition(editor->position() + 1);
|
|
|
|
|
|
2023-04-21 22:08:45 +02:00
|
|
|
if (!fileToRename.fromGlobbing)
|
2023-04-24 20:28:10 +02:00
|
|
|
editor->replace(fileToRename.relativeFileName.length(), newRelPathName);
|
2023-04-21 22:08:45 +02:00
|
|
|
|
|
|
|
|
editor->editorWidget()->autoIndent();
|
|
|
|
|
if (!Core::DocumentManager::saveDocument(editor->document()))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
FilePaths CMakeBuildSystem::filesGeneratedFrom(const FilePath &sourceFile) const
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
|
FilePath project = projectDirectory();
|
2021-09-13 14:58:18 +02:00
|
|
|
FilePath baseDirectory = sourceFile.parentDir();
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
|
while (baseDirectory.isChildOf(project)) {
|
|
|
|
|
const FilePath cmakeListsTxt = baseDirectory.pathAppended("CMakeLists.txt");
|
|
|
|
|
if (cmakeListsTxt.exists())
|
|
|
|
|
break;
|
|
|
|
|
baseDirectory = baseDirectory.parentDir();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 14:38:29 +02:00
|
|
|
const FilePath relativePath = baseDirectory.relativePathFrom(project);
|
2022-04-25 13:40:05 +02:00
|
|
|
FilePath generatedFilePath = buildConfiguration()->buildDirectory().resolvePath(relativePath);
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2021-09-13 14:58:18 +02:00
|
|
|
if (sourceFile.suffix() == "ui") {
|
2023-08-08 19:21:46 +02:00
|
|
|
const QString generatedFileName = "ui_" + sourceFile.completeBaseName() + ".h";
|
2023-08-04 16:46:42 +02:00
|
|
|
|
2023-08-08 19:21:46 +02:00
|
|
|
auto targetNode = this->project()->nodeForFilePath(sourceFile);
|
|
|
|
|
while (!dynamic_cast<const CMakeTargetNode *>(targetNode))
|
|
|
|
|
targetNode = targetNode->parentFolderNode();
|
|
|
|
|
|
|
|
|
|
FilePaths generatedFilePaths;
|
|
|
|
|
if (targetNode) {
|
|
|
|
|
const QString autogenSignature = targetNode->buildKey() + "_autogen/include";
|
|
|
|
|
|
|
|
|
|
// If AUTOUIC reports the generated header file name, use that path
|
|
|
|
|
generatedFilePaths = this->project()->files(
|
|
|
|
|
[autogenSignature, generatedFileName](const Node *n) {
|
|
|
|
|
const FilePath filePath = n->filePath();
|
|
|
|
|
if (!filePath.contains(autogenSignature))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return Project::GeneratedFiles(n) && filePath.endsWith(generatedFileName);
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-08-04 16:46:42 +02:00
|
|
|
|
|
|
|
|
if (generatedFilePaths.empty())
|
2023-08-08 19:21:46 +02:00
|
|
|
generatedFilePaths = {generatedFilePath.pathAppended(generatedFileName)};
|
2023-08-04 16:46:42 +02:00
|
|
|
|
|
|
|
|
return generatedFilePaths;
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
2021-09-13 14:58:18 +02:00
|
|
|
if (sourceFile.suffix() == "scxml") {
|
|
|
|
|
generatedFilePath = generatedFilePath.pathAppended(sourceFile.completeBaseName());
|
|
|
|
|
return {generatedFilePath.stringAppended(".h"), generatedFilePath.stringAppended(".cpp")};
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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";
|
|
|
|
|
}
|
|
|
|
|
return result.trimmed();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-05 15:28:09 +02:00
|
|
|
void CMakeBuildSystem::reparse(int reparseParameters)
|
|
|
|
|
{
|
|
|
|
|
setParametersAndRequestParse(BuildDirParameters(this), reparseParameters);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-24 10:29:43 +02:00
|
|
|
void CMakeBuildSystem::setParametersAndRequestParse(const BuildDirParameters ¶meters,
|
|
|
|
|
const int reparseParameters)
|
|
|
|
|
{
|
2021-09-21 22:22:37 +02:00
|
|
|
project()->clearIssues();
|
|
|
|
|
|
2022-04-25 13:40:05 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << buildConfiguration()->displayName()
|
2020-06-15 12:31:44 +02:00
|
|
|
<< "setting parameters and requesting reparse"
|
2020-04-02 14:49:05 +02:00
|
|
|
<< reparseParametersString(reparseParameters);
|
2020-06-15 12:31:44 +02:00
|
|
|
|
2022-04-25 13:40:05 +02:00
|
|
|
if (!buildConfiguration()->isActive()) {
|
2020-06-15 12:31:44 +02:00
|
|
|
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!
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-28 16:08:09 +02:00
|
|
|
const CMakeTool *tool = parameters.cmakeTool();
|
|
|
|
|
if (!tool || !tool->isValid()) {
|
2020-04-24 10:29:43 +02:00
|
|
|
TaskHub::addTask(
|
|
|
|
|
BuildSystemTask(Task::Error,
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("The kit needs to define a CMake tool to parse this project.")));
|
2020-04-24 10:29:43 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2022-06-28 16:08:09 +02:00
|
|
|
if (!tool->hasFileApi()) {
|
|
|
|
|
TaskHub::addTask(
|
|
|
|
|
BuildSystemTask(Task::Error,
|
|
|
|
|
CMakeKitAspect::msgUnsupportedVersion(tool->version().fullVersion)));
|
2020-11-19 09:45:55 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
QTC_ASSERT(parameters.isValid(), return );
|
|
|
|
|
|
|
|
|
|
m_parameters = parameters;
|
2022-05-20 14:11:52 +02:00
|
|
|
ensureBuildDirectory(parameters);
|
2020-04-24 10:29:43 +02:00
|
|
|
updateReparseParameters(reparseParameters);
|
|
|
|
|
|
|
|
|
|
m_reader.setParameters(m_parameters);
|
|
|
|
|
|
|
|
|
|
if (reparseParameters & REPARSE_URGENT) {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "calling requestReparse";
|
|
|
|
|
requestParse();
|
|
|
|
|
} else {
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "calling requestDelayedReparse";
|
|
|
|
|
requestDelayedParse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 21:42:29 +01:00
|
|
|
bool CMakeBuildSystem::mustApplyConfigurationChangesArguments(const BuildDirParameters ¶meters) const
|
2020-04-24 10:29:43 +02:00
|
|
|
{
|
2021-12-28 21:42:29 +01:00
|
|
|
if (parameters.configurationChangesArguments.isEmpty())
|
2020-04-02 14:49:05 +02:00
|
|
|
return false;
|
2020-04-24 10:29:43 +02:00
|
|
|
|
2022-07-22 13:27:19 +02:00
|
|
|
int answer = QMessageBox::question(Core::ICore::dialogParent(),
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("Apply configuration changes?"),
|
|
|
|
|
"<p>" + Tr::tr("Run CMake with configuration changes?")
|
2022-07-22 13:27:19 +02:00
|
|
|
+ "</p><pre>"
|
|
|
|
|
+ parameters.configurationChangesArguments.join("\n")
|
|
|
|
|
+ "</pre>",
|
|
|
|
|
QMessageBox::Apply | QMessageBox::Discard,
|
|
|
|
|
QMessageBox::Apply);
|
2020-04-02 14:49:05 +02:00
|
|
|
return answer == QMessageBox::Apply;
|
2020-04-24 10:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
void CMakeBuildSystem::runCMake()
|
|
|
|
|
{
|
2019-12-06 11:29:36 +01:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due \"Run CMake\" command";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(REPARSE_FORCE_CMAKE_RUN | REPARSE_URGENT);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::runCMakeAndScanProjectTree()
|
|
|
|
|
{
|
2019-12-06 11:29:36 +01:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to \"Rescan Project\" command";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(REPARSE_FORCE_CMAKE_RUN | REPARSE_URGENT);
|
2020-04-02 14:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::runCMakeWithExtraArguments()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to \"Rescan Project\" command";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(REPARSE_FORCE_CMAKE_RUN | REPARSE_FORCE_EXTRA_CONFIGURATION | REPARSE_URGENT);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-22 15:18:00 +01:00
|
|
|
void CMakeBuildSystem::stopCMakeRun()
|
|
|
|
|
{
|
2022-04-25 14:20:12 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << buildConfiguration()->displayName()
|
2021-12-28 21:42:29 +01:00
|
|
|
<< "stopping CMake's run";
|
2021-12-22 15:18:00 +01:00
|
|
|
m_reader.stopCMakeRun();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
bool CMakeBuildSystem::persistCMakeState()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2022-04-25 14:20:12 +02:00
|
|
|
BuildDirParameters parameters(this);
|
2020-04-02 14:49:05 +02:00
|
|
|
QTC_ASSERT(parameters.isValid(), return false);
|
|
|
|
|
|
2021-06-09 15:08:13 +02:00
|
|
|
const bool hadBuildDirectory = parameters.buildDirectory.exists();
|
2022-05-20 14:11:52 +02:00
|
|
|
ensureBuildDirectory(parameters);
|
2020-04-02 14:49:05 +02:00
|
|
|
|
|
|
|
|
int reparseFlags = REPARSE_DEFAULT;
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Checking whether build system needs to be persisted:"
|
|
|
|
|
<< "buildDir:" << parameters.buildDirectory
|
2021-12-28 21:42:29 +01:00
|
|
|
<< "Has extraargs:" << !parameters.configurationChangesArguments.isEmpty();
|
2020-04-02 14:49:05 +02:00
|
|
|
|
2022-05-20 14:11:52 +02:00
|
|
|
if (mustApplyConfigurationChangesArguments(parameters)) {
|
2020-04-02 14:49:05 +02:00
|
|
|
reparseFlags = REPARSE_FORCE_EXTRA_CONFIGURATION;
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << " -> must run CMake with extra arguments.";
|
|
|
|
|
}
|
2021-06-09 15:08:13 +02:00
|
|
|
if (!hadBuildDirectory) {
|
2020-04-02 14:49:05 +02:00
|
|
|
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
|
|
|
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();
|
|
|
|
|
|
2021-07-01 08:59:32 +02:00
|
|
|
const FilePath pathsToDelete[] = {
|
2021-06-09 15:08:13 +02:00
|
|
|
m_parameters.buildDirectory / "CMakeCache.txt",
|
|
|
|
|
m_parameters.buildDirectory / "CMakeCache.txt.prev",
|
|
|
|
|
m_parameters.buildDirectory / "CMakeFiles",
|
|
|
|
|
m_parameters.buildDirectory / ".cmake/api/v1/reply",
|
2023-02-07 18:15:58 +01:00
|
|
|
m_parameters.buildDirectory / ".cmake/api/v1/reply.prev",
|
|
|
|
|
m_parameters.buildDirectory / Constants::PACKAGE_MANAGER_DIR
|
2021-03-23 10:33:57 +01:00
|
|
|
};
|
|
|
|
|
|
2021-07-01 08:59:32 +02:00
|
|
|
for (const FilePath &path : pathsToDelete)
|
|
|
|
|
path.removeRecursively();
|
2021-12-28 21:42:29 +01:00
|
|
|
|
|
|
|
|
emit configurationCleared();
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2021-09-21 22:22:37 +02:00
|
|
|
void CMakeBuildSystem::combineScanAndParse(bool restoredFromBackup)
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2022-04-25 13:40:05 +02:00
|
|
|
if (buildConfiguration()->isActive()) {
|
2021-09-27 17:26:40 +02:00
|
|
|
if (m_waitingForParse)
|
2019-08-06 12:41:46 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_combinedScanAndParseResult) {
|
2019-10-25 09:55:32 +02:00
|
|
|
updateProjectData();
|
|
|
|
|
m_currentGuard.markAsSuccess();
|
2021-09-21 22:22:37 +02:00
|
|
|
|
|
|
|
|
if (restoredFromBackup)
|
|
|
|
|
project()->addIssue(
|
2022-03-29 20:09:02 +02:00
|
|
|
CMakeProject::IssueType::Warning,
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("<b>CMake configuration failed<b>"
|
2023-02-14 16:14:08 +01:00
|
|
|
"<p>The backup of the previous configuration has been restored.</p>"
|
|
|
|
|
"<p>Issues and \"Projects > Build\" settings "
|
|
|
|
|
"show more information about the failure.</p>"));
|
2021-09-27 17:26:40 +02:00
|
|
|
|
|
|
|
|
m_reader.resetData();
|
|
|
|
|
|
|
|
|
|
m_currentGuard = {};
|
|
|
|
|
m_testNames.clear();
|
|
|
|
|
|
|
|
|
|
emitBuildSystemUpdated();
|
|
|
|
|
|
|
|
|
|
runCTest();
|
2020-10-26 15:36:59 +01:00
|
|
|
} else {
|
|
|
|
|
updateFallbackProjectData();
|
2021-09-21 22:22:37 +02:00
|
|
|
|
2023-02-14 16:14:08 +01:00
|
|
|
project()->addIssue(CMakeProject::IssueType::Warning,
|
|
|
|
|
Tr::tr("<b>Failed to load project<b>"
|
|
|
|
|
"<p>Issues and \"Projects > Build\" settings "
|
|
|
|
|
"show more information about the failure.</p>"));
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::checkAndReportError(QString &errorMessage)
|
|
|
|
|
{
|
|
|
|
|
if (!errorMessage.isEmpty()) {
|
2022-04-25 13:40:05 +02:00
|
|
|
setError(errorMessage);
|
2019-10-25 09:55:32 +02:00
|
|
|
errorMessage.clear();
|
|
|
|
|
}
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-08 13:37:07 +02:00
|
|
|
static QSet<FilePath> projectFilesToWatch(const QSet<CMakeFileInfo> &cmakeFiles)
|
|
|
|
|
{
|
|
|
|
|
return Utils::transform(Utils::filtered(cmakeFiles,
|
|
|
|
|
[](const CMakeFileInfo &info) {
|
|
|
|
|
return !info.isGenerated;
|
|
|
|
|
}),
|
|
|
|
|
[](const CMakeFileInfo &info) { return info.path; });
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2023-05-08 13:37:07 +02:00
|
|
|
buildConfiguration()->project()->setExtraProjectFiles(projectFilesToWatch(m_cmakeFiles));
|
2019-08-15 12:22:09 +02:00
|
|
|
|
2022-05-02 18:02:37 +02:00
|
|
|
CMakeConfig patchedConfig = configurationFromCMake();
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
QSet<QString> res;
|
|
|
|
|
QStringList apps;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const auto &target : std::as_const(m_buildTargets)) {
|
2021-03-26 16:54:40 +01:00
|
|
|
if (target.targetType == DynamicLibraryType) {
|
2019-08-06 12:41:46 +02:00
|
|
|
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
|
|
|
{
|
2021-09-27 17:26:40 +02:00
|
|
|
auto newRoot = m_reader.rootProjectNode();
|
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
|
|
|
|
2021-06-10 10:31:53 +02:00
|
|
|
if (QTC_GUARD(p->rootProjectNode())) {
|
2020-09-28 20:29:29 +03:00
|
|
|
const QString nodeName = p->rootProjectNode()->displayName();
|
|
|
|
|
p->setDisplayName(nodeName);
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2021-06-10 10:31:53 +02:00
|
|
|
// set config on target nodes
|
|
|
|
|
const QSet<QString> buildKeys = Utils::transform<QSet>(m_buildTargets,
|
|
|
|
|
&CMakeBuildTarget::title);
|
|
|
|
|
p->rootProjectNode()->forEachProjectNode(
|
|
|
|
|
[patchedConfig, buildKeys](const ProjectNode *node) {
|
|
|
|
|
if (buildKeys.contains(node->buildKey())) {
|
|
|
|
|
auto targetNode = const_cast<CMakeTargetNode *>(
|
|
|
|
|
dynamic_cast<const CMakeTargetNode *>(node));
|
|
|
|
|
if (QTC_GUARD(targetNode))
|
|
|
|
|
targetNode->setConfig(patchedConfig);
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
qDeleteAll(m_extraCompilers);
|
2019-10-25 09:55:32 +02:00
|
|
|
m_extraCompilers = findExtraCompilers();
|
2021-06-29 15:26:23 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Extra compilers created.";
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
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 );
|
|
|
|
|
|
2021-02-26 14:33:34 +01:00
|
|
|
QString errorMessage;
|
|
|
|
|
RawProjectParts rpps = m_reader.createRawProjectParts(errorMessage);
|
|
|
|
|
if (!errorMessage.isEmpty())
|
2022-04-25 13:40:05 +02:00
|
|
|
setError(errorMessage);
|
2021-02-26 14:33:34 +01:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Raw project parts created." << errorMessage;
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2022-10-11 16:22:15 +02:00
|
|
|
for (RawProjectPart &rpp : rpps) {
|
|
|
|
|
rpp.setQtVersion(
|
|
|
|
|
kitInfo.projectPartQtVersion); // TODO: Check if project actually uses Qt.
|
2022-11-25 14:06:47 +01:00
|
|
|
const FilePath includeFileBaseDir = buildConfiguration()->buildDirectory();
|
2022-10-11 16:22:15 +02:00
|
|
|
QStringList cxxFlags = rpp.flagsForCxx.commandLineFlags;
|
|
|
|
|
QStringList cFlags = rpp.flagsForC.commandLineFlags;
|
|
|
|
|
addTargetFlagForIos(cxxFlags, cFlags, this, [this] {
|
|
|
|
|
return m_configurationFromCMake.stringValueOf("CMAKE_OSX_DEPLOYMENT_TARGET");
|
|
|
|
|
});
|
|
|
|
|
if (kitInfo.cxxToolChain)
|
|
|
|
|
rpp.setFlagsForCxx({kitInfo.cxxToolChain, cxxFlags, includeFileBaseDir});
|
|
|
|
|
if (kitInfo.cToolChain)
|
|
|
|
|
rpp.setFlagsForC({kitInfo.cToolChain, cFlags, includeFileBaseDir});
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
2022-10-11 16:22:15 +02:00
|
|
|
|
|
|
|
|
m_cppCodeModelUpdater->update({p, kitInfo, buildConfiguration()->environment(), rpps},
|
|
|
|
|
m_extraCompilers);
|
|
|
|
|
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
2021-02-26 14:33:34 +01:00
|
|
|
const bool mergedHeaderPathsAndQmlImportPaths = kit()->value(
|
|
|
|
|
QtSupport::KitHasMergedHeaderPathsWithQmlImportPaths::id(), false).toBool();
|
|
|
|
|
QStringList extraHeaderPaths;
|
2021-03-17 11:38:33 +01:00
|
|
|
QList<QByteArray> moduleMappings;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const RawProjectPart &rpp : std::as_const(rpps)) {
|
2022-04-25 13:40:05 +02:00
|
|
|
FilePath moduleMapFile = buildConfiguration()->buildDirectory()
|
2021-08-13 11:41:52 +02:00
|
|
|
.pathAppended("qml_module_mappings/" + rpp.buildSystemTarget);
|
2023-02-07 18:32:49 +01:00
|
|
|
if (expected_str<QByteArray> content = moduleMapFile.fileContents()) {
|
|
|
|
|
auto lines = content->split('\n');
|
|
|
|
|
for (const QByteArray &line : lines) {
|
|
|
|
|
if (!line.isEmpty())
|
|
|
|
|
moduleMappings.append(line.simplified());
|
2021-03-17 11:38:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-26 14:33:34 +01:00
|
|
|
if (mergedHeaderPathsAndQmlImportPaths) {
|
|
|
|
|
for (const auto &headerPath : rpp.headerPaths) {
|
2022-07-13 10:42:49 +03:00
|
|
|
if (headerPath.type == HeaderPathType::User || headerPath.type == HeaderPathType::System)
|
2021-02-26 14:33:34 +01:00
|
|
|
extraHeaderPaths.append(headerPath.path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-17 11:38:33 +01:00
|
|
|
updateQmlJSCodeModel(extraHeaderPaths, moduleMappings);
|
2019-08-06 12:41:46 +02:00
|
|
|
}
|
2021-04-15 22:48:23 +02:00
|
|
|
updateInitialCMakeExpandableVars();
|
|
|
|
|
|
2022-04-25 13:40:05 +02:00
|
|
|
emit buildConfiguration()->buildTypeChanged();
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "All CMake project data up to date.";
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 17:26:40 +02:00
|
|
|
void CMakeBuildSystem::handleTreeScanningFinished()
|
2020-10-26 15:36:59 +01:00
|
|
|
{
|
2021-09-27 17:26:40 +02:00
|
|
|
TreeScanner::Result result = m_treeScanner.release();
|
|
|
|
|
m_allFiles = result.folderNode;
|
|
|
|
|
qDeleteAll(result.allFiles);
|
2020-10-26 15:36:59 +01:00
|
|
|
|
2021-09-27 17:26:40 +02:00
|
|
|
updateFileSystemNodes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::updateFileSystemNodes()
|
|
|
|
|
{
|
|
|
|
|
auto newRoot = std::make_unique<CMakeProjectNode>(m_parameters.sourceDirectory);
|
|
|
|
|
newRoot->setDisplayName(m_parameters.sourceDirectory.fileName());
|
2020-10-26 15:36:59 +01:00
|
|
|
|
2021-09-27 17:26:40 +02:00
|
|
|
if (!m_reader.topCmakeFile().isEmpty()) {
|
|
|
|
|
auto node = std::make_unique<FileNode>(m_reader.topCmakeFile(), FileType::Project);
|
|
|
|
|
node->setIsGenerated(false);
|
|
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<FileNode>> fileNodes;
|
|
|
|
|
fileNodes.emplace_back(std::move(node));
|
|
|
|
|
|
|
|
|
|
addCMakeLists(newRoot.get(), std::move(fileNodes));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 13:14:14 +02:00
|
|
|
if (m_allFiles)
|
|
|
|
|
addFileSystemNodes(newRoot.get(), m_allFiles);
|
2020-10-26 15:36:59 +01:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
|
|
|
|
|
2021-09-27 17:26:40 +02:00
|
|
|
m_reader.resetData();
|
|
|
|
|
|
|
|
|
|
m_currentGuard = {};
|
|
|
|
|
emitBuildSystemUpdated();
|
|
|
|
|
|
2020-10-26 15:36:59 +01:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "All fallback CMake project data up to date.";
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 17:26:40 +02:00
|
|
|
void CMakeBuildSystem::updateFallbackProjectData()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Updating fallback CMake project data";
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Starting TreeScanner";
|
|
|
|
|
QTC_CHECK(m_treeScanner.isFinished());
|
|
|
|
|
if (m_treeScanner.asyncScanForFiles(projectDirectory()))
|
|
|
|
|
Core::ProgressManager::addTask(m_treeScanner.future(),
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("Scan \"%1\" project tree")
|
2021-09-27 17:26:40 +02:00
|
|
|
.arg(project()->displayName()),
|
|
|
|
|
"CMake.Scan.Tree");
|
|
|
|
|
}
|
|
|
|
|
|
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()) {
|
2022-05-02 18:02:37 +02:00
|
|
|
const CMakeConfig changes = configurationChanges();
|
2021-02-04 16:22:40 +01:00
|
|
|
for (const auto &ci : changes) {
|
2021-12-28 21:42:29 +01:00
|
|
|
if (ci.isInitial)
|
|
|
|
|
continue;
|
2021-02-04 16:22:40 +01:00
|
|
|
const bool haveConfigItem = Utils::contains(cmakeConfig, [ci](const CMakeConfigItem& i) {
|
|
|
|
|
return i.key == ci.key;
|
|
|
|
|
});
|
|
|
|
|
if (!haveConfigItem)
|
|
|
|
|
cmakeConfig.append(ci);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-02 18:02:37 +02:00
|
|
|
setConfigurationFromCMake(cmakeConfig);
|
2021-02-04 16:22:40 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-21 22:22:37 +02:00
|
|
|
void CMakeBuildSystem::handleParsingSucceeded(bool restoredFromBackup)
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
2022-04-25 13:40:05 +02:00
|
|
|
if (!buildConfiguration()->isActive()) {
|
2020-04-24 10:29:43 +02:00
|
|
|
stopParsingAndClearState();
|
2019-10-25 09:55:32 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 13:40:05 +02:00
|
|
|
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;
|
2021-06-09 15:08:13 +02:00
|
|
|
result.workingDirectory = m_parameters.buildDirectory;
|
2020-06-03 11:27:37 +02:00
|
|
|
result.sourceDirectory = m_parameters.sourceDirectory;
|
|
|
|
|
return result;
|
|
|
|
|
});
|
|
|
|
|
m_buildTargets += m_reader.takeBuildTargets(errorMessage);
|
2023-04-13 12:52:39 +02:00
|
|
|
m_cmakeFiles = m_reader.takeCMakeFileInfos(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
|
|
|
}
|
|
|
|
|
|
2023-01-30 09:43:38 +02:00
|
|
|
if (const CMakeTool *tool = m_parameters.cmakeTool())
|
|
|
|
|
m_ctestPath = tool->cmakeExecutable().withNewPath(m_reader.ctestPath());
|
2020-09-28 15:10:04 +02:00
|
|
|
|
2019-10-25 09:55:32 +02:00
|
|
|
setApplicationTargets(appTargets());
|
2023-03-31 16:52:22 +02:00
|
|
|
|
|
|
|
|
// Note: This is practically always wrong and resulting in an empty view.
|
|
|
|
|
// Setting the real data is triggered from a successful run of a
|
|
|
|
|
// MakeInstallStep.
|
|
|
|
|
setDeploymentData(deploymentDataFromFile());
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2020-04-23 18:29:27 +02:00
|
|
|
QTC_ASSERT(m_waitingForParse, return );
|
|
|
|
|
m_waitingForParse = false;
|
|
|
|
|
|
2021-09-21 22:22:37 +02:00
|
|
|
combineScanAndParse(restoredFromBackup);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::handleParsingFailed(const QString &msg)
|
|
|
|
|
{
|
2022-04-25 13:40:05 +02:00
|
|
|
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;
|
|
|
|
|
|
2021-09-21 22:22:37 +02:00
|
|
|
combineScanAndParse(false);
|
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
|
|
|
|
|
|
|
|
|
|
// Became active/inactive:
|
2022-12-07 15:37:42 +01: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";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(CMakeBuildSystem::REPARSE_DEFAULT);
|
2020-04-20 17:33:36 +02:00
|
|
|
});
|
2022-12-07 15:37:42 +01:00
|
|
|
connect(project(), &Project::activeTargetChanged, this, [this] {
|
2020-08-11 16:36:24 +02:00
|
|
|
// Build configuration has changed:
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to active target changed";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(CMakeBuildSystem::REPARSE_DEFAULT);
|
2020-08-11 16:36:24 +02:00
|
|
|
});
|
2020-04-20 17:33:36 +02:00
|
|
|
|
|
|
|
|
// BuildConfiguration changed:
|
2022-04-25 14:20:12 +02:00
|
|
|
connect(buildConfiguration(), &BuildConfiguration::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";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
2020-04-20 17:33:36 +02:00
|
|
|
});
|
2022-04-25 14:20:12 +02:00
|
|
|
connect(buildConfiguration(), &BuildConfiguration::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(this);
|
|
|
|
|
const FilePath cmakeCacheTxt = parameters.buildDirectory.pathAppended("CMakeCache.txt");
|
2022-05-05 15:51:11 +02:00
|
|
|
const bool hasCMakeCache = cmakeCacheTxt.exists();
|
2022-04-25 14:20:12 +02:00
|
|
|
const auto options = ReparseParameters(
|
2020-11-25 17:56:03 +01:00
|
|
|
hasCMakeCache
|
2022-04-25 14:20:12 +02:00
|
|
|
? REPARSE_DEFAULT
|
|
|
|
|
: (REPARSE_FORCE_INITIAL_CONFIGURATION | REPARSE_FORCE_CMAKE_RUN));
|
|
|
|
|
if (hasCMakeCache) {
|
|
|
|
|
QString errorMessage;
|
2022-05-05 15:51:11 +02:00
|
|
|
const CMakeConfig config = CMakeConfig::fromFile(cmakeCacheTxt, &errorMessage);
|
2022-04-25 14:20:12 +02:00
|
|
|
if (!config.isEmpty() && errorMessage.isEmpty()) {
|
|
|
|
|
QString cmakeBuildTypeName = config.stringValueOf("CMAKE_BUILD_TYPE");
|
2022-05-02 18:02:37 +02:00
|
|
|
setCMakeBuildType(cmakeBuildTypeName, true);
|
2022-04-25 14:20:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(options);
|
2022-04-25 14:20:12 +02:00
|
|
|
});
|
2020-04-20 17:33:36 +02:00
|
|
|
|
2022-04-25 14:20:12 +02:00
|
|
|
connect(project(), &Project::projectFileIsDirty, this, [this] {
|
|
|
|
|
if (buildConfiguration()->isActive() && !isParsing()) {
|
2023-01-20 09:10:23 +01:00
|
|
|
auto settings = CMakeSpecificSettings::instance();
|
2022-12-12 20:02:01 +01:00
|
|
|
if (settings->autorunCMake.value()) {
|
2020-04-20 17:33:36 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to dirty project file";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
|
2020-04-20 17:33:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Force initial parsing run:
|
2022-04-25 14:20:12 +02:00
|
|
|
if (buildConfiguration()->isActive()) {
|
2020-04-02 14:49:05 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Initial run:";
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(CMakeBuildSystem::REPARSE_DEFAULT);
|
2020-04-02 14:49:05 +02:00
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-20 14:11:52 +02:00
|
|
|
void CMakeBuildSystem::ensureBuildDirectory(const BuildDirParameters ¶meters)
|
2020-04-24 10:29:43 +02:00
|
|
|
{
|
2021-03-26 16:54:40 +01:00
|
|
|
const FilePath bdir = parameters.buildDirectory;
|
2021-06-09 15:08:13 +02:00
|
|
|
|
2022-09-14 16:04:30 +02:00
|
|
|
if (!buildConfiguration()->createBuildDirectory()) {
|
2022-09-29 15:26:31 +02:00
|
|
|
handleParsingFailed(Tr::tr("Failed to create build directory \"%1\".").arg(bdir.toUserOutput()));
|
2022-09-14 16:04:30 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CMakeTool *tool = parameters.cmakeTool();
|
|
|
|
|
if (!tool) {
|
2022-09-29 15:26:31 +02:00
|
|
|
handleParsingFailed(Tr::tr("No CMake tool set up in kit."));
|
2022-09-14 16:04:30 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tool->cmakeExecutable().needsDevice()) {
|
2022-09-16 10:26:41 +02:00
|
|
|
if (!tool->cmakeExecutable().ensureReachable(bdir)) {
|
2022-09-14 16:04:30 +02:00
|
|
|
// Make sure that the build directory is available on the device.
|
|
|
|
|
handleParsingFailed(
|
2022-09-29 15:26:31 +02:00
|
|
|
Tr::tr("The remote CMake executable cannot write to the local build directory."));
|
2022-09-14 16:04:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-24 10:29:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::stopParsingAndClearState()
|
|
|
|
|
{
|
2022-04-25 13:40:05 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << buildConfiguration()->displayName()
|
2021-05-31 13:38:41 +02:00
|
|
|
<< "stopping parsing run!";
|
2020-04-24 10:29:43 +02:00
|
|
|
m_reader.stop();
|
|
|
|
|
m_reader.resetData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::becameDirty()
|
|
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "CMakeBuildSystem: becameDirty was triggered.";
|
|
|
|
|
if (isParsing())
|
|
|
|
|
return;
|
|
|
|
|
|
2022-05-05 15:28:09 +02:00
|
|
|
reparse(REPARSE_DEFAULT);
|
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()
|
|
|
|
|
{
|
2022-04-25 13:40:05 +02:00
|
|
|
if (!m_error.isEmpty() || m_ctestPath.isEmpty()) {
|
2020-09-28 15:10:04 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog) << "Cancel ctest run after failed cmake run";
|
|
|
|
|
emit testInformationUpdated();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Requesting ctest run after cmake run";
|
|
|
|
|
|
2022-04-25 14:20:12 +02:00
|
|
|
const BuildDirParameters parameters(this);
|
2021-01-11 07:55:53 +01:00
|
|
|
QTC_ASSERT(parameters.isValid(), return);
|
|
|
|
|
|
2022-05-20 14:11:52 +02:00
|
|
|
ensureBuildDirectory(parameters);
|
2023-05-03 16:00:22 +02:00
|
|
|
m_ctestProcess.reset(new Process);
|
2023-01-12 23:32:11 +01:00
|
|
|
m_ctestProcess->setEnvironment(buildConfiguration()->environment());
|
|
|
|
|
m_ctestProcess->setWorkingDirectory(parameters.buildDirectory);
|
|
|
|
|
m_ctestProcess->setCommand({m_ctestPath, { "-N", "--show-only=json-v1"}});
|
2023-05-03 16:00:22 +02:00
|
|
|
connect(m_ctestProcess.get(), &Process::done, this, [this] {
|
2023-01-12 23:32:11 +01:00
|
|
|
if (m_ctestProcess->result() == ProcessResult::FinishedWithSuccess) {
|
|
|
|
|
const QJsonDocument json
|
|
|
|
|
= QJsonDocument::fromJson(m_ctestProcess->readAllRawStandardOutput());
|
2021-02-25 12:53:41 +01:00
|
|
|
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();
|
2021-05-20 09:45:50 +02:00
|
|
|
int counter = 0;
|
2021-02-25 12:53:41 +01:00
|
|
|
for (const QJsonValue &testVal : tests) {
|
2021-05-20 09:45:50 +02:00
|
|
|
++counter;
|
2021-02-25 12:53:41 +01:00
|
|
|
const QJsonObject test = testVal.toObject();
|
|
|
|
|
QTC_ASSERT(!test.isEmpty(), continue);
|
2021-06-10 13:34:10 +02:00
|
|
|
int file = -1;
|
|
|
|
|
int line = -1;
|
2021-02-25 12:53:41 +01:00
|
|
|
const int bt = test.value("backtrace").toInt(-1);
|
2021-06-10 13:34:10 +02:00
|
|
|
// we may have no real backtrace due to different registering
|
|
|
|
|
if (bt != -1) {
|
2021-06-11 11:39:45 +02:00
|
|
|
QSet<int> seen;
|
|
|
|
|
std::function<QJsonObject(int)> findAncestor = [&](int index){
|
|
|
|
|
const QJsonObject node = nodes.at(index).toObject();
|
|
|
|
|
const int parent = node.value("parent").toInt(-1);
|
|
|
|
|
if (seen.contains(parent) || parent < 0)
|
|
|
|
|
return node;
|
|
|
|
|
seen << parent;
|
|
|
|
|
return findAncestor(parent);
|
|
|
|
|
};
|
|
|
|
|
const QJsonObject btRef = findAncestor(bt);
|
2021-06-10 13:34:10 +02:00
|
|
|
file = btRef.value("file").toInt(-1);
|
|
|
|
|
line = btRef.value("line").toInt(-1);
|
|
|
|
|
}
|
|
|
|
|
// we may have no CMakeLists.txt file reference due to different registering
|
|
|
|
|
const FilePath cmakeFile = file != -1
|
|
|
|
|
? FilePath::fromString(cmakelists.at(file).toString()) : FilePath();
|
|
|
|
|
m_testNames.append({ test.value("name").toString(), counter, cmakeFile, line });
|
2021-02-25 12:53:41 +01:00
|
|
|
}
|
2020-09-28 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-25 12:53:41 +01:00
|
|
|
emit testInformationUpdated();
|
|
|
|
|
});
|
2023-01-12 23:32:11 +01:00
|
|
|
m_ctestProcess->start();
|
2020-09-28 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-01-12 23:32:11 +01:00
|
|
|
static FilePaths librarySearchPaths(const CMakeBuildSystem *bs, const QString &buildKey)
|
2020-01-21 14:00:56 +01:00
|
|
|
{
|
|
|
|
|
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) {
|
2021-05-19 17:22:29 +02:00
|
|
|
if (CMakeBuildSystem::filteredOutTarget(ct))
|
2019-10-25 09:55:32 +02:00
|
|
|
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;
|
2021-11-14 17:25:44 -08:00
|
|
|
bti.projectFilePath = ct.sourceDirectory.cleanPath();
|
2019-10-25 09:55:32 +02:00
|
|
|
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;
|
2021-06-24 17:44:14 +02:00
|
|
|
bti.isQtcRunnable = ct.qtcRunnable;
|
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) {
|
2021-11-09 18:20:14 +01:00
|
|
|
if (enabled)
|
|
|
|
|
env.prependOrSetLibrarySearchPaths(librarySearchPaths(this, buildKey));
|
2019-10-25 09:55:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
appTargetList.append(bti);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return appTargetList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList CMakeBuildSystem::buildTargetTitles() const
|
|
|
|
|
{
|
2021-06-24 11:31:48 +02:00
|
|
|
auto nonAutogenTargets = filtered(m_buildTargets, [](const CMakeBuildTarget &target){
|
2021-05-19 17:22:29 +02:00
|
|
|
return !CMakeBuildSystem::filteredOutTarget(target);
|
2021-03-30 17:56:02 +02:00
|
|
|
});
|
2021-05-19 17:22:29 +02:00
|
|
|
return transform(nonAutogenTargets, &CMakeBuildTarget::title);
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<CMakeBuildTarget> &CMakeBuildSystem::buildTargets() const
|
|
|
|
|
{
|
|
|
|
|
return m_buildTargets;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 17:22:29 +02:00
|
|
|
bool CMakeBuildSystem::filteredOutTarget(const CMakeBuildTarget &target)
|
|
|
|
|
{
|
|
|
|
|
return target.title.endsWith("_autogen") ||
|
|
|
|
|
target.title.endsWith("_autogen_timestamp_deps");
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 16:38:55 +01:00
|
|
|
bool CMakeBuildSystem::isMultiConfig() const
|
2022-05-02 16:58:26 +02:00
|
|
|
{
|
|
|
|
|
return m_isMultiConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeBuildSystem::setIsMultiConfig(bool isMultiConfig)
|
|
|
|
|
{
|
|
|
|
|
m_isMultiConfig = isMultiConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildSystem::isMultiConfigReader() const
|
2021-01-14 16:38:55 +01:00
|
|
|
{
|
|
|
|
|
return m_reader.isMultiConfig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CMakeBuildSystem::usesAllCapsTargets() const
|
|
|
|
|
{
|
|
|
|
|
return m_reader.usesAllCapsTargets();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 22:22:37 +02:00
|
|
|
CMakeProject *CMakeBuildSystem::project() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<CMakeProject *>(ProjectExplorer::BuildSystem::project());
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2021-05-20 09:45:50 +02:00
|
|
|
const QSet<QString> testsSet = Utils::toSet(tests);
|
2020-09-28 15:10:04 +02:00
|
|
|
auto current = Utils::transform<QSet<QString>>(m_testNames, &TestCaseInfo::name);
|
2021-05-20 09:45:50 +02:00
|
|
|
if (tests.isEmpty() || current == testsSet)
|
2020-09-28 15:10:04 +02:00
|
|
|
return {m_ctestPath, args};
|
|
|
|
|
|
2021-05-20 09:45:50 +02:00
|
|
|
QString testNumbers("0,0,0"); // start, end, stride
|
|
|
|
|
for (const TestCaseInfo &info : m_testNames) {
|
|
|
|
|
if (testsSet.contains(info.name))
|
|
|
|
|
testNumbers += QString(",%1").arg(info.number);
|
|
|
|
|
}
|
|
|
|
|
args << "-I" << testNumbers;
|
2020-09-28 15:10:04 +02:00
|
|
|
return {m_ctestPath, args};
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 16:52:22 +02:00
|
|
|
DeploymentData CMakeBuildSystem::deploymentDataFromFile() const
|
2019-10-25 09:55:32 +02:00
|
|
|
{
|
|
|
|
|
DeploymentData result;
|
|
|
|
|
|
2022-10-14 14:23:25 +02:00
|
|
|
FilePath sourceDir = project()->projectDirectory();
|
|
|
|
|
FilePath buildDir = buildConfiguration()->buildDirectory();
|
2019-10-25 09:55:32 +02:00
|
|
|
|
|
|
|
|
QString deploymentPrefix;
|
2022-10-14 14:23:25 +02:00
|
|
|
FilePath deploymentFilePath = sourceDir.pathAppended("QtCreatorDeployment.txt");
|
2019-10-25 09:55:32 +02:00
|
|
|
|
2022-10-14 14:23:25 +02:00
|
|
|
bool hasDeploymentFile = deploymentFilePath.exists();
|
2019-10-25 09:55:32 +02:00
|
|
|
if (!hasDeploymentFile) {
|
2022-10-14 14:23:25 +02:00
|
|
|
deploymentFilePath = buildDir.pathAppended("QtCreatorDeployment.txt");
|
|
|
|
|
hasDeploymentFile = deploymentFilePath.exists();
|
2019-10-25 09:55:32 +02:00
|
|
|
}
|
|
|
|
|
if (!hasDeploymentFile)
|
|
|
|
|
return result;
|
|
|
|
|
|
2023-02-08 08:21:41 +01:00
|
|
|
deploymentPrefix = result.addFilesFromDeploymentFile(deploymentFilePath, sourceDir);
|
2019-10-25 09:55:32 +02:00
|
|
|
for (const CMakeBuildTarget &ct : m_buildTargets) {
|
|
|
|
|
if (ct.targetType == ExecutableType || ct.targetType == DynamicLibraryType) {
|
|
|
|
|
if (!ct.executable.isEmpty()
|
|
|
|
|
&& result.deployableForLocalFile(ct.executable).localFilePath() != ct.executable) {
|
2021-09-13 12:55:01 +02:00
|
|
|
result.addFile(ct.executable,
|
2022-10-14 14:23:25 +02:00
|
|
|
deploymentPrefix + buildDir.relativeChildPath(ct.executable).toString(),
|
2019-10-25 09:55:32 +02:00
|
|
|
DeployableFile::TypeExecutable);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 16:54:40 +01:00
|
|
|
QList<ExtraCompiler *> CMakeBuildSystem::findExtraCompilers()
|
2019-08-06 12:41:46 +02:00
|
|
|
{
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: start.";
|
|
|
|
|
|
2021-03-26 16:54:40 +01:00
|
|
|
QList<ExtraCompiler *> extraCompilers;
|
2019-08-06 12:41:46 +02:00
|
|
|
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) {
|
2021-06-09 15:48:59 +02:00
|
|
|
if (!Project::SourceFiles(n) || !n->isEnabled()) // isEnabled excludes nodes from the file system tree
|
2019-08-06 12:41:46 +02:00
|
|
|
return false;
|
2022-11-23 12:53:58 +01:00
|
|
|
const QString suffix = n->filePath().suffix();
|
|
|
|
|
return !suffix.isEmpty() && fileExtensions.contains(suffix);
|
2019-08-06 12:41:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
FilePaths generated = filesGeneratedFrom(file);
|
2019-08-06 12:41:46 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "Finding Extra Compilers: generated files:" << generated;
|
|
|
|
|
if (generated.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
2021-07-14 16:49:42 +02:00
|
|
|
extraCompilers.append(factory->create(p, file, generated));
|
2019-08-06 12:41:46 +02:00
|
|
|
qCDebug(cmakeBuildSystemLog)
|
|
|
|
|
<< "Finding Extra Compilers: done with" << file.toUserOutput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qCDebug(cmakeBuildSystemLog) << "Finding Extra Compilers: done.";
|
|
|
|
|
|
|
|
|
|
return extraCompilers;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-17 11:38:33 +01:00
|
|
|
void CMakeBuildSystem::updateQmlJSCodeModel(const QStringList &extraHeaderPaths,
|
|
|
|
|
const QList<QByteArray> &moduleMappings)
|
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();
|
2022-10-25 08:57:49 +02:00
|
|
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo
|
|
|
|
|
= modelManager->defaultProjectInfoForProject(p, p->files(Project::HiddenRccFolders));
|
2019-08-06 12:41:46 +02:00
|
|
|
|
|
|
|
|
projectInfo.importPaths.clear();
|
|
|
|
|
|
2021-02-26 14:22:42 +01:00
|
|
|
auto addImports = [&projectInfo](const QString &imports) {
|
2022-05-18 12:28:04 +02:00
|
|
|
const QStringList importList = CMakeConfigItem::cmakeSplitValue(imports);
|
|
|
|
|
for (const QString &import : importList)
|
2021-02-26 14:22:42 +01:00
|
|
|
projectInfo.importPaths.maybeInsert(FilePath::fromString(import), QmlJS::Dialect::Qml);
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-02 18:02:37 +02:00
|
|
|
const CMakeConfig &cm = configurationFromCMake();
|
2021-07-06 10:29:29 +02:00
|
|
|
addImports(cm.stringValueOf("QML_IMPORT_PATH"));
|
2021-02-26 14:22:42 +01:00
|
|
|
addImports(kit()->value(QtSupport::KitQmlImportPath::id()).toString());
|
2019-08-06 12:41:46 +02:00
|
|
|
|
2021-02-26 14:33:34 +01:00
|
|
|
for (const QString &extraHeaderPath : extraHeaderPaths)
|
|
|
|
|
projectInfo.importPaths.maybeInsert(FilePath::fromString(extraHeaderPath),
|
|
|
|
|
QmlJS::Dialect::Qml);
|
|
|
|
|
|
2021-03-17 11:38:33 +01:00
|
|
|
for (const QByteArray &mm : moduleMappings) {
|
|
|
|
|
auto kvPair = mm.split('=');
|
|
|
|
|
if (kvPair.size() != 2)
|
|
|
|
|
continue;
|
|
|
|
|
QString from = QString::fromUtf8(kvPair.at(0).trimmed());
|
|
|
|
|
QString to = QString::fromUtf8(kvPair.at(1).trimmed());
|
|
|
|
|
if (!from.isEmpty() && !to.isEmpty() && from != to) {
|
|
|
|
|
// The QML code-model does not support sub-projects, so if there are multiple mappings for a single module,
|
|
|
|
|
// choose the shortest one.
|
|
|
|
|
if (projectInfo.moduleMappings.contains(from)) {
|
|
|
|
|
if (to.size() < projectInfo.moduleMappings.value(from).size())
|
|
|
|
|
projectInfo.moduleMappings.insert(from, to);
|
|
|
|
|
} else {
|
|
|
|
|
projectInfo.moduleMappings.insert(from, to);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 22:48:23 +02:00
|
|
|
void CMakeBuildSystem::updateInitialCMakeExpandableVars()
|
|
|
|
|
{
|
2022-05-02 18:02:37 +02:00
|
|
|
const CMakeConfig &cm = configurationFromCMake();
|
|
|
|
|
const CMakeConfig &initialConfig = initialCMakeConfiguration();
|
2021-04-15 22:48:23 +02:00
|
|
|
|
|
|
|
|
CMakeConfig config;
|
|
|
|
|
|
2021-07-05 15:55:18 +02:00
|
|
|
const FilePath projectDirectory = project()->projectDirectory();
|
|
|
|
|
const auto samePath = [projectDirectory](const FilePath &first, const FilePath &second) {
|
|
|
|
|
// if a path is relative, resolve it relative to the project directory
|
|
|
|
|
// this is not 100% correct since CMake resolve them to CMAKE_CURRENT_SOURCE_DIR
|
|
|
|
|
// depending on context, but we cannot do better here
|
|
|
|
|
return first == second
|
2021-09-08 16:13:43 +02:00
|
|
|
|| projectDirectory.resolvePath(first)
|
|
|
|
|
== projectDirectory.resolvePath(second)
|
|
|
|
|
|| projectDirectory.resolvePath(first).canonicalPath()
|
|
|
|
|
== projectDirectory.resolvePath(second).canonicalPath();
|
2021-07-05 15:55:18 +02:00
|
|
|
};
|
|
|
|
|
|
2021-04-15 22:48:23 +02:00
|
|
|
// Replace path values that do not exist on file system
|
|
|
|
|
const QByteArrayList singlePathList = {
|
|
|
|
|
"CMAKE_C_COMPILER",
|
|
|
|
|
"CMAKE_CXX_COMPILER",
|
|
|
|
|
"QT_QMAKE_EXECUTABLE",
|
|
|
|
|
"QT_HOST_PATH",
|
|
|
|
|
"CMAKE_TOOLCHAIN_FILE"
|
|
|
|
|
};
|
|
|
|
|
for (const auto &var : singlePathList) {
|
|
|
|
|
auto it = std::find_if(cm.cbegin(), cm.cend(), [var](const CMakeConfigItem &item) {
|
2021-12-28 21:42:29 +01:00
|
|
|
return item.key == var && !item.isInitial;
|
2021-04-15 22:48:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (it != cm.cend()) {
|
2021-07-06 10:29:29 +02:00
|
|
|
const QByteArray initialValue = initialConfig.expandedValueOf(kit(), var).toUtf8();
|
2023-02-03 15:13:04 +01:00
|
|
|
const FilePath initialPath = FilePath::fromUserInput(QString::fromUtf8(initialValue));
|
|
|
|
|
const FilePath path = FilePath::fromUserInput(QString::fromUtf8(it->value));
|
2021-07-05 15:55:18 +02:00
|
|
|
|
|
|
|
|
if (!initialValue.isEmpty() && !samePath(path, initialPath) && !path.exists()) {
|
2021-04-15 22:48:23 +02:00
|
|
|
CMakeConfigItem item(*it);
|
|
|
|
|
item.value = initialValue;
|
|
|
|
|
|
|
|
|
|
config << item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Prepend new values to existing path lists
|
|
|
|
|
const QByteArrayList multiplePathList = {
|
|
|
|
|
"CMAKE_PREFIX_PATH",
|
|
|
|
|
"CMAKE_FIND_ROOT_PATH"
|
|
|
|
|
};
|
|
|
|
|
for (const auto &var : multiplePathList) {
|
|
|
|
|
auto it = std::find_if(cm.cbegin(), cm.cend(), [var](const CMakeConfigItem &item) {
|
2021-12-28 21:42:29 +01:00
|
|
|
return item.key == var && !item.isInitial;
|
2021-04-15 22:48:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (it != cm.cend()) {
|
2021-07-06 10:29:29 +02:00
|
|
|
const QByteArrayList initialValueList = initialConfig.expandedValueOf(kit(), var).toUtf8().split(';');
|
2021-07-20 19:58:05 +02:00
|
|
|
|
|
|
|
|
for (const auto &initialValue: initialValueList) {
|
2023-02-03 15:13:04 +01:00
|
|
|
const FilePath initialPath = FilePath::fromUserInput(QString::fromUtf8(initialValue));
|
2021-07-20 19:58:05 +02:00
|
|
|
|
|
|
|
|
const bool pathIsContained
|
|
|
|
|
= Utils::contains(it->value.split(';'), [samePath, initialPath](const QByteArray &p) {
|
2023-02-03 15:13:04 +01:00
|
|
|
return samePath(FilePath::fromUserInput(QString::fromUtf8(p)), initialPath);
|
2021-07-20 19:58:05 +02:00
|
|
|
});
|
|
|
|
|
if (!initialValue.isEmpty() && !pathIsContained) {
|
|
|
|
|
CMakeConfigItem item(*it);
|
|
|
|
|
item.value = initialValue;
|
|
|
|
|
item.value.append(";");
|
|
|
|
|
item.value.append(it->value);
|
|
|
|
|
|
|
|
|
|
config << item;
|
|
|
|
|
}
|
2021-04-15 22:48:23 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!config.isEmpty())
|
2022-04-25 14:03:03 +02:00
|
|
|
emit configurationChanged(config);
|
2021-04-15 22:48:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-10 16:41:27 +02:00
|
|
|
MakeInstallCommand CMakeBuildSystem::makeInstallCommand(const FilePath &installRoot) const
|
|
|
|
|
{
|
|
|
|
|
MakeInstallCommand cmd;
|
|
|
|
|
if (CMakeTool *tool = CMakeKitAspect::cmakeTool(target()->kit()))
|
|
|
|
|
cmd.command.setExecutable(tool->cmakeExecutable());
|
|
|
|
|
|
|
|
|
|
QString installTarget = "install";
|
|
|
|
|
if (usesAllCapsTargets())
|
|
|
|
|
installTarget = "INSTALL";
|
|
|
|
|
|
|
|
|
|
FilePath buildDirectory = ".";
|
|
|
|
|
if (auto bc = buildConfiguration())
|
|
|
|
|
buildDirectory = bc->buildDirectory();
|
|
|
|
|
|
|
|
|
|
cmd.command.addArg("--build");
|
2023-04-04 10:39:20 +02:00
|
|
|
cmd.command.addArg(buildDirectory.path());
|
2022-06-10 16:41:27 +02:00
|
|
|
cmd.command.addArg("--target");
|
|
|
|
|
cmd.command.addArg(installTarget);
|
|
|
|
|
|
|
|
|
|
if (isMultiConfigReader())
|
|
|
|
|
cmd.command.addArgs({"--config", cmakeBuildType()});
|
|
|
|
|
|
|
|
|
|
cmd.environment.set("DESTDIR", installRoot.nativePath());
|
|
|
|
|
return cmd;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 17:07:52 +01:00
|
|
|
QList<QPair<Id, QString>> CMakeBuildSystem::generators() const
|
|
|
|
|
{
|
|
|
|
|
if (!buildConfiguration())
|
|
|
|
|
return {};
|
|
|
|
|
const CMakeTool * const cmakeTool
|
|
|
|
|
= CMakeKitAspect::cmakeTool(buildConfiguration()->target()->kit());
|
|
|
|
|
if (!cmakeTool)
|
|
|
|
|
return {};
|
|
|
|
|
QList<QPair<Id, QString>> result;
|
|
|
|
|
const QList<CMakeTool::Generator> &generators = cmakeTool->supportedGenerators();
|
|
|
|
|
for (const CMakeTool::Generator &generator : generators) {
|
|
|
|
|
result << qMakePair(Id::fromSetting(generator.name),
|
|
|
|
|
Tr::tr("%1 (via cmake)").arg(generator.name));
|
|
|
|
|
for (const QString &extraGenerator : generator.extraGenerators) {
|
|
|
|
|
const QString displayName = extraGenerator + " - " + generator.name;
|
|
|
|
|
result << qMakePair(Id::fromSetting(displayName),
|
|
|
|
|
Tr::tr("%1 (via cmake)").arg(displayName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 23:32:11 +01:00
|
|
|
void CMakeBuildSystem::runGenerator(Id id)
|
2022-12-06 17:07:52 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(cmakeBuildConfiguration(), return);
|
|
|
|
|
const auto showError = [](const QString &detail) {
|
|
|
|
|
Core::MessageManager::writeDisrupting(Tr::tr("cmake generator failed: %1.").arg(detail));
|
|
|
|
|
};
|
|
|
|
|
const CMakeTool * const cmakeTool
|
|
|
|
|
= CMakeKitAspect::cmakeTool(buildConfiguration()->target()->kit());
|
|
|
|
|
if (!cmakeTool) {
|
2023-05-26 11:52:43 +02:00
|
|
|
showError(Tr::tr("Kit does not have a cmake binary set."));
|
2022-12-06 17:07:52 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const QString generator = id.toSetting().toString();
|
|
|
|
|
const FilePath outDir = buildConfiguration()->buildDirectory()
|
|
|
|
|
/ ("qtc_" + FileUtils::fileSystemFriendlyName(generator));
|
|
|
|
|
if (!outDir.ensureWritableDir()) {
|
2023-05-26 11:52:43 +02:00
|
|
|
showError(Tr::tr("Cannot create output directory \"%1\".").arg(outDir.toString()));
|
2022-12-06 17:07:52 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CommandLine cmdLine(cmakeTool->cmakeExecutable(), {"-S", buildConfiguration()->target()
|
|
|
|
|
->project()->projectDirectory().toUserOutput(), "-G", generator});
|
|
|
|
|
if (!cmdLine.executable().isExecutableFile()) {
|
2023-05-26 11:52:43 +02:00
|
|
|
showError(Tr::tr("No valid cmake executable."));
|
2022-12-06 17:07:52 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto itemFilter = [](const CMakeConfigItem &item) {
|
|
|
|
|
return !item.isNull()
|
|
|
|
|
&& item.type != CMakeConfigItem::STATIC
|
|
|
|
|
&& item.type != CMakeConfigItem::INTERNAL
|
|
|
|
|
&& !item.key.contains("GENERATOR");
|
|
|
|
|
};
|
|
|
|
|
QList<CMakeConfigItem> configItems = Utils::filtered(m_configurationChanges.toList(),
|
|
|
|
|
itemFilter);
|
|
|
|
|
const QList<CMakeConfigItem> initialConfigItems
|
|
|
|
|
= Utils::filtered(initialCMakeConfiguration().toList(), itemFilter);
|
|
|
|
|
for (const CMakeConfigItem &item : std::as_const(initialConfigItems)) {
|
|
|
|
|
if (!Utils::contains(configItems, [&item](const CMakeConfigItem &existingItem) {
|
|
|
|
|
return existingItem.key == item.key;
|
|
|
|
|
})) {
|
|
|
|
|
configItems << item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const CMakeConfigItem &item : std::as_const(configItems))
|
|
|
|
|
cmdLine.addArg(item.toArgument(buildConfiguration()->macroExpander()));
|
|
|
|
|
if (const auto optionsAspect = buildConfiguration()->aspect<AdditionalCMakeOptionsAspect>();
|
|
|
|
|
optionsAspect && !optionsAspect->value().isEmpty()) {
|
|
|
|
|
cmdLine.addArgs(optionsAspect->value(), CommandLine::Raw);
|
|
|
|
|
}
|
2023-05-03 16:00:22 +02:00
|
|
|
const auto proc = new Process(this);
|
|
|
|
|
connect(proc, &Process::done, proc, &Process::deleteLater);
|
|
|
|
|
connect(proc, &Process::readyReadStandardOutput, this, [proc] {
|
2023-01-05 17:55:04 +01:00
|
|
|
Core::MessageManager::writeFlashing(QString::fromLocal8Bit(proc->readAllRawStandardOutput()));
|
2022-12-06 17:07:52 +01:00
|
|
|
});
|
2023-05-03 16:00:22 +02:00
|
|
|
connect(proc, &Process::readyReadStandardError, this, [proc] {
|
2023-01-05 17:55:04 +01:00
|
|
|
Core::MessageManager::writeDisrupting(QString::fromLocal8Bit(proc->readAllRawStandardError()));
|
2022-12-06 17:07:52 +01:00
|
|
|
});
|
|
|
|
|
proc->setWorkingDirectory(outDir);
|
|
|
|
|
proc->setEnvironment(buildConfiguration()->environment());
|
|
|
|
|
proc->setCommand(cmdLine);
|
2023-05-26 11:52:43 +02:00
|
|
|
Core::MessageManager::writeFlashing(
|
|
|
|
|
Tr::tr("Running in %1: %2.").arg(outDir.toUserOutput(), cmdLine.toUserOutput()));
|
2022-12-06 17:07:52 +01:00
|
|
|
proc->start();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-25 14:15:15 +01:00
|
|
|
ExtraCompiler *CMakeBuildSystem::findExtraCompiler(const ExtraCompilerFilter &filter) const
|
2023-01-16 17:03:26 +01:00
|
|
|
{
|
2023-01-25 14:15:15 +01:00
|
|
|
return Utils::findOrDefault(m_extraCompilers, filter);
|
2023-01-16 17:03:26 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-29 15:26:31 +02:00
|
|
|
} // CMakeProjectManager::Internal
|