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:
@@ -31,7 +31,7 @@
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
#include <cpptools/baseeditordocumentparser.h>
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/editordocumenthandle.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
@@ -70,21 +70,53 @@ QStringList createClangOptions(const ProjectPart::Ptr &pPart, const QString &fil
|
||||
return createClangOptions(pPart, fileKind);
|
||||
}
|
||||
|
||||
class LibClangOptionsBuilder final : public ClangCompilerOptionsBuilder
|
||||
static QString creatorResourcePath()
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::instance()->resourcePath();
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
class LibClangOptionsBuilder final : public CompilerOptionsBuilder
|
||||
{
|
||||
public:
|
||||
LibClangOptionsBuilder(const ProjectPart &projectPart)
|
||||
: ClangCompilerOptionsBuilder(projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR)
|
||||
: CompilerOptionsBuilder(projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR)
|
||||
{
|
||||
}
|
||||
|
||||
void addPredefinedHeaderPathsOptions() final
|
||||
{
|
||||
CompilerOptionsBuilder::addPredefinedHeaderPathsOptions();
|
||||
addWrappedQtHeadersIncludePath();
|
||||
}
|
||||
|
||||
void addExtraOptions() final
|
||||
{
|
||||
addDummyUiHeaderOnDiskIncludePath();
|
||||
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");
|
||||
}
|
||||
|
||||
private:
|
||||
void 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 addDummyUiHeaderOnDiskIncludePath()
|
||||
{
|
||||
const QString path = ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskDirPath();
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <removepchprojectpartsmessage.h>
|
||||
#include <updatepchprojectpartsmessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -108,9 +108,9 @@ HeaderAndSources ProjectUpdater::headerAndSourcesFromProjectPart(
|
||||
|
||||
QStringList ProjectUpdater::compilerArguments(CppTools::ProjectPart *projectPart)
|
||||
{
|
||||
using ClangCOBuilder = CppTools::ClangCompilerOptionsBuilder;
|
||||
ClangCOBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
|
||||
return builder.build(CppTools::ProjectFile::CXXHeader, ClangCOBuilder::PchUsage::None);
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
CompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
|
||||
return builder.build(CppTools::ProjectFile::CXXHeader, CompilerOptionsBuilder::PchUsage::None);
|
||||
}
|
||||
|
||||
ClangBackEnd::V2::ProjectPartContainer ProjectUpdater::toProjectPartContainer(
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <refactoringserverinterface.h>
|
||||
#include <clangrefactoringservermessages.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
@@ -151,12 +151,12 @@ void ClangQueryProjectsFindFilter::setUnsavedContent(
|
||||
Utils::SmallStringVector ClangQueryProjectsFindFilter::compilerArguments(CppTools::ProjectPart *projectPart,
|
||||
CppTools::ProjectFile::Kind fileKind)
|
||||
{
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
|
||||
ClangCompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
|
||||
CompilerOptionsBuilder builder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
|
||||
|
||||
return Utils::SmallStringVector(builder.build(fileKind,
|
||||
ClangCompilerOptionsBuilder::PchUsage::None));
|
||||
CompilerOptionsBuilder::PchUsage::None));
|
||||
}
|
||||
|
||||
QWidget *ClangQueryProjectsFindFilter::widget() const
|
||||
@@ -170,7 +170,7 @@ Utils::SmallStringVector createCommandLine(CppTools::ProjectPart *projectPart,
|
||||
const QString &documentFilePath,
|
||||
CppTools::ProjectFile::Kind fileKind)
|
||||
{
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
|
||||
Utils::SmallStringVector commandLine = ClangQueryProjectsFindFilter::compilerArguments(projectPart, fileKind);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <refactoringserverinterface.h>
|
||||
#include <requestsourcelocationforrenamingmessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
@@ -58,7 +58,7 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
||||
CppTools::ProjectPart *projectPart,
|
||||
RenameCallback &&renameSymbolsCallback)
|
||||
{
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
|
||||
setRefactoringEngineAvailable(false);
|
||||
|
||||
@@ -66,8 +66,8 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
||||
|
||||
QString filePath = data.filePath().toString();
|
||||
QTextCursor textCursor = data.cursor();
|
||||
ClangCompilerOptionsBuilder clangCOBuilder{*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR};
|
||||
Utils::SmallStringVector commandLine{clangCOBuilder.build(
|
||||
CompilerOptionsBuilder optionsBuilder{*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR};
|
||||
Utils::SmallStringVector commandLine{optionsBuilder.build(
|
||||
fileKindInProjectPart(projectPart, filePath),
|
||||
CppTools::getPchUsage())};
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <coreplugin/progressmanager/futureprogress.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/cppprojectfile.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
@@ -191,45 +191,32 @@ QStringList inputAndOutputArgumentsRemoved(const QString &inputFile, const QStri
|
||||
return newArguments;
|
||||
}
|
||||
|
||||
class ClangStaticAnalyzerOptionsBuilder final : public ClangCompilerOptionsBuilder
|
||||
class ClangStaticAnalyzerOptionsBuilder final : public CompilerOptionsBuilder
|
||||
{
|
||||
public:
|
||||
ClangStaticAnalyzerOptionsBuilder(const CppTools::ProjectPart &projectPart)
|
||||
: ClangCompilerOptionsBuilder(projectPart)
|
||||
, m_isMsvcToolchain(m_projectPart.toolchainType
|
||||
== ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
|
||||
, m_isMinGWToolchain(m_projectPart.toolchainType
|
||||
== ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID)
|
||||
: CompilerOptionsBuilder(projectPart)
|
||||
{
|
||||
}
|
||||
|
||||
bool excludeHeaderPath(const QString &headerPath) const final
|
||||
{
|
||||
if (m_isMinGWToolchain && headerPath.contains(m_projectPart.toolChainTargetTriple))
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID
|
||||
&& headerPath.contains(m_projectPart.toolChainTargetTriple)) {
|
||||
return true;
|
||||
return ClangCompilerOptionsBuilder::excludeHeaderPath(headerPath);
|
||||
}
|
||||
return CompilerOptionsBuilder::excludeHeaderPath(headerPath);
|
||||
}
|
||||
|
||||
void addPredefinedHeaderPathsOptions() final
|
||||
{
|
||||
add("-undef");
|
||||
if (m_isMsvcToolchain) {
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
|
||||
// exclude default clang path to use msvc includes
|
||||
add("-nostdinc");
|
||||
add("-nostdlibinc");
|
||||
}
|
||||
}
|
||||
|
||||
void addExtraOptions() final {}
|
||||
|
||||
void addWrappedQtHeadersIncludePath() final
|
||||
{
|
||||
// Empty, analyzer doesn't need them
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_isMsvcToolchain;
|
||||
bool m_isMinGWToolchain;
|
||||
};
|
||||
|
||||
static QStringList createMsCompatibilityVersionOption(const ProjectPart &projectPart)
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include <clangrefactoringservermessages.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
namespace {
|
||||
@@ -49,7 +49,7 @@ using testing::ReturnNew;
|
||||
using testing::DefaultValue;
|
||||
using testing::ByMove;
|
||||
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
using ClangBackEnd::V2::FileContainer;
|
||||
|
||||
class ClangQueryProjectFindFilter : public ::testing::Test
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <removepchprojectpartsmessage.h>
|
||||
#include <updatepchprojectpartsmessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
namespace {
|
||||
@@ -49,7 +49,7 @@ using testing::AnyNumber;
|
||||
|
||||
using ClangBackEnd::V2::FileContainer;
|
||||
using ClangBackEnd::V2::ProjectPartContainer;
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
|
||||
class ProjectUpdater : public testing::Test
|
||||
{
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
#include <clangrefactoringclientmessages.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
|
||||
using ClangRefactoring::RefactoringEngine;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
#include <clangrefactoringmessages.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
@@ -45,7 +45,7 @@ namespace {
|
||||
|
||||
using testing::_;
|
||||
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
using CppTools::CompilerOptionsBuilder;
|
||||
|
||||
using ClangBackEnd::RequestSourceLocationsForRenamingMessage;
|
||||
|
||||
@@ -126,12 +126,10 @@ void RefactoringEngine::SetUp()
|
||||
projectPart = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart);
|
||||
projectPart->files.push_back(projectFile);
|
||||
|
||||
ClangCompilerOptionsBuilder clangCOBuilder(*projectPart,
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR);
|
||||
commandLine = Utils::SmallStringVector(clangCOBuilder.build(
|
||||
CompilerOptionsBuilder optionsBuilder(*projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR);
|
||||
commandLine = Utils::SmallStringVector(optionsBuilder.build(
|
||||
projectFile.kind,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None));
|
||||
CompilerOptionsBuilder::PchUsage::None));
|
||||
commandLine.push_back(qStringFilePath);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user