2016-01-13 14:12:15 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2016-01-13 14:12:15 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
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.
|
2016-01-13 14:12:15 +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.
|
2016-01-13 14:12:15 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
2016-01-13 14:32:28 +01:00
|
|
|
|
2016-01-13 14:12:15 +01:00
|
|
|
#include "projectpart.h"
|
|
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
|
2017-02-07 15:00:38 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
|
2016-12-05 16:08:01 +01:00
|
|
|
#include <QFile>
|
2016-01-13 14:12:15 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
2021-05-06 12:56:21 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2016-01-13 14:12:15 +01:00
|
|
|
namespace CppTools {
|
|
|
|
|
|
|
|
|
|
QString ProjectPart::id() const
|
|
|
|
|
{
|
2017-03-09 14:13:22 +01:00
|
|
|
QString projectPartId = projectFileLocation();
|
2016-01-13 14:12:15 +01:00
|
|
|
if (!displayName.isEmpty())
|
|
|
|
|
projectPartId.append(QLatin1Char(' ') + displayName);
|
|
|
|
|
return projectPartId;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 14:13:22 +01:00
|
|
|
QString ProjectPart::projectFileLocation() const
|
|
|
|
|
{
|
|
|
|
|
QString location = QDir::fromNativeSeparators(projectFile);
|
|
|
|
|
if (projectFileLine > 0)
|
|
|
|
|
location += ":" + QString::number(projectFileLine);
|
|
|
|
|
if (projectFileColumn > 0)
|
|
|
|
|
location += ":" + QString::number(projectFileColumn);
|
|
|
|
|
return location;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
bool ProjectPart::belongsToProject(const ProjectExplorer::Project *project) const
|
|
|
|
|
{
|
|
|
|
|
return project && topLevelProject == project->projectFilePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray ProjectPart::readProjectConfigFile(const QString &projectConfigFile)
|
2016-01-13 14:12:15 +01:00
|
|
|
{
|
|
|
|
|
QByteArray result;
|
|
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
QFile f(projectConfigFile);
|
2016-01-13 14:12:15 +01:00
|
|
|
if (f.open(QIODevice::ReadOnly)) {
|
|
|
|
|
QTextStream is(&f);
|
|
|
|
|
result = is.readAll().toUtf8();
|
|
|
|
|
f.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 16:10:07 +02:00
|
|
|
// TODO: Why do we keep the file *and* the resulting macros? Why do we read the file
|
|
|
|
|
// in several places?
|
|
|
|
|
static Macros getProjectMacros(const RawProjectPart &rpp)
|
|
|
|
|
{
|
|
|
|
|
Macros macros = rpp.projectMacros;
|
|
|
|
|
if (!rpp.projectConfigFile.isEmpty())
|
|
|
|
|
macros += Macro::toMacros(ProjectPart::readProjectConfigFile(rpp.projectConfigFile));
|
|
|
|
|
return macros;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HeaderPaths getHeaderPaths(const RawProjectPart &rpp,
|
|
|
|
|
const RawProjectPartFlags &flags,
|
|
|
|
|
const ProjectExplorer::ToolChainInfo &tcInfo)
|
|
|
|
|
{
|
|
|
|
|
HeaderPaths headerPaths;
|
|
|
|
|
|
|
|
|
|
// Prevent duplicate include paths.
|
|
|
|
|
// TODO: Do this once when finalizing the raw project part?
|
|
|
|
|
std::set<QString> seenPaths;
|
|
|
|
|
for (const HeaderPath &p : qAsConst(rpp.headerPaths)) {
|
|
|
|
|
const QString cleanPath = QDir::cleanPath(p.path);
|
|
|
|
|
if (seenPaths.insert(cleanPath).second)
|
|
|
|
|
headerPaths << HeaderPath(cleanPath, p.type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tcInfo.headerPathsRunner) {
|
|
|
|
|
const HeaderPaths builtInHeaderPaths = tcInfo.headerPathsRunner(
|
|
|
|
|
flags.commandLineFlags, tcInfo.sysRootPath, tcInfo.targetTriple);
|
|
|
|
|
for (const HeaderPath &header : builtInHeaderPaths) {
|
|
|
|
|
if (seenPaths.insert(header.path).second)
|
|
|
|
|
headerPaths.push_back(HeaderPath{header.path, header.type});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return headerPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ToolChain::MacroInspectionReport getToolchainMacros(
|
|
|
|
|
const RawProjectPartFlags &flags, const ToolChainInfo &tcInfo, Utils::Language language)
|
|
|
|
|
{
|
|
|
|
|
ToolChain::MacroInspectionReport report;
|
|
|
|
|
if (tcInfo.macroInspectionRunner) {
|
|
|
|
|
report = tcInfo.macroInspectionRunner(flags.commandLineFlags);
|
|
|
|
|
} else if (language == Utils::Language::C) { // No compiler set in kit.
|
|
|
|
|
report.languageVersion = Utils::LanguageVersion::LatestC;
|
|
|
|
|
} else {
|
|
|
|
|
report.languageVersion = Utils::LanguageVersion::LatestCxx;
|
|
|
|
|
}
|
|
|
|
|
return report;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectPart::ProjectPart(const Utils::FilePath &topLevelProject,
|
|
|
|
|
const RawProjectPart &rpp,
|
|
|
|
|
const QString &displayName,
|
|
|
|
|
const ProjectFiles &files,
|
|
|
|
|
Utils::Language language,
|
|
|
|
|
Utils::LanguageExtensions languageExtensions,
|
|
|
|
|
const RawProjectPartFlags &flags,
|
|
|
|
|
const ToolChainInfo &tcInfo)
|
|
|
|
|
: topLevelProject(topLevelProject),
|
|
|
|
|
displayName(displayName),
|
|
|
|
|
projectFile(rpp.projectFile),
|
|
|
|
|
projectConfigFile(rpp.projectConfigFile),
|
|
|
|
|
projectFileLine(rpp.projectFileLine),
|
|
|
|
|
projectFileColumn(rpp.projectFileColumn),
|
|
|
|
|
callGroupId(rpp.callGroupId),
|
|
|
|
|
language(language),
|
|
|
|
|
languageExtensions(languageExtensions | flags.languageExtensions),
|
|
|
|
|
qtVersion(rpp.qtVersion),
|
|
|
|
|
files(files),
|
|
|
|
|
includedFiles(rpp.includedFiles),
|
|
|
|
|
precompiledHeaders(rpp.precompiledHeaders),
|
|
|
|
|
headerPaths(getHeaderPaths(rpp, flags, tcInfo)),
|
|
|
|
|
projectMacros(getProjectMacros(rpp)),
|
|
|
|
|
buildSystemTarget(rpp.buildSystemTarget),
|
|
|
|
|
buildTargetType(rpp.buildTargetType),
|
|
|
|
|
selectedForBuilding(rpp.selectedForBuilding),
|
|
|
|
|
toolchainType(tcInfo.type),
|
|
|
|
|
isMsvc2015Toolchain(tcInfo.isMsvc2015ToolChain),
|
|
|
|
|
toolChainTargetTriple(tcInfo.targetTriple),
|
|
|
|
|
toolChainWordWidth(tcInfo.wordWidth == 64 ? ProjectPart::WordWidth64Bit
|
|
|
|
|
: ProjectPart::WordWidth32Bit),
|
|
|
|
|
toolChainInstallDir(tcInfo.installDir),
|
|
|
|
|
compilerFilePath(tcInfo.compilerFilePath),
|
|
|
|
|
warningFlags(flags.warningFlags),
|
|
|
|
|
extraCodeModelFlags(tcInfo.extraCodeModelFlags),
|
|
|
|
|
compilerFlags(flags.commandLineFlags),
|
|
|
|
|
m_macroReport(getToolchainMacros(flags, tcInfo, language)),
|
|
|
|
|
languageFeatures(deriveLanguageFeatures())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CPlusPlus::LanguageFeatures ProjectPart::deriveLanguageFeatures() const
|
|
|
|
|
{
|
|
|
|
|
const bool hasCxx = languageVersion >= Utils::LanguageVersion::CXX98;
|
|
|
|
|
const bool hasQt = hasCxx && qtVersion != Utils::QtVersion::None;
|
|
|
|
|
CPlusPlus::LanguageFeatures features;
|
|
|
|
|
features.cxx11Enabled = languageVersion >= Utils::LanguageVersion::CXX11;
|
|
|
|
|
features.cxx14Enabled = languageVersion >= Utils::LanguageVersion::CXX14;
|
|
|
|
|
features.cxxEnabled = hasCxx;
|
|
|
|
|
features.c99Enabled = languageVersion >= Utils::LanguageVersion::C99;
|
|
|
|
|
features.objCEnabled = languageExtensions.testFlag(Utils::LanguageExtension::ObjectiveC);
|
|
|
|
|
features.qtEnabled = hasQt;
|
|
|
|
|
features.qtMocRunEnabled = hasQt;
|
|
|
|
|
if (!hasQt) {
|
|
|
|
|
features.qtKeywordsEnabled = false;
|
|
|
|
|
} else {
|
|
|
|
|
features.qtKeywordsEnabled = !Utils::contains(projectMacros,
|
|
|
|
|
[] (const ProjectExplorer::Macro ¯o) { return macro.key == "QT_NO_KEYWORDS"; });
|
|
|
|
|
}
|
|
|
|
|
return features;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-13 14:12:15 +01:00
|
|
|
} // namespace CppTools
|