2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeproject.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
|
|
|
|
|
#include "cmakebuildconfiguration.h"
|
2016-01-06 15:51:44 +01:00
|
|
|
#include "cmakekitinformation.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cmakeprojectconstants.h"
|
|
|
|
|
#include "cmakeprojectnodes.h"
|
2015-03-10 10:22:38 +01:00
|
|
|
#include "cmakeprojectmanager.h"
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2016-12-04 03:36:12 +10:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
2017-02-06 16:59:53 +01:00
|
|
|
#include <cpptools/cpprawprojectpart.h>
|
|
|
|
|
#include <cpptools/cppprojectupdater.h>
|
2016-10-06 11:31:23 +02:00
|
|
|
#include <cpptools/generatedcodemodelsupport.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2016-12-04 03:36:12 +10:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2013-07-07 23:49:13 +02:00
|
|
|
#include <projectexplorer/buildtargetinfo.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/deploymentdata.h>
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2017-09-28 11:32:39 +02:00
|
|
|
#include <projectexplorer/kitmanager.h>
|
2016-01-20 12:19:16 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2010-11-01 14:14:17 +01:00
|
|
|
#include <projectexplorer/toolchain.h>
|
2013-01-17 15:12:46 +01:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
2019-01-04 12:35:28 +01:00
|
|
|
#include <qtsupport/qtcppkitinfo.h>
|
2013-01-17 15:12:46 +01:00
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2016-04-18 13:06:41 +02:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2016-10-06 11:31:23 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2012-11-19 14:18:14 +01:00
|
|
|
#include <utils/stringutils.h>
|
2013-01-01 18:18:03 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2016-06-14 17:43:11 +02:00
|
|
|
#include <QSet>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
2015-02-01 18:44:47 +02:00
|
|
|
using namespace Utils;
|
2008-12-12 17:22:02 +01:00
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
namespace CMakeProjectManager {
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
static CMakeBuildConfiguration *activeBc(const CMakeProject *p)
|
|
|
|
|
{
|
|
|
|
|
return qobject_cast<CMakeBuildConfiguration *>(p->activeTarget() ? p->activeTarget()->activeBuildConfiguration() : nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-12 17:22:02 +01:00
|
|
|
// QtCreator CMake Generator wishlist:
|
|
|
|
|
// Which make targets we need to build to get all executables
|
|
|
|
|
// What is the actual compiler executable
|
|
|
|
|
// DEFINES
|
|
|
|
|
|
2009-09-24 16:02:02 +02:00
|
|
|
/*!
|
|
|
|
|
\class CMakeProject
|
|
|
|
|
*/
|
2017-03-29 11:25:01 +02:00
|
|
|
CMakeProject::CMakeProject(const FileName &fileName) : Project(Constants::CMAKEMIMETYPE, fileName),
|
2018-12-11 15:37:59 +01:00
|
|
|
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-10-06 11:31:23 +02:00
|
|
|
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
2017-01-30 14:59:10 +01:00
|
|
|
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
2017-04-07 14:35:49 +02:00
|
|
|
setDisplayName(projectDirectory().fileName());
|
2011-04-12 12:17:19 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
// Timer:
|
|
|
|
|
m_delayedParsingTimer.setSingleShot(true);
|
2017-07-28 11:16:18 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
connect(&m_delayedParsingTimer, &QTimer::timeout,
|
|
|
|
|
this, [this]() { startParsing(m_delayedParsingParameters); });
|
|
|
|
|
|
|
|
|
|
// BuildDirManager:
|
|
|
|
|
connect(&m_buildDirManager, &BuildDirManager::requestReparse,
|
|
|
|
|
this, &CMakeProject::handleReparseRequest);
|
|
|
|
|
connect(&m_buildDirManager, &BuildDirManager::dataAvailable,
|
|
|
|
|
this, [this]() {
|
|
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (bc && bc == m_buildDirManager.buildConfiguration()) {
|
|
|
|
|
bc->clearError();
|
|
|
|
|
handleParsingSuccess(bc);
|
2017-07-28 11:16:18 +02:00
|
|
|
}
|
|
|
|
|
});
|
2017-09-28 11:32:39 +02:00
|
|
|
connect(&m_buildDirManager, &BuildDirManager::errorOccured,
|
|
|
|
|
this, [this](const QString &msg) {
|
|
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (bc && bc == m_buildDirManager.buildConfiguration()) {
|
|
|
|
|
bc->setError(msg);
|
2017-12-07 16:25:47 +01:00
|
|
|
bc->setConfigurationFromCMake(m_buildDirManager.takeCMakeConfiguration());
|
2017-09-28 11:32:39 +02:00
|
|
|
handleParsingError(bc);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
connect(&m_buildDirManager, &BuildDirManager::parsingStarted,
|
|
|
|
|
this, [this]() {
|
|
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (bc && bc == m_buildDirManager.buildConfiguration())
|
|
|
|
|
bc->clearError(CMakeBuildConfiguration::ForceEnabledChanged::True);
|
|
|
|
|
});
|
2017-07-28 11:16:18 +02:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
// Kit changed:
|
|
|
|
|
connect(KitManager::instance(), &KitManager::kitUpdated,
|
|
|
|
|
this, [this](Kit *k) {
|
|
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (!bc || k != bc->target()->kit())
|
|
|
|
|
return; // not for us...
|
|
|
|
|
|
|
|
|
|
// Build configuration has not changed, but Kit settings might have:
|
|
|
|
|
// reparse and check the configuration, independent of whether the reader has changed
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(
|
|
|
|
|
BuildDirParameters(bc),
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Target switched:
|
|
|
|
|
connect(this, &Project::activeTargetChanged, this, [this]() {
|
|
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
|
2017-10-17 15:41:52 +02:00
|
|
|
if (!bc)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
// Target has switched, so the kit has changed, too.
|
|
|
|
|
// * run cmake with configuration arguments if the reader needs to be switched
|
|
|
|
|
// * run cmake without configuration arguments if the reader stays
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(
|
|
|
|
|
BuildDirParameters(bc),
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// BuildConfiguration switched:
|
|
|
|
|
subscribeSignal(&Target::activeBuildConfigurationChanged, this, [this]() {
|
|
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
|
2017-10-17 15:41:52 +02:00
|
|
|
if (!bc)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
// Build configuration has switched:
|
2017-10-18 13:05:44 +02:00
|
|
|
// * Check configuration if reader changes due to it not existing yet:-)
|
2017-09-28 11:32:39 +02:00
|
|
|
// * run cmake without configuration arguments if the reader stays
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(
|
|
|
|
|
BuildDirParameters(bc),
|
2017-10-18 13:05:44 +02:00
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
2017-09-28 11:32:39 +02:00
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// BuildConfiguration changed:
|
|
|
|
|
subscribeSignal(&CMakeBuildConfiguration::environmentChanged, this, [this]() {
|
|
|
|
|
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
|
|
|
|
|
|
|
|
|
if (senderBc && senderBc->isActive()) {
|
|
|
|
|
// The environment on our BC has changed:
|
2018-10-22 16:34:31 +02:00
|
|
|
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
|
2017-09-28 11:32:39 +02:00
|
|
|
// * run cmake without configuration arguments if the reader stays
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(
|
|
|
|
|
BuildDirParameters(senderBc),
|
|
|
|
|
BuildDirManager::REPARSE_FAIL,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
subscribeSignal(&CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() {
|
|
|
|
|
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
|
|
|
|
|
|
|
|
|
if (senderBc && senderBc->isActive() && senderBc == m_buildDirManager.buildConfiguration()) {
|
|
|
|
|
// The build directory of our BC has changed:
|
2018-10-22 16:34:31 +02:00
|
|
|
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
|
2017-09-28 11:32:39 +02:00
|
|
|
// * run cmake without configuration arguments if the reader stays
|
|
|
|
|
// If no configuration exists, then the arguments will get added automatically by
|
|
|
|
|
// the reader.
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(
|
|
|
|
|
BuildDirParameters(senderBc),
|
|
|
|
|
BuildDirManager::REPARSE_FAIL,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
subscribeSignal(&CMakeBuildConfiguration::configurationForCMakeChanged, this, [this]() {
|
|
|
|
|
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
|
|
|
|
|
|
|
|
|
|
if (senderBc && senderBc->isActive() && senderBc == m_buildDirManager.buildConfiguration()) {
|
|
|
|
|
// The CMake configuration has changed on our BC:
|
2018-10-22 16:34:31 +02:00
|
|
|
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
|
2017-09-28 11:32:39 +02:00
|
|
|
// * run cmake with configuration arguments if the reader stays
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(
|
|
|
|
|
BuildDirParameters(senderBc),
|
|
|
|
|
BuildDirManager::REPARSE_FAIL,
|
|
|
|
|
BuildDirManager::REPARSE_FORCE_CONFIGURATION);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// TreeScanner:
|
2016-12-04 03:36:12 +10:00
|
|
|
connect(&m_treeScanner, &TreeScanner::finished, this, &CMakeProject::handleTreeScanningFinished);
|
|
|
|
|
|
|
|
|
|
m_treeScanner.setFilter([this](const Utils::MimeType &mimeType, const Utils::FileName &fn) {
|
|
|
|
|
// Mime checks requires more resources, so keep it last in check list
|
|
|
|
|
auto isIgnored =
|
|
|
|
|
fn.toString().startsWith(projectFilePath().toString() + ".user") ||
|
|
|
|
|
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::FileName &fn) {
|
|
|
|
|
auto type = TreeScanner::genericFileType(mimeType, fn);
|
|
|
|
|
if (type == FileType::Unknown) {
|
|
|
|
|
if (mimeType.isValid()) {
|
|
|
|
|
const QString mt = mimeType.name();
|
|
|
|
|
if (mt == CMakeProjectManager::Constants::CMAKEPROJECTMIMETYPE
|
|
|
|
|
|| mt == CMakeProjectManager::Constants::CMAKEMIMETYPE)
|
|
|
|
|
type = FileType::Project;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return type;
|
|
|
|
|
});
|
2009-01-12 15:10:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CMakeProject::~CMakeProject()
|
|
|
|
|
{
|
2017-02-14 16:34:22 +10:00
|
|
|
if (!m_treeScanner.isFinished()) {
|
|
|
|
|
auto future = m_treeScanner.future();
|
|
|
|
|
future.cancel();
|
|
|
|
|
future.waitForFinished();
|
|
|
|
|
}
|
2017-02-06 16:59:53 +01:00
|
|
|
delete m_cppCodeModelUpdater;
|
2016-01-15 16:12:54 +01:00
|
|
|
qDeleteAll(m_extraCompilers);
|
2016-12-04 03:36:12 +10:00
|
|
|
qDeleteAll(m_allFiles);
|
2009-09-24 16:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-02 17:32:31 +01:00
|
|
|
void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
2009-01-12 15:10:33 +01:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
const CMakeBuildConfiguration *aBc = activeBc(this);
|
2016-12-04 03:36:12 +10:00
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
QTC_ASSERT(bc, return);
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(bc == aBc, return);
|
|
|
|
|
QTC_ASSERT(m_treeScanner.isFinished() && !m_buildDirManager.isParsing(), return);
|
2016-12-04 03:36:12 +10:00
|
|
|
|
2019-03-06 14:17:17 +02:00
|
|
|
const QList<CMakeBuildTarget> buildTargets = m_buildDirManager.takeBuildTargets();
|
|
|
|
|
bc->setBuildTargets(buildTargets);
|
|
|
|
|
const CMakeConfig cmakeConfig = m_buildDirManager.takeCMakeConfiguration();
|
|
|
|
|
bc->setConfigurationFromCMake(cmakeConfig);
|
|
|
|
|
|
|
|
|
|
CMakeConfig patchedConfig = cmakeConfig;
|
|
|
|
|
{
|
|
|
|
|
CMakeConfigItem settingFileItem;
|
|
|
|
|
settingFileItem.key = "ANDROID_DEPLOYMENT_SETTINGS_FILE";
|
|
|
|
|
settingFileItem.value = bc->buildDirectory().appendPath("android_deployment_settings.json").toString().toUtf8();
|
|
|
|
|
patchedConfig.append(settingFileItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSet<QString> res;
|
|
|
|
|
QStringList apps;
|
|
|
|
|
for (const auto &target : bc->buildTargets()) {
|
|
|
|
|
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;
|
|
|
|
|
paths.key = "ANDROID_SO_LIBS_PATHS";
|
|
|
|
|
paths.values = res.toList();
|
|
|
|
|
patchedConfig.append(paths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apps.sort();
|
|
|
|
|
{
|
|
|
|
|
CMakeConfigItem appsPaths;
|
|
|
|
|
appsPaths.key = "TARGETS_BUILD_PATH";
|
|
|
|
|
appsPaths.values = apps;
|
|
|
|
|
patchedConfig.append(appsPaths);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
|
|
|
|
|
auto newRoot = generateProjectTree(m_allFiles);
|
2017-04-07 14:35:49 +02:00
|
|
|
if (newRoot) {
|
|
|
|
|
setDisplayName(newRoot->displayName());
|
2018-04-26 14:41:46 +02:00
|
|
|
setRootProjectNode(std::move(newRoot));
|
2019-03-06 14:17:17 +02:00
|
|
|
|
|
|
|
|
for (const CMakeBuildTarget &bt : buildTargets) {
|
|
|
|
|
const QString buildKey = CMakeTargetNode::generateId(bt.sourceDirectory, bt.title);
|
|
|
|
|
if (ProjectNode *node = findNodeForBuildKey(buildKey)) {
|
|
|
|
|
if (auto targetNode = dynamic_cast<CMakeTargetNode *>(node))
|
|
|
|
|
targetNode->setConfig(patchedConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-07 14:35:49 +02:00
|
|
|
}
|
2008-12-09 14:13:29 +01:00
|
|
|
|
2019-01-04 12:35:28 +01:00
|
|
|
Target *t = bc->target();
|
2018-12-20 18:51:12 +01:00
|
|
|
t->setApplicationTargets(bc->appTargets());
|
|
|
|
|
t->setDeploymentData(bc->deploymentData());
|
|
|
|
|
|
2018-03-23 09:32:52 +01:00
|
|
|
t->updateDefaultRunConfigurations();
|
2010-09-24 13:17:43 +02:00
|
|
|
|
2019-01-20 15:03:55 +01:00
|
|
|
qDeleteAll(m_extraCompilers);
|
|
|
|
|
m_extraCompilers = findExtraCompilers();
|
|
|
|
|
CppTools::GeneratedCodeModelSupport::update(m_extraCompilers);
|
2009-02-11 12:14:51 +01:00
|
|
|
|
2019-01-04 12:35:28 +01:00
|
|
|
QtSupport::CppKitInfo kitInfo(this);
|
|
|
|
|
QTC_ASSERT(kitInfo.isValid(), return);
|
2015-04-21 09:08:07 +03:00
|
|
|
|
2019-01-20 15:25:18 +01:00
|
|
|
CppTools::RawProjectParts rpps = m_buildDirManager.createRawProjectParts();
|
2015-04-21 09:08:07 +03:00
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
for (CppTools::RawProjectPart &rpp : rpps) {
|
2019-01-04 12:35:28 +01:00
|
|
|
rpp.setQtVersion(kitInfo.projectPartQtVersion); // TODO: Check if project actually uses Qt.
|
|
|
|
|
if (kitInfo.cxxToolChain)
|
|
|
|
|
rpp.setFlagsForCxx({kitInfo.cxxToolChain, rpp.flagsForCxx.commandLineFlags});
|
|
|
|
|
if (kitInfo.cToolChain)
|
|
|
|
|
rpp.setFlagsForC({kitInfo.cToolChain, rpp.flagsForC.commandLineFlags});
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
2013-04-28 16:23:01 +04:00
|
|
|
|
2019-01-08 12:33:18 +01:00
|
|
|
m_cppCodeModelUpdater->update({this, kitInfo, rpps});
|
2015-02-15 23:13:28 +02:00
|
|
|
|
2016-04-18 13:06:41 +02:00
|
|
|
updateQmlJSCodeModel();
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
m_buildDirManager.resetData();
|
|
|
|
|
|
2010-09-27 20:34:22 +01:00
|
|
|
emit fileListChanged();
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2019-01-15 00:00:02 +01:00
|
|
|
bc->emitBuildTypeChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-18 13:06:41 +02:00
|
|
|
void CMakeProject::updateQmlJSCodeModel()
|
|
|
|
|
{
|
|
|
|
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
QTC_ASSERT(modelManager, return);
|
|
|
|
|
|
|
|
|
|
if (!activeTarget() || !activeTarget()->activeBuildConfiguration())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
|
|
|
|
modelManager->defaultProjectInfoForProject(this);
|
|
|
|
|
|
|
|
|
|
projectInfo.importPaths.clear();
|
|
|
|
|
|
|
|
|
|
QString cmakeImports;
|
2018-11-04 23:09:41 +01:00
|
|
|
auto bc = qobject_cast<const CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
2016-04-18 13:06:41 +02:00
|
|
|
if (!bc)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
const CMakeConfig &cm = bc->configurationFromCMake();
|
|
|
|
|
foreach (const CMakeConfigItem &di, cm) {
|
|
|
|
|
if (di.key.contains("QML_IMPORT_PATH")) {
|
|
|
|
|
cmakeImports = QString::fromUtf8(di.value);
|
2016-04-18 13:06:41 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 11:31:25 +02:00
|
|
|
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
2017-03-27 13:59:19 +02:00
|
|
|
projectInfo.importPaths.maybeInsert(FileName::fromString(cmakeImport), QmlJS::Dialect::Qml);
|
2016-04-18 13:06:41 +02:00
|
|
|
|
|
|
|
|
modelManager->updateProjectInfo(projectInfo, this);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 14:41:46 +02:00
|
|
|
std::unique_ptr<CMakeProjectNode>
|
|
|
|
|
CMakeProject::generateProjectTree(const QList<const FileNode *> &allFiles) const
|
2017-09-28 11:32:39 +02:00
|
|
|
{
|
|
|
|
|
if (m_buildDirManager.isParsing())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
auto root = std::make_unique<CMakeProjectNode>(projectDirectory());
|
|
|
|
|
m_buildDirManager.generateProjectTree(root.get(), allFiles);
|
2018-04-26 14:41:46 +02:00
|
|
|
return root;
|
2017-09-28 11:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 16:22:07 +02:00
|
|
|
bool CMakeProject::knowsAllBuildExecutables() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 13:39:05 +02:00
|
|
|
QList<Task> CMakeProject::projectIssues(const Kit *k) const
|
2016-01-06 15:51:44 +01:00
|
|
|
{
|
2018-04-18 13:39:05 +02:00
|
|
|
QList<Task> result = Project::projectIssues(k);
|
|
|
|
|
|
2019-02-06 12:50:51 +01:00
|
|
|
if (!CMakeKitAspect::cmakeTool(k))
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Error, tr("No cmake tool set.")));
|
2019-02-06 12:50:51 +01:00
|
|
|
if (ToolChainKitAspect::toolChains(k).isEmpty())
|
2018-04-18 13:39:05 +02:00
|
|
|
result.append(createProjectTask(Task::TaskType::Warning, tr("No compilers set in kit.")));
|
|
|
|
|
|
|
|
|
|
return result;
|
2016-01-06 15:51:44 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 12:19:16 +01:00
|
|
|
void CMakeProject::runCMake()
|
|
|
|
|
{
|
2017-11-21 11:06:41 +01:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (isParsing() || !bc)
|
2017-07-28 11:16:18 +02:00
|
|
|
return;
|
2016-01-20 12:19:16 +01:00
|
|
|
|
2017-11-21 11:06:41 +01:00
|
|
|
BuildDirParameters parameters(bc);
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(parameters,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
|
2017-07-28 11:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::runCMakeAndScanProjectTree()
|
|
|
|
|
{
|
2017-11-21 11:06:41 +01:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
if (isParsing() || !bc)
|
2017-07-28 11:16:18 +02:00
|
|
|
return;
|
2017-11-21 11:06:41 +01:00
|
|
|
QTC_ASSERT(m_treeScanner.isFinished(), return);
|
2017-07-28 11:16:18 +02:00
|
|
|
|
2017-11-21 11:06:41 +01:00
|
|
|
BuildDirParameters parameters(bc);
|
|
|
|
|
m_buildDirManager.setParametersAndRequestParse(parameters,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION | BuildDirManager::REPARSE_SCAN,
|
|
|
|
|
BuildDirManager::REPARSE_CHECK_CONFIGURATION | BuildDirManager::REPARSE_SCAN);
|
2011-03-31 17:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 15:18:25 +01:00
|
|
|
void CMakeProject::buildCMakeTarget(const QString &buildTarget)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!buildTarget.isEmpty(), return);
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
2016-11-14 15:18:25 +01:00
|
|
|
if (bc)
|
|
|
|
|
bc->buildTarget(buildTarget);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 14:33:44 +02:00
|
|
|
ProjectImporter *CMakeProject::projectImporter() const
|
|
|
|
|
{
|
|
|
|
|
if (!m_projectImporter)
|
|
|
|
|
m_projectImporter = std::make_unique<CMakeProjectImporter>(projectFilePath());
|
|
|
|
|
return m_projectImporter.get();
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
bool CMakeProject::persistCMakeState()
|
|
|
|
|
{
|
|
|
|
|
return m_buildDirManager.persistCMakeState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::clearCMakeCache()
|
|
|
|
|
{
|
|
|
|
|
m_buildDirManager.clearCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::handleReparseRequest(int reparseParameters)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!(reparseParameters & BuildDirManager::REPARSE_FAIL), return);
|
|
|
|
|
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_delayedParsingTimer.setInterval((reparseParameters & BuildDirManager::REPARSE_URGENT) ? 0 : 1000);
|
|
|
|
|
m_delayedParsingTimer.start();
|
|
|
|
|
m_delayedParsingParameters = m_delayedParsingParameters | reparseParameters;
|
2017-11-21 11:06:41 +01:00
|
|
|
if (m_allFiles.isEmpty())
|
|
|
|
|
m_delayedParsingParameters |= BuildDirManager::REPARSE_SCAN;
|
2017-09-28 11:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CMakeProject::startParsing(int reparseParameters)
|
|
|
|
|
{
|
|
|
|
|
m_delayedParsingParameters = BuildDirManager::REPARSE_DEFAULT;
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT((reparseParameters & BuildDirManager::REPARSE_FAIL) == 0, return);
|
|
|
|
|
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QTC_ASSERT(activeBc(this), return);
|
|
|
|
|
|
|
|
|
|
emitParsingStarted();
|
|
|
|
|
|
2017-11-21 11:06:41 +01:00
|
|
|
m_waitingForScan = reparseParameters & BuildDirManager::REPARSE_SCAN;
|
2017-09-28 11:32:39 +02:00
|
|
|
m_waitingForParse = true;
|
|
|
|
|
m_combinedScanAndParseResult = true;
|
|
|
|
|
|
|
|
|
|
if (m_waitingForScan) {
|
|
|
|
|
QTC_CHECK(m_treeScanner.isFinished());
|
|
|
|
|
m_treeScanner.asyncScanForFiles(projectDirectory());
|
|
|
|
|
Core::ProgressManager::addTask(m_treeScanner.future(),
|
|
|
|
|
tr("Scan \"%1\" project tree").arg(displayName()),
|
|
|
|
|
"CMake.Scan.Tree");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_buildDirManager.parse(reparseParameters);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-12 16:33:28 +01:00
|
|
|
QStringList CMakeProject::buildTargetTitles() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-12-20 18:51:12 +01:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
|
|
|
|
return bc ? bc->buildTargetTitles() : QStringList();
|
2010-01-14 15:38:31 +01:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2015-05-18 16:57:29 +02:00
|
|
|
RestoreResult result = Project::fromMap(map, errorMessage);
|
|
|
|
|
if (result != RestoreResult::Ok)
|
|
|
|
|
return result;
|
|
|
|
|
return RestoreResult::Ok;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2012-10-02 17:46:19 +02:00
|
|
|
bool CMakeProject::setupTarget(Target *t)
|
|
|
|
|
{
|
2013-07-07 23:49:13 +02:00
|
|
|
t->updateDefaultBuildConfigurations();
|
2014-07-31 16:36:46 +02:00
|
|
|
if (t->buildConfigurations().isEmpty())
|
|
|
|
|
return false;
|
2013-07-07 23:49:13 +02:00
|
|
|
t->updateDefaultDeployConfigurations();
|
2012-10-02 17:46:19 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
void CMakeProject::handleTreeScanningFinished()
|
2016-02-24 18:00:24 +01:00
|
|
|
{
|
2017-07-28 11:16:18 +02:00
|
|
|
QTC_CHECK(m_waitingForScan);
|
2016-02-24 18:00:24 +01:00
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
qDeleteAll(m_allFiles);
|
|
|
|
|
m_allFiles = Utils::transform(m_treeScanner.release(), [](const FileNode *fn) { return fn; });
|
2016-02-24 18:00:24 +01:00
|
|
|
|
2017-09-28 11:32:39 +02:00
|
|
|
CMakeBuildConfiguration *bc = activeBc(this);
|
2017-07-28 11:16:18 +02:00
|
|
|
QTC_ASSERT(bc, return);
|
|
|
|
|
|
|
|
|
|
m_combinedScanAndParseResult = m_combinedScanAndParseResult && true;
|
|
|
|
|
m_waitingForScan = false;
|
2016-03-31 15:07:58 +02:00
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
combineScanAndParse(bc);
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
void CMakeProject::handleParsingSuccess(CMakeBuildConfiguration *bc)
|
2016-02-24 18:00:24 +01:00
|
|
|
{
|
2017-09-28 11:32:39 +02:00
|
|
|
QTC_ASSERT(m_waitingForParse, return);
|
2017-07-28 11:16:18 +02:00
|
|
|
|
|
|
|
|
if (!bc || !bc->isActive())
|
2016-02-24 18:00:24 +01:00
|
|
|
return;
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
m_waitingForParse = false;
|
|
|
|
|
m_combinedScanAndParseResult = m_combinedScanAndParseResult && true;
|
|
|
|
|
|
|
|
|
|
combineScanAndParse(bc);
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
void CMakeProject::handleParsingError(CMakeBuildConfiguration *bc)
|
2016-02-24 18:00:24 +01:00
|
|
|
{
|
2017-07-28 11:16:18 +02:00
|
|
|
QTC_CHECK(m_waitingForParse);
|
|
|
|
|
|
|
|
|
|
if (!bc || !bc->isActive())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_waitingForParse = false;
|
|
|
|
|
m_combinedScanAndParseResult = false;
|
|
|
|
|
|
|
|
|
|
combineScanAndParse(bc);
|
2016-02-24 18:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
|
|
|
|
|
void CMakeProject::combineScanAndParse(CMakeBuildConfiguration *bc)
|
2016-12-04 03:36:12 +10:00
|
|
|
{
|
2017-07-28 11:16:18 +02:00
|
|
|
QTC_ASSERT(bc && bc->isActive(), return);
|
2016-12-04 03:36:12 +10:00
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
if (m_waitingForParse || m_waitingForScan)
|
2016-12-04 03:36:12 +10:00
|
|
|
return;
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
if (m_combinedScanAndParseResult)
|
|
|
|
|
updateProjectData(bc);
|
2016-12-04 03:36:12 +10:00
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
emitParsingFinished(m_combinedScanAndParseResult);
|
2016-12-04 03:36:12 +10:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
2010-09-24 13:17:43 +02:00
|
|
|
{
|
2015-09-10 16:17:38 +02:00
|
|
|
if (!activeTarget())
|
2016-01-15 16:12:54 +01:00
|
|
|
return QStringList();
|
|
|
|
|
QFileInfo fi(sourceFile);
|
2015-02-01 18:44:47 +02:00
|
|
|
FileName project = projectDirectory();
|
|
|
|
|
FileName baseDirectory = FileName::fromString(fi.absolutePath());
|
2013-01-08 17:21:18 +01:00
|
|
|
|
|
|
|
|
while (baseDirectory.isChildOf(project)) {
|
2015-02-01 18:44:47 +02:00
|
|
|
FileName cmakeListsTxt = baseDirectory;
|
2016-10-06 11:31:23 +02:00
|
|
|
cmakeListsTxt.appendPath("CMakeLists.txt");
|
2014-10-24 13:15:54 +02:00
|
|
|
if (cmakeListsTxt.exists())
|
2013-01-08 17:21:18 +01:00
|
|
|
break;
|
|
|
|
|
QDir dir(baseDirectory.toString());
|
|
|
|
|
dir.cdUp();
|
2015-02-01 18:44:47 +02:00
|
|
|
baseDirectory = FileName::fromString(dir.absolutePath());
|
2013-01-08 17:21:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QDir srcDirRoot = QDir(project.toString());
|
|
|
|
|
QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString());
|
2013-08-16 17:45:16 +02:00
|
|
|
QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory().toString());
|
2016-01-15 16:12:54 +01:00
|
|
|
QString generatedFilePath = buildDir.absoluteFilePath(relativePath);
|
2013-01-08 17:21:18 +01:00
|
|
|
|
2016-10-06 11:31:23 +02:00
|
|
|
if (fi.suffix() == "ui") {
|
|
|
|
|
generatedFilePath += "/ui_";
|
2016-01-15 16:12:54 +01:00
|
|
|
generatedFilePath += fi.completeBaseName();
|
2016-10-06 11:31:23 +02:00
|
|
|
generatedFilePath += ".h";
|
2016-01-15 16:12:54 +01:00
|
|
|
return QStringList(QDir::cleanPath(generatedFilePath));
|
2016-10-06 11:31:23 +02:00
|
|
|
} else if (fi.suffix() == "scxml") {
|
|
|
|
|
generatedFilePath += "/";
|
2016-01-15 16:58:22 +01:00
|
|
|
generatedFilePath += QDir::cleanPath(fi.completeBaseName());
|
2017-02-22 15:09:35 +01:00
|
|
|
return QStringList({generatedFilePath + ".h",
|
|
|
|
|
generatedFilePath + ".cpp"});
|
2016-01-15 16:12:54 +01:00
|
|
|
} else {
|
|
|
|
|
// TODO: Other types will be added when adapters for their compilers become available.
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-28 11:16:18 +02:00
|
|
|
bool CMakeProject::mustUpdateCMakeStateBeforeBuild()
|
|
|
|
|
{
|
|
|
|
|
return m_delayedParsingTimer.isActive();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-20 15:03:55 +01:00
|
|
|
QList<ProjectExplorer::ExtraCompiler *> CMakeProject::findExtraCompilers() const
|
2016-01-15 16:12:54 +01:00
|
|
|
{
|
2019-01-20 15:03:55 +01:00
|
|
|
QList<ProjectExplorer::ExtraCompiler *> extraCompilers;
|
2017-03-27 17:12:52 +02:00
|
|
|
const QList<ExtraCompilerFactory *> factories =
|
2016-10-06 11:31:23 +02:00
|
|
|
ExtraCompilerFactory::extraCompilerFactories();
|
2016-01-15 16:12:54 +01:00
|
|
|
|
2017-03-27 17:12:52 +02:00
|
|
|
const QSet<QString> fileExtensions
|
2018-05-28 11:05:37 +02:00
|
|
|
= Utils::transform<QSet>(factories, &ExtraCompilerFactory::sourceTag);
|
2017-03-27 17:12:52 +02:00
|
|
|
|
2016-01-15 16:12:54 +01:00
|
|
|
// Find all files generated by any of the extra compilers, in a rather crude way.
|
2017-12-06 10:58:59 +01:00
|
|
|
const FileNameList fileList = files([&fileExtensions](const Node *n) {
|
|
|
|
|
if (!SourceFiles(n))
|
|
|
|
|
return false;
|
2017-05-03 13:46:02 +02:00
|
|
|
const QString fp = n->filePath().toString();
|
2017-03-27 17:12:52 +02:00
|
|
|
const int pos = fp.lastIndexOf('.');
|
|
|
|
|
return pos >= 0 && fileExtensions.contains(fp.mid(pos + 1));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Generate the necessary information:
|
2017-12-06 10:27:27 +01:00
|
|
|
for (const FileName &file : fileList) {
|
2017-03-27 17:12:52 +02:00
|
|
|
ExtraCompilerFactory *factory = Utils::findOrDefault(factories, [&file](const ExtraCompilerFactory *f) {
|
|
|
|
|
return file.endsWith('.' + f->sourceTag());
|
|
|
|
|
});
|
|
|
|
|
QTC_ASSERT(factory, continue);
|
|
|
|
|
|
2017-12-06 10:27:27 +01:00
|
|
|
QStringList generated = filesGeneratedFrom(file.toString());
|
2017-03-27 17:12:52 +02:00
|
|
|
if (generated.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
const FileNameList fileNames
|
|
|
|
|
= transform(generated,
|
|
|
|
|
[](const QString &s) { return FileName::fromString(s); });
|
2019-01-20 15:03:55 +01:00
|
|
|
extraCompilers.append(factory->create(this, file, fileNames));
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-20 15:03:55 +01:00
|
|
|
return extraCompilers;
|
2010-09-24 13:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-24 18:00:24 +01:00
|
|
|
} // namespace CMakeProjectManager
|