2017-02-06 16:59:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "cppprojectinfogenerator.h"
|
|
|
|
|
|
|
|
#include "cppprojectfilecategorizer.h"
|
|
|
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2018-08-13 11:15:27 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2018-09-27 10:18:44 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
namespace CppTools {
|
|
|
|
namespace Internal {
|
|
|
|
|
2019-08-29 09:59:45 +02:00
|
|
|
ProjectInfoGenerator::ProjectInfoGenerator(
|
|
|
|
const QFutureInterface<void> &futureInterface,
|
|
|
|
const ProjectExplorer::ProjectUpdateInfo &projectUpdateInfo)
|
2017-02-06 16:59:53 +01:00
|
|
|
: m_futureInterface(futureInterface)
|
|
|
|
, m_projectUpdateInfo(projectUpdateInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectInfo ProjectInfoGenerator::generate()
|
|
|
|
{
|
2017-10-27 13:31:11 +02:00
|
|
|
ProjectInfo projectInfo(m_projectUpdateInfo.project);
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
for (const ProjectExplorer::RawProjectPart &rpp : m_projectUpdateInfo.rawProjectParts) {
|
2017-02-06 16:59:53 +01:00
|
|
|
if (m_futureInterface.isCanceled())
|
|
|
|
return ProjectInfo();
|
|
|
|
|
2017-10-27 13:31:11 +02:00
|
|
|
for (ProjectPart::Ptr part : createProjectParts(rpp))
|
|
|
|
projectInfo.appendProjectPart(part);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
2017-10-27 13:31:11 +02:00
|
|
|
return projectInfo;
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
static ProjectPart::Ptr projectPartFromRawProjectPart(
|
|
|
|
const ProjectExplorer::RawProjectPart &rawProjectPart, ProjectExplorer::Project *project)
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
|
|
|
ProjectPart::Ptr part(new ProjectPart);
|
2017-02-21 12:26:04 +01:00
|
|
|
part->project = project;
|
2017-02-06 16:59:53 +01:00
|
|
|
part->projectFile = rawProjectPart.projectFile;
|
|
|
|
part->projectConfigFile = rawProjectPart.projectConfigFile;
|
2017-02-27 14:02:38 +01:00
|
|
|
part->projectFileLine = rawProjectPart.projectFileLine;
|
|
|
|
part->projectFileColumn = rawProjectPart.projectFileColumn;
|
2017-02-27 14:37:41 +01:00
|
|
|
part->callGroupId = rawProjectPart.callGroupId;
|
2017-02-27 14:46:45 +01:00
|
|
|
part->buildSystemTarget = rawProjectPart.buildSystemTarget;
|
2017-08-29 12:11:27 +02:00
|
|
|
part->buildTargetType = rawProjectPart.buildTargetType;
|
2017-02-06 16:59:53 +01:00
|
|
|
part->qtVersion = rawProjectPart.qtVersion;
|
2017-02-07 15:00:38 +01:00
|
|
|
part->projectMacros = rawProjectPart.projectMacros;
|
2017-11-23 17:21:35 +02:00
|
|
|
if (!part->projectConfigFile.isEmpty())
|
|
|
|
part->projectMacros += ProjectExplorer::Macro::toMacros(ProjectPart::readProjectConfigFile(part));
|
2017-02-06 16:59:53 +01:00
|
|
|
part->headerPaths = rawProjectPart.headerPaths;
|
|
|
|
part->precompiledHeaders = rawProjectPart.precompiledHeaders;
|
|
|
|
part->selectedForBuilding = rawProjectPart.selectedForBuilding;
|
|
|
|
|
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
2019-08-28 18:22:45 +02:00
|
|
|
QVector<ProjectPart::Ptr> ProjectInfoGenerator::createProjectParts(
|
|
|
|
const ProjectExplorer::RawProjectPart &rawProjectPart)
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2019-01-09 18:31:20 +01:00
|
|
|
using Utils::LanguageExtension;
|
2018-10-08 09:49:02 +02:00
|
|
|
|
2017-10-27 13:31:11 +02:00
|
|
|
QVector<ProjectPart::Ptr> result;
|
2017-02-06 16:59:53 +01:00
|
|
|
ProjectFileCategorizer cat(rawProjectPart.displayName,
|
|
|
|
rawProjectPart.files,
|
2019-08-28 12:23:37 +02:00
|
|
|
rawProjectPart.fileIsActive);
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2019-05-09 10:24:57 +02:00
|
|
|
if (!cat.hasParts())
|
|
|
|
return result;
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2019-05-09 10:24:57 +02:00
|
|
|
const ProjectPart::Ptr part = projectPartFromRawProjectPart(rawProjectPart,
|
|
|
|
m_projectUpdateInfo.project);
|
|
|
|
|
|
|
|
if (m_projectUpdateInfo.cxxToolChain) {
|
2017-02-06 16:59:53 +01:00
|
|
|
if (cat.hasCxxSources()) {
|
2017-10-27 13:31:11 +02:00
|
|
|
result << createProjectPart(rawProjectPart,
|
|
|
|
part,
|
|
|
|
cat.cxxSources(),
|
|
|
|
cat.partName("C++"),
|
2018-10-08 10:54:27 +02:00
|
|
|
Language::Cxx,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::None);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
if (cat.hasObjcxxSources()) {
|
2017-10-27 13:31:11 +02:00
|
|
|
result << createProjectPart(rawProjectPart,
|
|
|
|
part,
|
|
|
|
cat.objcxxSources(),
|
|
|
|
cat.partName("Obj-C++"),
|
2018-10-08 10:54:27 +02:00
|
|
|
Language::Cxx,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::ObjectiveC);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
2019-05-09 10:24:57 +02:00
|
|
|
}
|
2017-02-06 16:59:53 +01:00
|
|
|
|
2019-05-09 10:24:57 +02:00
|
|
|
if (m_projectUpdateInfo.cToolChain) {
|
2017-02-06 16:59:53 +01:00
|
|
|
if (cat.hasCSources()) {
|
2017-10-27 13:31:11 +02:00
|
|
|
result << createProjectPart(rawProjectPart,
|
|
|
|
part,
|
|
|
|
cat.cSources(),
|
|
|
|
cat.partName("C"),
|
2018-09-27 10:18:44 +02:00
|
|
|
Language::C,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::None);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cat.hasObjcSources()) {
|
2017-10-27 13:31:11 +02:00
|
|
|
result << createProjectPart(rawProjectPart,
|
|
|
|
part,
|
|
|
|
cat.objcSources(),
|
|
|
|
cat.partName("Obj-C"),
|
2018-09-27 10:18:44 +02:00
|
|
|
Language::C,
|
2018-10-08 09:49:02 +02:00
|
|
|
LanguageExtension::ObjectiveC);
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 10:24:57 +02:00
|
|
|
|
2017-10-27 13:31:11 +02:00
|
|
|
return result;
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
2018-10-08 09:49:02 +02:00
|
|
|
ProjectPart::Ptr ProjectInfoGenerator::createProjectPart(
|
2019-08-28 18:22:45 +02:00
|
|
|
const ProjectExplorer::RawProjectPart &rawProjectPart,
|
2018-10-08 09:49:02 +02:00
|
|
|
const ProjectPart::Ptr &templateProjectPart,
|
|
|
|
const ProjectFiles &projectFiles,
|
|
|
|
const QString &partName,
|
|
|
|
Language language,
|
2019-01-09 18:31:20 +01:00
|
|
|
Utils::LanguageExtensions languageExtensions)
|
2017-02-06 16:59:53 +01:00
|
|
|
{
|
2019-08-28 18:22:45 +02:00
|
|
|
ProjectExplorer::RawProjectPartFlags flags;
|
2019-08-29 09:59:45 +02:00
|
|
|
ProjectExplorer::ToolChainInfo tcInfo;
|
2018-09-27 10:18:44 +02:00
|
|
|
if (language == Language::C) {
|
2017-02-06 16:59:53 +01:00
|
|
|
flags = rawProjectPart.flagsForC;
|
|
|
|
tcInfo = m_projectUpdateInfo.cToolChainInfo;
|
|
|
|
}
|
|
|
|
// Use Cxx toolchain for C projects without C compiler in kit and for C++ code
|
|
|
|
if (!tcInfo.isValid()) {
|
|
|
|
flags = rawProjectPart.flagsForCxx;
|
|
|
|
tcInfo = m_projectUpdateInfo.cxxToolChainInfo;
|
|
|
|
}
|
|
|
|
// TODO: If no toolchain is set, show a warning
|
2018-10-08 11:04:03 +02:00
|
|
|
|
|
|
|
ProjectPart::Ptr part(templateProjectPart->copy());
|
|
|
|
part->displayName = partName;
|
|
|
|
part->files = projectFiles;
|
|
|
|
part->toolchainType = tcInfo.type;
|
|
|
|
part->isMsvc2015Toolchain = tcInfo.isMsvc2015ToolChain;
|
|
|
|
part->toolChainWordWidth = tcInfo.wordWidth == 64 ? ProjectPart::WordWidth64Bit
|
|
|
|
: ProjectPart::WordWidth32Bit;
|
|
|
|
part->toolChainTargetTriple = tcInfo.targetTriple;
|
|
|
|
part->extraCodeModelFlags = tcInfo.extraCodeModelFlags;
|
2019-01-08 16:22:39 +01:00
|
|
|
part->compilerFlags = flags.commandLineFlags;
|
2018-10-08 11:04:03 +02:00
|
|
|
part->warningFlags = flags.warningFlags;
|
2018-12-17 12:06:57 +01:00
|
|
|
part->language = language;
|
2018-10-08 11:04:03 +02:00
|
|
|
part->languageExtensions = flags.languageExtensions;
|
|
|
|
|
|
|
|
// Toolchain macros and language version
|
|
|
|
if (tcInfo.macroInspectionRunner) {
|
|
|
|
auto macroInspectionReport = tcInfo.macroInspectionRunner(flags.commandLineFlags);
|
|
|
|
part->toolChainMacros = macroInspectionReport.macros;
|
|
|
|
part->languageVersion = macroInspectionReport.languageVersion;
|
|
|
|
// No compiler set in kit.
|
|
|
|
} else if (language == Language::C) {
|
2019-01-09 18:31:20 +01:00
|
|
|
part->languageVersion = Utils::LanguageVersion::LatestC;
|
2018-10-08 11:04:03 +02:00
|
|
|
} else {
|
2019-01-09 18:31:20 +01:00
|
|
|
part->languageVersion = Utils::LanguageVersion::LatestCxx;
|
2018-10-08 11:04:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Header paths
|
|
|
|
if (tcInfo.headerPathsRunner) {
|
|
|
|
const ProjectExplorer::HeaderPaths builtInHeaderPaths
|
2019-04-25 16:06:39 +02:00
|
|
|
= tcInfo.headerPathsRunner(flags.commandLineFlags,
|
|
|
|
tcInfo.sysRootPath,
|
|
|
|
tcInfo.targetTriple);
|
2018-10-08 11:04:03 +02:00
|
|
|
|
|
|
|
ProjectExplorer::HeaderPaths &headerPaths = part->headerPaths;
|
|
|
|
for (const ProjectExplorer::HeaderPath &header : builtInHeaderPaths) {
|
|
|
|
const ProjectExplorer::HeaderPath headerPath{header.path, header.type};
|
|
|
|
if (!headerPaths.contains(headerPath))
|
|
|
|
headerPaths.push_back(headerPath);
|
|
|
|
}
|
|
|
|
}
|
2017-02-06 16:59:53 +01:00
|
|
|
|
|
|
|
part->languageExtensions |= languageExtensions;
|
|
|
|
part->updateLanguageFeatures();
|
|
|
|
|
2017-10-27 13:31:11 +02:00
|
|
|
return part;
|
2017-02-06 16:59:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
} // namespace CppTools
|