forked from qt-creator/qt-creator
CppTools: merge CompilerOptionsBuilder with Clang one
Since it's never used for other compilers. Change-Id: I9512692d1dc9f9a701ea2453b7d50005478bed5d Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -1,165 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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 "clangcompileroptionsbuilder.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
static QString creatorResourcePath()
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::instance()->resourcePath();
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
static QString creatorLibexecPath()
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::instance()->libexecPath();
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
QStringList ClangCompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage)
|
||||
{
|
||||
addWordWidth();
|
||||
addTargetTriple();
|
||||
addLanguageOption(fileKind);
|
||||
addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
|
||||
enableExceptions();
|
||||
|
||||
addDefineFloat128ForMingw();
|
||||
addToolchainAndProjectMacros();
|
||||
undefineClangVersionMacrosForMsvc();
|
||||
undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
addPredefinedHeaderPathsOptions();
|
||||
addWrappedQtHeadersIncludePath();
|
||||
addPrecompiledHeaderOptions(pchUsage);
|
||||
addHeaderPathOptions();
|
||||
addProjectConfigFileInclude();
|
||||
|
||||
addMsvcCompatibilityVersion();
|
||||
|
||||
addExtraOptions();
|
||||
|
||||
return options();
|
||||
}
|
||||
|
||||
ClangCompilerOptionsBuilder::ClangCompilerOptionsBuilder(const CppTools::ProjectPart &projectPart,
|
||||
const QString &clangVersion,
|
||||
const QString &clangResourceDirectory)
|
||||
: CompilerOptionsBuilder(projectPart),
|
||||
m_clangVersion(clangVersion),
|
||||
m_clangResourceDirectory(clangResourceDirectory)
|
||||
{
|
||||
}
|
||||
|
||||
bool ClangCompilerOptionsBuilder::excludeHeaderPath(const QString &path) const
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID
|
||||
&& path.contains("lib/gcc/i686-apple-darwin")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return CompilerOptionsBuilder::excludeHeaderPath(path);
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
|
||||
{
|
||||
add("-undef");
|
||||
add("-nostdinc");
|
||||
add("-nostdlibinc");
|
||||
|
||||
if (m_projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
|
||||
add(includeDirOption() + clangIncludeDirectory());
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addWrappedQtHeadersIncludePath()
|
||||
{
|
||||
static const QString resourcePath = creatorResourcePath();
|
||||
static QString wrappedQtHeadersPath = resourcePath + "/cplusplus/wrappedQtHeaders";
|
||||
QTC_ASSERT(QDir(wrappedQtHeadersPath).exists(), return;);
|
||||
|
||||
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
|
||||
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
|
||||
add(includeDirOption() + QDir::toNativeSeparators(wrappedQtHeadersPath));
|
||||
add(includeDirOption() + QDir::toNativeSeparators(wrappedQtCoreHeaderPath));
|
||||
}
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addProjectConfigFileInclude()
|
||||
{
|
||||
if (!m_projectPart.projectConfigFile.isEmpty()) {
|
||||
add("-include");
|
||||
add(QDir::toNativeSeparators(m_projectPart.projectConfigFile));
|
||||
}
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addExtraOptions()
|
||||
{
|
||||
add("-fmessage-length=0");
|
||||
add("-fdiagnostics-show-note-include-stack");
|
||||
add("-fmacro-backtrace-limit=0");
|
||||
add("-fretain-comments-from-system-headers");
|
||||
add("-ferror-limit=1000");
|
||||
}
|
||||
|
||||
QString ClangCompilerOptionsBuilder::clangIncludeDirectory() const
|
||||
{
|
||||
QDir dir(creatorLibexecPath() + "/clang/lib/clang/" + m_clangVersion + "/include");
|
||||
if (!dir.exists() || !QFileInfo(dir, "stdint.h").exists())
|
||||
dir = QDir(m_clangResourceDirectory);
|
||||
return QDir::toNativeSeparators(dir.canonicalPath());
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||
static QStringList macroNames {
|
||||
"__clang__",
|
||||
"__clang_major__",
|
||||
"__clang_minor__",
|
||||
"__clang_patchlevel__",
|
||||
"__clang_version__"
|
||||
};
|
||||
|
||||
foreach (const QString ¯oName, macroNames)
|
||||
add(undefineOption() + macroName);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
||||
@@ -1,59 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
class CPPTOOLS_EXPORT ClangCompilerOptionsBuilder : public CompilerOptionsBuilder
|
||||
{
|
||||
public:
|
||||
QStringList build(ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage);
|
||||
|
||||
ClangCompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||
const QString &clangVersion = QString(),
|
||||
const QString &clangResourceDirectory = QString());
|
||||
|
||||
virtual void addPredefinedHeaderPathsOptions();
|
||||
virtual void addExtraOptions();
|
||||
|
||||
bool excludeHeaderPath(const QString &path) const override;
|
||||
|
||||
virtual void addWrappedQtHeadersIncludePath();
|
||||
void addProjectConfigFileInclude();
|
||||
|
||||
void undefineClangVersionMacrosForMsvc();
|
||||
private:
|
||||
QString clangIncludeDirectory() const;
|
||||
QString m_clangVersion;
|
||||
QString m_clangResourceDirectory;
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
@@ -25,7 +25,10 @@
|
||||
|
||||
#include "compileroptionsbuilder.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
#include <utils/qtcfallthrough.h>
|
||||
|
||||
#include <QDir>
|
||||
@@ -33,11 +36,42 @@
|
||||
|
||||
namespace CppTools {
|
||||
|
||||
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart)
|
||||
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||
const QString &clangVersion,
|
||||
const QString &clangResourceDirectory)
|
||||
: m_projectPart(projectPart)
|
||||
, m_clangVersion(clangVersion)
|
||||
, m_clangResourceDirectory(clangResourceDirectory)
|
||||
{
|
||||
}
|
||||
|
||||
QStringList CompilerOptionsBuilder::build(CppTools::ProjectFile::Kind fileKind, PchUsage pchUsage)
|
||||
{
|
||||
m_options.clear();
|
||||
|
||||
addWordWidth();
|
||||
addTargetTriple();
|
||||
addLanguageOption(fileKind);
|
||||
addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
|
||||
enableExceptions();
|
||||
|
||||
addDefineFloat128ForMingw();
|
||||
addToolchainAndProjectMacros();
|
||||
undefineClangVersionMacrosForMsvc();
|
||||
undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
addPredefinedHeaderPathsOptions();
|
||||
addPrecompiledHeaderOptions(pchUsage);
|
||||
addHeaderPathOptions();
|
||||
addProjectConfigFileInclude();
|
||||
|
||||
addMsvcCompatibilityVersion();
|
||||
|
||||
addExtraOptions();
|
||||
|
||||
return options();
|
||||
}
|
||||
|
||||
QStringList CompilerOptionsBuilder::options() const
|
||||
{
|
||||
return m_options;
|
||||
@@ -438,6 +472,8 @@ bool CompilerOptionsBuilder::excludeHeaderPath(const QString &headerPath) const
|
||||
// intrinsics path from that version will lead to errors (unknown
|
||||
// intrinsics, unfavorable order with regard to include_next).
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) {
|
||||
if (headerPath.contains("lib/gcc/i686-apple-darwin"))
|
||||
return true;
|
||||
static QRegularExpression clangIncludeDir(
|
||||
QLatin1String("\\A.*/lib/clang/\\d+\\.\\d+(\\.\\d+)?/include\\z"));
|
||||
return clangIncludeDir.match(headerPath).hasMatch();
|
||||
@@ -446,4 +482,57 @@ bool CompilerOptionsBuilder::excludeHeaderPath(const QString &headerPath) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::addPredefinedHeaderPathsOptions()
|
||||
{
|
||||
add("-undef");
|
||||
add("-nostdinc");
|
||||
add("-nostdlibinc");
|
||||
|
||||
if (!m_clangVersion.isEmpty()
|
||||
&& m_projectPart.toolchainType != ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||
add(includeDirOption() + clangIncludeDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::addProjectConfigFileInclude()
|
||||
{
|
||||
if (!m_projectPart.projectConfigFile.isEmpty()) {
|
||||
add("-include");
|
||||
add(QDir::toNativeSeparators(m_projectPart.projectConfigFile));
|
||||
}
|
||||
}
|
||||
|
||||
static QString creatorLibexecPath()
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::instance()->libexecPath();
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString CompilerOptionsBuilder::clangIncludeDirectory() const
|
||||
{
|
||||
QDir dir(creatorLibexecPath() + "/clang/lib/clang/" + m_clangVersion + "/include");
|
||||
if (!dir.exists() || !QFileInfo(dir, "stdint.h").exists())
|
||||
dir = QDir(m_clangResourceDirectory);
|
||||
return QDir::toNativeSeparators(dir.canonicalPath());
|
||||
}
|
||||
|
||||
void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||
static QStringList macroNames {
|
||||
"__clang__",
|
||||
"__clang_major__",
|
||||
"__clang_minor__",
|
||||
"__clang_patchlevel__",
|
||||
"__clang_version__"
|
||||
};
|
||||
|
||||
foreach (const QString ¯oName, macroNames)
|
||||
add(undefineOption() + macroName);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
@@ -39,9 +39,21 @@ public:
|
||||
Use
|
||||
};
|
||||
|
||||
CompilerOptionsBuilder(const ProjectPart &projectPart);
|
||||
CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||
const QString &clangVersion = QString(),
|
||||
const QString &clangResourceDirectory = QString());
|
||||
virtual ~CompilerOptionsBuilder() {}
|
||||
|
||||
virtual void addTargetTriple();
|
||||
virtual void enableExceptions();
|
||||
virtual void addPredefinedHeaderPathsOptions();
|
||||
virtual void addLanguageOption(ProjectFile::Kind fileKind);
|
||||
virtual void addOptionsForLanguage(bool checkForBorlandExtensions = true);
|
||||
|
||||
virtual void addExtraOptions() {}
|
||||
|
||||
QStringList build(ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage);
|
||||
QStringList options() const;
|
||||
|
||||
// Add custom options
|
||||
@@ -50,19 +62,17 @@ public:
|
||||
|
||||
// Add options based on project part
|
||||
void addWordWidth();
|
||||
virtual void addTargetTriple();
|
||||
virtual void enableExceptions();
|
||||
void addHeaderPathOptions();
|
||||
void addPrecompiledHeaderOptions(PchUsage pchUsage);
|
||||
void addToolchainAndProjectMacros();
|
||||
void addMacros(const ProjectExplorer::Macros ¯os);
|
||||
virtual void addLanguageOption(ProjectFile::Kind fileKind);
|
||||
virtual void addOptionsForLanguage(bool checkForBorlandExtensions = true);
|
||||
|
||||
void addMsvcCompatibilityVersion();
|
||||
void undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
void addDefineFloat128ForMingw();
|
||||
void addProjectConfigFileInclude();
|
||||
void undefineClangVersionMacrosForMsvc();
|
||||
|
||||
protected:
|
||||
virtual bool excludeDefineDirective(const ProjectExplorer::Macro ¯o) const;
|
||||
@@ -79,8 +89,11 @@ private:
|
||||
QByteArray macroOption(const ProjectExplorer::Macro ¯o) const;
|
||||
QByteArray toDefineOption(const ProjectExplorer::Macro ¯o) const;
|
||||
QString defineDirectiveToDefineOption(const ProjectExplorer::Macro &marco) const;
|
||||
QString clangIncludeDirectory() const;
|
||||
|
||||
QStringList m_options;
|
||||
QString m_clangVersion;
|
||||
QString m_clangResourceDirectory;
|
||||
};
|
||||
|
||||
} // namespace CppTools
|
||||
|
||||
@@ -91,7 +91,6 @@ HEADERS += \
|
||||
compileroptionsbuilder.h \
|
||||
refactoringengineinterface.h \
|
||||
cppprojectfilecategorizer.h \
|
||||
clangcompileroptionsbuilder.h \
|
||||
cppprojectpartchooser.h \
|
||||
cppsymbolinfo.h \
|
||||
cursorineditor.h \
|
||||
@@ -176,7 +175,6 @@ SOURCES += \
|
||||
cppprojectinfogenerator.cpp \
|
||||
compileroptionsbuilder.cpp \
|
||||
cppprojectfilecategorizer.cpp \
|
||||
clangcompileroptionsbuilder.cpp \
|
||||
cppprojectpartchooser.cpp \
|
||||
wrappablelineedit.cpp \
|
||||
|
||||
|
||||
@@ -42,8 +42,6 @@ Project {
|
||||
"builtinindexingsupport.h",
|
||||
"builtincursorinfo.cpp",
|
||||
"builtincursorinfo.h",
|
||||
"clangcompileroptionsbuilder.cpp",
|
||||
"clangcompileroptionsbuilder.h",
|
||||
"clangdiagnosticconfig.cpp",
|
||||
"clangdiagnosticconfig.h",
|
||||
"clangdiagnosticconfigsmodel.cpp",
|
||||
|
||||
@@ -10,7 +10,6 @@ HEADERS += \
|
||||
$$PWD/projectpart.h \
|
||||
$$PWD/compileroptionsbuilder.h \
|
||||
$$PWD/cppprojectfilecategorizer.h \
|
||||
$$PWD/clangcompileroptionsbuilder.h \
|
||||
$$PWD/projectinfo.h \
|
||||
$$PWD/cppprojectinfogenerator.cpp \
|
||||
$$PWD/cppprojectpartchooser.h \
|
||||
@@ -21,7 +20,6 @@ SOURCES += \
|
||||
$$PWD/projectpart.cpp \
|
||||
$$PWD/compileroptionsbuilder.cpp \
|
||||
$$PWD/cppprojectfilecategorizer.cpp \
|
||||
$$PWD/clangcompileroptionsbuilder.cpp \
|
||||
$$PWD/projectinfo.cpp \
|
||||
$$PWD/cppprojectinfogenerator.cpp \
|
||||
$$PWD/cppprojectpartchooser.cpp \
|
||||
|
||||
Reference in New Issue
Block a user