2014-07-30 17:13:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2014-07-30 17:13:45 +02: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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-15 14:46:23 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2014-07-30 17:13:45 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-15 14:46:23 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2014-07-30 17:13:45 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2014-07-30 17:13:45 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppprojects.h"
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/headerpath.h>
|
2014-06-18 16:16:55 +02:00
|
|
|
#include <projectexplorer/kit.h>
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/kitmanager.h>
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <projectexplorer/project.h>
|
2014-06-18 16:16:55 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2014-07-30 17:13:45 +02:00
|
|
|
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <utils/fileutils.h>
|
2015-01-05 11:54:52 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <QDir>
|
2014-07-30 17:13:45 +02:00
|
|
|
#include <QSet>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
|
2014-06-18 16:16:55 +02:00
|
|
|
using namespace CppTools;
|
2015-02-05 16:32:18 +01:00
|
|
|
using namespace CppTools::Internal;
|
2014-06-18 16:16:55 +02:00
|
|
|
using namespace ProjectExplorer;
|
2014-07-30 17:13:45 +02:00
|
|
|
|
2014-06-18 16:16:55 +02:00
|
|
|
|
2014-07-30 17:13:45 +02:00
|
|
|
|
|
|
|
|
ProjectInfo::ProjectInfo()
|
|
|
|
|
{}
|
|
|
|
|
|
2015-02-04 17:01:07 +02:00
|
|
|
ProjectInfo::ProjectInfo(QPointer<Project> project)
|
2014-07-30 17:13:45 +02:00
|
|
|
: m_project(project)
|
|
|
|
|
{}
|
|
|
|
|
|
2014-10-28 12:29:23 +01:00
|
|
|
bool ProjectInfo::operator ==(const ProjectInfo &other) const
|
|
|
|
|
{
|
|
|
|
|
return m_project == other.m_project
|
|
|
|
|
&& m_projectParts == other.m_projectParts
|
|
|
|
|
&& m_compilerCallData == other.m_compilerCallData
|
|
|
|
|
&& m_headerPaths == other.m_headerPaths
|
|
|
|
|
&& m_sourceFiles == other.m_sourceFiles
|
|
|
|
|
&& m_defines == other.m_defines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectInfo::operator !=(const ProjectInfo &other) const
|
|
|
|
|
{
|
|
|
|
|
return !operator ==(other);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectInfo::definesChanged(const ProjectInfo &other) const
|
|
|
|
|
{
|
|
|
|
|
return m_defines != other.m_defines;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectInfo::configurationChanged(const ProjectInfo &other) const
|
|
|
|
|
{
|
|
|
|
|
return definesChanged(other) || m_headerPaths != other.m_headerPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProjectInfo::configurationOrFilesChanged(const ProjectInfo &other) const
|
|
|
|
|
{
|
|
|
|
|
return configurationChanged(other) || m_sourceFiles != other.m_sourceFiles;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 17:13:45 +02:00
|
|
|
bool ProjectInfo::isValid() const
|
|
|
|
|
{
|
|
|
|
|
return !m_project.isNull();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 17:01:07 +02:00
|
|
|
QPointer<Project> ProjectInfo::project() const
|
2014-07-30 17:13:45 +02:00
|
|
|
{
|
|
|
|
|
return m_project;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QList<ProjectPart::Ptr> ProjectInfo::projectParts() const
|
|
|
|
|
{
|
|
|
|
|
return m_projectParts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectInfo::appendProjectPart(const ProjectPart::Ptr &part)
|
|
|
|
|
{
|
2014-09-12 14:14:18 +02:00
|
|
|
if (part)
|
|
|
|
|
m_projectParts.append(part);
|
|
|
|
|
}
|
2014-07-30 17:13:45 +02:00
|
|
|
|
2014-09-12 14:14:18 +02:00
|
|
|
void ProjectInfo::finish()
|
|
|
|
|
{
|
2016-01-13 14:12:15 +01:00
|
|
|
typedef ProjectPartHeaderPath HeaderPath;
|
2014-07-30 17:13:45 +02:00
|
|
|
|
2014-09-12 14:14:18 +02:00
|
|
|
QSet<HeaderPath> incs;
|
|
|
|
|
foreach (const ProjectPart::Ptr &part, m_projectParts) {
|
2015-02-15 23:43:26 +02:00
|
|
|
part->updateLanguageFeatures();
|
2014-09-12 14:14:18 +02:00
|
|
|
// Update header paths
|
|
|
|
|
foreach (const HeaderPath &hp, part->headerPaths) {
|
|
|
|
|
if (!incs.contains(hp)) {
|
|
|
|
|
incs.insert(hp);
|
|
|
|
|
m_headerPaths += hp;
|
|
|
|
|
}
|
2014-07-30 17:13:45 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-12 14:14:18 +02:00
|
|
|
// Update source files
|
|
|
|
|
foreach (const ProjectFile &file, part->files)
|
|
|
|
|
m_sourceFiles.insert(file.path);
|
|
|
|
|
|
|
|
|
|
// Update defines
|
|
|
|
|
m_defines.append(part->toolchainDefines);
|
|
|
|
|
m_defines.append(part->projectDefines);
|
|
|
|
|
if (!part->projectConfigFile.isEmpty()) {
|
|
|
|
|
m_defines.append('\n');
|
|
|
|
|
m_defines += ProjectPart::readProjectConfigFile(part);
|
|
|
|
|
m_defines.append('\n');
|
|
|
|
|
}
|
2014-07-30 17:13:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-13 14:12:15 +01:00
|
|
|
const ProjectPartHeaderPaths ProjectInfo::headerPaths() const
|
2014-07-30 17:13:45 +02:00
|
|
|
{
|
|
|
|
|
return m_headerPaths;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-04 14:59:50 +02:00
|
|
|
const QSet<QString> ProjectInfo::sourceFiles() const
|
2014-07-30 17:13:45 +02:00
|
|
|
{
|
|
|
|
|
return m_sourceFiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QByteArray ProjectInfo::defines() const
|
|
|
|
|
{
|
|
|
|
|
return m_defines;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 12:29:23 +01:00
|
|
|
void ProjectInfo::setCompilerCallData(const CompilerCallData &data)
|
|
|
|
|
{
|
|
|
|
|
m_compilerCallData = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProjectInfo::CompilerCallData ProjectInfo::compilerCallData() const
|
|
|
|
|
{
|
|
|
|
|
return m_compilerCallData;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 16:16:55 +02:00
|
|
|
namespace {
|
|
|
|
|
class ProjectFileCategorizer
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ProjectFileCategorizer(const QString &partName, const QStringList &files)
|
|
|
|
|
: m_partName(partName)
|
|
|
|
|
{
|
|
|
|
|
using CppTools::ProjectFile;
|
|
|
|
|
|
|
|
|
|
QStringList cHeaders, cxxHeaders;
|
|
|
|
|
|
|
|
|
|
foreach (const QString &file, files) {
|
|
|
|
|
switch (ProjectFile::classify(file)) {
|
|
|
|
|
case ProjectFile::CSource: m_cSources += file; break;
|
|
|
|
|
case ProjectFile::CHeader: cHeaders += file; break;
|
|
|
|
|
case ProjectFile::CXXSource: m_cxxSources += file; break;
|
|
|
|
|
case ProjectFile::CXXHeader: cxxHeaders += file; break;
|
|
|
|
|
case ProjectFile::ObjCSource: m_objcSources += file; break;
|
|
|
|
|
case ProjectFile::ObjCXXSource: m_objcxxSources += file; break;
|
|
|
|
|
default:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool hasC = !m_cSources.isEmpty();
|
|
|
|
|
const bool hasCxx = !m_cxxSources.isEmpty();
|
|
|
|
|
const bool hasObjc = !m_objcSources.isEmpty();
|
|
|
|
|
const bool hasObjcxx = !m_objcxxSources.isEmpty();
|
|
|
|
|
|
|
|
|
|
if (hasObjcxx)
|
|
|
|
|
m_objcxxSources += cxxHeaders + cHeaders;
|
|
|
|
|
if (hasCxx)
|
|
|
|
|
m_cxxSources += cxxHeaders + cHeaders;
|
|
|
|
|
else if (!hasObjcxx)
|
|
|
|
|
m_cxxSources += cxxHeaders;
|
|
|
|
|
if (hasObjc)
|
|
|
|
|
m_objcSources += cHeaders;
|
|
|
|
|
if (hasC || (!hasObjc && !hasObjcxx && !hasCxx))
|
|
|
|
|
m_cSources += cHeaders;
|
|
|
|
|
|
|
|
|
|
m_partCount =
|
|
|
|
|
(m_cSources.isEmpty() ? 0 : 1) +
|
|
|
|
|
(m_cxxSources.isEmpty() ? 0 : 1) +
|
|
|
|
|
(m_objcSources.isEmpty() ? 0 : 1) +
|
|
|
|
|
(m_objcxxSources.isEmpty() ? 0 : 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool hasCSources() const { return !m_cSources.isEmpty(); }
|
|
|
|
|
bool hasCxxSources() const { return !m_cxxSources.isEmpty(); }
|
|
|
|
|
bool hasObjcSources() const { return !m_objcSources.isEmpty(); }
|
|
|
|
|
bool hasObjcxxSources() const { return !m_objcxxSources.isEmpty(); }
|
|
|
|
|
|
|
|
|
|
QStringList cSources() const { return m_cSources; }
|
|
|
|
|
QStringList cxxSources() const { return m_cxxSources; }
|
|
|
|
|
QStringList objcSources() const { return m_objcSources; }
|
|
|
|
|
QStringList objcxxSources() const { return m_objcxxSources; }
|
|
|
|
|
|
|
|
|
|
bool hasMultipleParts() const { return m_partCount > 1; }
|
|
|
|
|
bool hasNoParts() const { return m_partCount == 0; }
|
|
|
|
|
|
|
|
|
|
QString partName(const QString &languageName) const
|
|
|
|
|
{
|
|
|
|
|
if (hasMultipleParts())
|
|
|
|
|
return QString::fromLatin1("%1 (%2)").arg(m_partName).arg(languageName);
|
|
|
|
|
|
|
|
|
|
return m_partName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString m_partName;
|
|
|
|
|
QStringList m_cSources, m_cxxSources, m_objcSources, m_objcxxSources;
|
|
|
|
|
int m_partCount;
|
|
|
|
|
};
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
ProjectPartBuilder::ProjectPartBuilder(ProjectInfo &pInfo)
|
|
|
|
|
: m_templatePart(new ProjectPart)
|
|
|
|
|
, m_pInfo(pInfo)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->project = pInfo.project();
|
|
|
|
|
m_templatePart->displayName = pInfo.project()->displayName();
|
|
|
|
|
m_templatePart->projectFile = pInfo.project()->projectFilePath().toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setQtVersion(ProjectPart::QtVersion qtVersion)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->qtVersion = qtVersion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setCFlags(const QStringList &flags)
|
|
|
|
|
{
|
|
|
|
|
m_cFlags = flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setCxxFlags(const QStringList &flags)
|
|
|
|
|
{
|
|
|
|
|
m_cxxFlags = flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setDefines(const QByteArray &defines)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->projectDefines = defines;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-13 14:12:15 +01:00
|
|
|
void ProjectPartBuilder::setHeaderPaths(const ProjectPartHeaderPaths &headerPaths)
|
2014-06-18 16:16:55 +02:00
|
|
|
{
|
|
|
|
|
m_templatePart->headerPaths = headerPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setIncludePaths(const QStringList &includePaths)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->headerPaths.clear();
|
|
|
|
|
|
|
|
|
|
foreach (const QString &includeFile, includePaths) {
|
2016-01-13 14:12:15 +01:00
|
|
|
ProjectPartHeaderPath hp(includeFile, ProjectPartHeaderPath::IncludePath);
|
2014-06-18 16:16:55 +02:00
|
|
|
|
|
|
|
|
// The simple project managers are utterly ignorant of frameworks on OSX, and won't report
|
|
|
|
|
// framework paths. The work-around is to check if the include path ends in ".framework",
|
|
|
|
|
// and if so, add the parent directory as framework path.
|
|
|
|
|
if (includeFile.endsWith(QLatin1String(".framework"))) {
|
|
|
|
|
const int slashIdx = includeFile.lastIndexOf(QLatin1Char('/'));
|
|
|
|
|
if (slashIdx != -1) {
|
2016-01-13 14:12:15 +01:00
|
|
|
hp = ProjectPartHeaderPath(includeFile.left(slashIdx),
|
|
|
|
|
ProjectPartHeaderPath::FrameworkPath);
|
2014-06-18 16:16:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_templatePart->headerPaths += hp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setPreCompiledHeaders(const QStringList &pchs)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->precompiledHeaders = pchs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setProjectFile(const QString &projectFile)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->projectFile = projectFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setDisplayName(const QString &displayName)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->displayName = displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::setConfigFileName(const QString &configFileName)
|
|
|
|
|
{
|
|
|
|
|
m_templatePart->projectConfigFile = configFileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Core::Id> ProjectPartBuilder::createProjectPartsForFiles(const QStringList &files)
|
|
|
|
|
{
|
|
|
|
|
QList<Core::Id> languages;
|
|
|
|
|
|
|
|
|
|
ProjectFileCategorizer cat(m_templatePart->displayName, files);
|
|
|
|
|
if (cat.hasNoParts())
|
|
|
|
|
return languages;
|
|
|
|
|
|
|
|
|
|
using CppTools::ProjectFile;
|
|
|
|
|
using CppTools::ProjectPart;
|
|
|
|
|
|
|
|
|
|
if (cat.hasCSources()) {
|
|
|
|
|
createProjectPart(cat.cSources(),
|
|
|
|
|
cat.partName(QCoreApplication::translate("CppTools", "C11")),
|
|
|
|
|
ProjectPart::C11,
|
2014-08-21 16:26:06 +02:00
|
|
|
ProjectPart::NoExtensions);
|
2014-06-18 16:16:55 +02:00
|
|
|
// TODO: there is no C...
|
|
|
|
|
// languages += ProjectExplorer::Constants::LANG_C;
|
|
|
|
|
}
|
|
|
|
|
if (cat.hasObjcSources()) {
|
|
|
|
|
createProjectPart(cat.objcSources(),
|
|
|
|
|
cat.partName(QCoreApplication::translate("CppTools", "Obj-C11")),
|
|
|
|
|
ProjectPart::C11,
|
2014-08-21 16:26:06 +02:00
|
|
|
ProjectPart::ObjectiveCExtensions);
|
2014-06-18 16:16:55 +02:00
|
|
|
// TODO: there is no Ojective-C...
|
|
|
|
|
// languages += ProjectExplorer::Constants::LANG_OBJC;
|
|
|
|
|
}
|
|
|
|
|
if (cat.hasCxxSources()) {
|
|
|
|
|
createProjectPart(cat.cxxSources(),
|
|
|
|
|
cat.partName(QCoreApplication::translate("CppTools", "C++11")),
|
2014-08-21 16:26:06 +02:00
|
|
|
ProjectPart::CXX11,
|
|
|
|
|
ProjectPart::NoExtensions);
|
2014-06-18 16:16:55 +02:00
|
|
|
languages += ProjectExplorer::Constants::LANG_CXX;
|
|
|
|
|
}
|
|
|
|
|
if (cat.hasObjcxxSources()) {
|
|
|
|
|
createProjectPart(cat.objcxxSources(),
|
|
|
|
|
cat.partName(QCoreApplication::translate("CppTools", "Obj-C++11")),
|
2014-08-21 16:26:06 +02:00
|
|
|
ProjectPart::CXX11,
|
|
|
|
|
ProjectPart::ObjectiveCExtensions);
|
2014-06-18 16:16:55 +02:00
|
|
|
// TODO: there is no Objective-C++...
|
|
|
|
|
languages += ProjectExplorer::Constants::LANG_CXX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return languages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProjectPartBuilder::createProjectPart(const QStringList &theSources,
|
|
|
|
|
const QString &partName,
|
2014-08-21 16:26:06 +02:00
|
|
|
ProjectPart::LanguageVersion languageVersion,
|
|
|
|
|
ProjectPart::LanguageExtensions languageExtensions)
|
2014-06-18 16:16:55 +02:00
|
|
|
{
|
2015-02-04 17:01:07 +02:00
|
|
|
ProjectPart::Ptr part(m_templatePart->copy());
|
2014-06-18 16:16:55 +02:00
|
|
|
part->displayName = partName;
|
|
|
|
|
|
2015-01-05 11:54:52 +01:00
|
|
|
QTC_ASSERT(part->project, return);
|
2015-02-04 17:01:07 +02:00
|
|
|
if (Target *activeTarget = part->project->activeTarget()) {
|
2015-01-05 11:54:52 +01:00
|
|
|
if (Kit *kit = activeTarget->kit()) {
|
|
|
|
|
if (ToolChain *toolChain = ToolChainKitInformation::toolChain(kit)) {
|
|
|
|
|
const QStringList flags = languageVersion >= ProjectPart::CXX98 ? m_cxxFlags
|
|
|
|
|
: m_cFlags;
|
|
|
|
|
part->evaluateToolchain(toolChain, flags, SysRootKitInformation::sysRoot(kit));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-18 16:16:55 +02:00
|
|
|
|
2014-08-21 16:26:06 +02:00
|
|
|
part->languageExtensions |= languageExtensions;
|
2014-06-18 16:16:55 +02:00
|
|
|
|
2015-02-04 17:01:07 +02:00
|
|
|
ProjectFileAdder adder(part->files);
|
2014-06-18 16:16:55 +02:00
|
|
|
foreach (const QString &file, theSources)
|
|
|
|
|
adder.maybeAdd(file);
|
|
|
|
|
|
|
|
|
|
m_pInfo.appendProjectPart(part);
|
|
|
|
|
}
|
2014-10-16 15:27:19 +02:00
|
|
|
|
|
|
|
|
|
2015-11-05 11:47:01 +01:00
|
|
|
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart)
|
2015-06-25 13:46:22 +02:00
|
|
|
: m_projectPart(projectPart)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList CompilerOptionsBuilder::options() const
|
|
|
|
|
{
|
|
|
|
|
return m_options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompilerOptionsBuilder::add(const QString &option)
|
|
|
|
|
{
|
|
|
|
|
m_options.append(option);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
QString CompilerOptionsBuilder::defineLineToDefineOption(const QByteArray &defineLine)
|
|
|
|
|
{
|
|
|
|
|
QByteArray str = defineLine.mid(8);
|
|
|
|
|
int spaceIdx = str.indexOf(' ');
|
|
|
|
|
const QString option = defineOption();
|
|
|
|
|
const bool hasValue = spaceIdx != -1;
|
|
|
|
|
QString arg = option + QLatin1String(str.left(hasValue ? spaceIdx : str.size()) + '=');
|
|
|
|
|
if (hasValue)
|
|
|
|
|
arg += QLatin1String(str.mid(spaceIdx + 1));
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompilerOptionsBuilder::addDefine(const QByteArray &defineLine)
|
|
|
|
|
{
|
|
|
|
|
m_options.append(defineLineToDefineOption(defineLine));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CompilerOptionsBuilder::addHeaderPathOptions()
|
2014-10-16 15:27:19 +02:00
|
|
|
{
|
2016-01-13 14:12:15 +01:00
|
|
|
typedef ProjectPartHeaderPath HeaderPath;
|
2015-06-26 10:50:06 +02:00
|
|
|
const QString defaultPrefix = includeOption();
|
2014-10-16 15:27:19 +02:00
|
|
|
|
|
|
|
|
QStringList result;
|
|
|
|
|
|
2015-11-05 11:47:01 +01:00
|
|
|
foreach (const HeaderPath &headerPath , m_projectPart.headerPaths) {
|
2014-10-16 15:27:19 +02:00
|
|
|
if (headerPath.path.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
if (excludeHeaderPath(headerPath.path))
|
2014-10-16 15:27:19 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
QString prefix;
|
|
|
|
|
switch (headerPath.type) {
|
|
|
|
|
case HeaderPath::FrameworkPath:
|
|
|
|
|
prefix = QLatin1String("-F");
|
|
|
|
|
break;
|
|
|
|
|
default: // This shouldn't happen, but let's be nice..:
|
|
|
|
|
// intentional fall-through:
|
|
|
|
|
case HeaderPath::IncludePath:
|
2015-01-23 14:52:21 +01:00
|
|
|
prefix = defaultPrefix;
|
2014-10-16 15:27:19 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.append(prefix + headerPath.path);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-25 13:46:22 +02:00
|
|
|
m_options.append(result);
|
2014-10-16 15:27:19 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
void CompilerOptionsBuilder::addToolchainAndProjectDefines()
|
2014-10-16 15:27:19 +02:00
|
|
|
{
|
2015-11-05 11:47:01 +01:00
|
|
|
QByteArray extendedDefines = m_projectPart.toolchainDefines + m_projectPart.projectDefines;
|
2014-10-16 15:27:19 +02:00
|
|
|
QStringList result;
|
|
|
|
|
|
2015-01-30 18:30:08 +01:00
|
|
|
foreach (QByteArray def, extendedDefines.split('\n')) {
|
2015-06-26 10:50:06 +02:00
|
|
|
if (def.isEmpty() || excludeDefineLine(def))
|
2015-01-28 17:13:02 +01:00
|
|
|
continue;
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
const QString defineOption = defineLineToDefineOption(def);
|
|
|
|
|
if (!result.contains(defineOption))
|
|
|
|
|
result.append(defineOption);
|
2014-10-16 15:27:19 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 13:46:22 +02:00
|
|
|
m_options.append(result);
|
2014-10-16 15:27:19 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 14:52:21 +01:00
|
|
|
static QStringList createLanguageOptionGcc(ProjectFile::Kind fileKind, bool objcExt)
|
2014-10-16 15:27:19 +02:00
|
|
|
{
|
|
|
|
|
QStringList opts;
|
|
|
|
|
|
|
|
|
|
switch (fileKind) {
|
2015-05-06 16:32:53 +02:00
|
|
|
case ProjectFile::Unclassified:
|
|
|
|
|
break;
|
2014-10-16 15:27:19 +02:00
|
|
|
case ProjectFile::CHeader:
|
|
|
|
|
if (objcExt)
|
|
|
|
|
opts += QLatin1String("objective-c-header");
|
|
|
|
|
else
|
|
|
|
|
opts += QLatin1String("c-header");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ProjectFile::CXXHeader:
|
|
|
|
|
default:
|
|
|
|
|
if (!objcExt) {
|
|
|
|
|
opts += QLatin1String("c++-header");
|
|
|
|
|
break;
|
|
|
|
|
} // else: fall-through!
|
|
|
|
|
case ProjectFile::ObjCHeader:
|
|
|
|
|
case ProjectFile::ObjCXXHeader:
|
|
|
|
|
opts += QLatin1String("objective-c++-header");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ProjectFile::CSource:
|
|
|
|
|
if (!objcExt) {
|
|
|
|
|
opts += QLatin1String("c");
|
|
|
|
|
break;
|
|
|
|
|
} // else: fall-through!
|
|
|
|
|
case ProjectFile::ObjCSource:
|
|
|
|
|
opts += QLatin1String("objective-c");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ProjectFile::CXXSource:
|
|
|
|
|
if (!objcExt) {
|
|
|
|
|
opts += QLatin1String("c++");
|
|
|
|
|
break;
|
|
|
|
|
} // else: fall-through!
|
|
|
|
|
case ProjectFile::ObjCXXSource:
|
|
|
|
|
opts += QLatin1String("objective-c++");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case ProjectFile::OpenCLSource:
|
|
|
|
|
opts += QLatin1String("cl");
|
|
|
|
|
break;
|
|
|
|
|
case ProjectFile::CudaSource:
|
|
|
|
|
opts += QLatin1String("cuda");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 16:32:53 +02:00
|
|
|
if (!opts.isEmpty())
|
|
|
|
|
opts.prepend(QLatin1String("-x"));
|
|
|
|
|
|
2014-10-16 15:27:19 +02:00
|
|
|
return opts;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
void CompilerOptionsBuilder::addLanguageOption(ProjectFile::Kind fileKind)
|
2015-01-23 14:52:21 +01:00
|
|
|
{
|
2015-11-05 11:47:01 +01:00
|
|
|
const bool objcExt = m_projectPart.languageExtensions & ProjectPart::ObjectiveCExtensions;
|
2015-06-26 10:50:06 +02:00
|
|
|
const QStringList options = createLanguageOptionGcc(fileKind, objcExt);
|
2015-06-25 13:46:22 +02:00
|
|
|
m_options.append(options);
|
2015-01-23 14:52:21 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
void CompilerOptionsBuilder::addOptionsForLanguage(bool checkForBorlandExtensions)
|
2014-10-16 15:27:19 +02:00
|
|
|
{
|
|
|
|
|
QStringList opts;
|
2015-11-05 11:47:01 +01:00
|
|
|
const ProjectPart::LanguageExtensions languageExtensions = m_projectPart.languageExtensions;
|
2015-06-25 13:46:22 +02:00
|
|
|
const bool gnuExtensions = languageExtensions & ProjectPart::GnuExtensions;
|
2015-11-05 11:47:01 +01:00
|
|
|
switch (m_projectPart.languageVersion) {
|
2014-10-16 15:27:19 +02:00
|
|
|
case ProjectPart::C89:
|
|
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu89") : QLatin1String("-std=c89"));
|
|
|
|
|
break;
|
|
|
|
|
case ProjectPart::C99:
|
|
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu99") : QLatin1String("-std=c99"));
|
|
|
|
|
break;
|
|
|
|
|
case ProjectPart::C11:
|
|
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu11") : QLatin1String("-std=c11"));
|
|
|
|
|
break;
|
|
|
|
|
case ProjectPart::CXX11:
|
|
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu++11") : QLatin1String("-std=c++11"));
|
|
|
|
|
break;
|
|
|
|
|
case ProjectPart::CXX98:
|
|
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu++98") : QLatin1String("-std=c++98"));
|
|
|
|
|
break;
|
|
|
|
|
case ProjectPart::CXX03:
|
2015-07-31 12:28:02 +02:00
|
|
|
// Clang 3.6 does not know -std=gnu++03.
|
2014-10-16 15:27:19 +02:00
|
|
|
opts << QLatin1String("-std=c++03");
|
|
|
|
|
break;
|
|
|
|
|
case ProjectPart::CXX14:
|
2015-07-31 12:28:02 +02:00
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu++14") : QLatin1String("-std=c++14"));
|
2014-10-16 15:27:19 +02:00
|
|
|
break;
|
|
|
|
|
case ProjectPart::CXX17:
|
2015-07-31 12:28:02 +02:00
|
|
|
// TODO: Change to (probably) "gnu++17"/"c++17" at some point in the future.
|
|
|
|
|
opts << (gnuExtensions ? QLatin1String("-std=gnu++1z") : QLatin1String("-std=c++1z"));
|
2014-10-16 15:27:19 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (languageExtensions & ProjectPart::MicrosoftExtensions)
|
|
|
|
|
opts << QLatin1String("-fms-extensions");
|
|
|
|
|
|
|
|
|
|
if (checkForBorlandExtensions && (languageExtensions & ProjectPart::BorlandExtensions))
|
|
|
|
|
opts << QLatin1String("-fborland-extensions");
|
|
|
|
|
|
2015-06-25 13:46:22 +02:00
|
|
|
m_options.append(opts);
|
2014-10-16 15:27:19 +02:00
|
|
|
}
|
2015-06-26 10:50:06 +02:00
|
|
|
|
|
|
|
|
QString CompilerOptionsBuilder::includeOption() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("-I");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CompilerOptionsBuilder::defineOption() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("-D");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CompilerOptionsBuilder::excludeDefineLine(const QByteArray &defineLine) const
|
|
|
|
|
{
|
|
|
|
|
// This is a quick fix for QTCREATORBUG-11501.
|
|
|
|
|
// TODO: do a proper fix, see QTCREATORBUG-11709.
|
|
|
|
|
if (defineLine.startsWith("#define __cplusplus"))
|
|
|
|
|
return true;
|
|
|
|
|
|
2015-06-29 13:16:59 +02:00
|
|
|
// gcc 4.9 has:
|
|
|
|
|
// #define __has_include(STR) __has_include__(STR)
|
|
|
|
|
// #define __has_include_next(STR) __has_include_next__(STR)
|
|
|
|
|
// The right-hand sides are gcc built-ins that clang does not understand, and they'd
|
|
|
|
|
// override clang's own (non-macro, it seems) definitions of the symbols on the left-hand
|
|
|
|
|
// side.
|
2015-11-05 11:47:01 +01:00
|
|
|
const bool isGccToolchain = m_projectPart.toolchainType == ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID;
|
2015-06-29 13:16:59 +02:00
|
|
|
if (isGccToolchain && defineLine.contains("has_include"))
|
|
|
|
|
return true;
|
|
|
|
|
|
2015-06-26 10:50:06 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CompilerOptionsBuilder::excludeHeaderPath(const QString &headerPath) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(headerPath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|