forked from qt-creator/qt-creator
Clang: Consolidate all ClangCompilerOptionsBuilder into one implementation
We used the same code in different but don't shared it. From a bug fixing perspective it's actually not that smart. Change-Id: Iaaffc883229e259ff77f95b5cf0a8f0d8b5117df 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/compileroptionsbuilder.h>
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/editordocumenthandle.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
@@ -70,18 +70,7 @@ QStringList createClangOptions(const ProjectPart::Ptr &pPart, const QString &fil
|
||||
return createClangOptions(pPart, fileKind);
|
||||
}
|
||||
|
||||
static QString getResourceDir()
|
||||
{
|
||||
QDir dir(ICore::libexecPath()
|
||||
+ QLatin1String("/clang/lib/clang/")
|
||||
+ QLatin1String(CLANG_VERSION)
|
||||
+ QLatin1String("/include"));
|
||||
if (!dir.exists() || !QFileInfo(dir, QLatin1String("stdint.h")).exists())
|
||||
dir = QDir(QLatin1String(CLANG_RESOURCE_DIR));
|
||||
return dir.canonicalPath();
|
||||
}
|
||||
|
||||
class LibClangOptionsBuilder : public CompilerOptionsBuilder
|
||||
class LibClangOptionsBuilder : public ClangCompilerOptionsBuilder
|
||||
{
|
||||
public:
|
||||
static QStringList build(const ProjectPart::Ptr &projectPart, ProjectFile::Kind fileKind)
|
||||
@@ -117,79 +106,16 @@ public:
|
||||
|
||||
private:
|
||||
LibClangOptionsBuilder(const CppTools::ProjectPart &projectPart)
|
||||
: CompilerOptionsBuilder(projectPart)
|
||||
: ClangCompilerOptionsBuilder(projectPart, CLANG_VERSION, CLANG_RESOURCE_DIR)
|
||||
{
|
||||
}
|
||||
|
||||
bool excludeHeaderPath(const QString &path) const override
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) {
|
||||
if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin")))
|
||||
return true;
|
||||
}
|
||||
|
||||
return CompilerOptionsBuilder::excludeHeaderPath(path);
|
||||
}
|
||||
|
||||
void addPredefinedMacrosAndHeaderPathsOptions()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
|
||||
addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
|
||||
else
|
||||
addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
|
||||
}
|
||||
|
||||
void addPredefinedMacrosAndHeaderPathsOptionsForMsvc()
|
||||
{
|
||||
add(QLatin1String("-nostdinc"));
|
||||
add(QLatin1String("-undef"));
|
||||
}
|
||||
|
||||
void addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc()
|
||||
{
|
||||
static const QString resourceDir = getResourceDir();
|
||||
if (QTC_GUARD(!resourceDir.isEmpty())) {
|
||||
add(QLatin1String("-nostdlibinc"));
|
||||
add(QLatin1String("-I") + QDir::toNativeSeparators(resourceDir));
|
||||
add(QLatin1String("-undef"));
|
||||
}
|
||||
}
|
||||
|
||||
void addWrappedQtHeadersIncludePath()
|
||||
{
|
||||
static const QString wrappedQtHeadersPath = ICore::instance()->resourcePath()
|
||||
+ QLatin1String("/cplusplus/wrappedQtHeaders");
|
||||
|
||||
if (m_projectPart.qtVersion != ProjectPart::NoQt) {
|
||||
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + QLatin1String("/QtCore");
|
||||
add(QLatin1String("-I") + QDir::toNativeSeparators(wrappedQtHeadersPath));
|
||||
add(QLatin1String("-I") + QDir::toNativeSeparators(wrappedQtCoreHeaderPath));
|
||||
}
|
||||
}
|
||||
|
||||
void addProjectConfigFileInclude()
|
||||
{
|
||||
if (!m_projectPart.projectConfigFile.isEmpty()) {
|
||||
add(QLatin1String("-include"));
|
||||
add(QDir::toNativeSeparators(m_projectPart.projectConfigFile));
|
||||
}
|
||||
}
|
||||
|
||||
void addDummyUiHeaderOnDiskIncludePath()
|
||||
{
|
||||
const QString path = ModelManagerSupportClang::instance()->dummyUiHeaderOnDiskDirPath();
|
||||
if (!path.isEmpty())
|
||||
add(includeDirOption() + QDir::toNativeSeparators(path));
|
||||
}
|
||||
|
||||
void addExtraOptions()
|
||||
{
|
||||
add(QLatin1String("-fmessage-length=0"));
|
||||
add(QLatin1String("-fdiagnostics-show-note-include-stack"));
|
||||
add(QLatin1String("-fmacro-backtrace-limit=0"));
|
||||
add(QLatin1String("-fretain-comments-from-system-headers"));
|
||||
add(QLatin1String("-ferror-limit=1000"));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -27,12 +27,13 @@
|
||||
|
||||
#include "projectpartutilities.h"
|
||||
#include "refactoringclient.h"
|
||||
#include "refactoringcompileroptionsbuilder.h"
|
||||
#include "searchinterface.h"
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
#include <requestsourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
ClangQueryProjectsFindFilter::ClangQueryProjectsFindFilter(
|
||||
@@ -112,11 +113,14 @@ Utils::SmallStringVector createCommandLine(CppTools::ProjectPart *projectPart,
|
||||
const QString &documentFilePath,
|
||||
CppTools::ProjectFile::Kind fileKind)
|
||||
{
|
||||
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
|
||||
auto commandLine = RefactoringCompilerOptionsBuilder::build(projectPart,
|
||||
fileKind,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||
Utils::SmallStringVector commandLine{ClangCompilerOptionsBuilder::build(
|
||||
projectPart,
|
||||
fileKind,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None,
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR)};
|
||||
|
||||
commandLine.push_back(documentFilePath);
|
||||
|
||||
|
@@ -3,7 +3,6 @@ INCLUDEPATH += $$PWD
|
||||
HEADERS += \
|
||||
$$PWD/refactoringengine.h \
|
||||
$$PWD/refactoringconnectionclient.h \
|
||||
$$PWD/refactoringcompileroptionsbuilder.h \
|
||||
$$PWD/refactoringclient.h \
|
||||
$$PWD/searchinterface.h \
|
||||
$$PWD/searchhandleinterface.h \
|
||||
@@ -13,7 +12,6 @@ HEADERS += \
|
||||
SOURCES += \
|
||||
$$PWD/refactoringengine.cpp \
|
||||
$$PWD/refactoringconnectionclient.cpp \
|
||||
$$PWD/refactoringcompileroptionsbuilder.cpp \
|
||||
$$PWD/refactoringclient.cpp \
|
||||
$$PWD/searchinterface.cpp \
|
||||
$$PWD/searchhandleinterface.cpp \
|
||||
|
@@ -1,152 +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 "refactoringcompileroptionsbuilder.h"
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
namespace {
|
||||
|
||||
QString getCreatorResourcePath()
|
||||
{
|
||||
#ifndef UNIT_TESTS
|
||||
return Core::ICore::instance()->resourcePath();
|
||||
#else
|
||||
return QString();
|
||||
#endif
|
||||
}
|
||||
|
||||
QString getClangIncludeDirectory()
|
||||
{
|
||||
QDir dir(getCreatorResourcePath() + QLatin1String("/cplusplus/clang/") +
|
||||
QLatin1String(CLANG_VERSION) + QLatin1String("/include"));
|
||||
if (!dir.exists() || !QFileInfo(dir, QLatin1String("stdint.h")).exists())
|
||||
dir = QDir(QLatin1String(CLANG_RESOURCE_DIR));
|
||||
return dir.canonicalPath();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RefactoringCompilerOptionsBuilder::RefactoringCompilerOptionsBuilder(CppTools::ProjectPart *projectPart)
|
||||
: CompilerOptionsBuilder(*projectPart)
|
||||
{
|
||||
}
|
||||
|
||||
bool RefactoringCompilerOptionsBuilder::excludeHeaderPath(const QString &path) const
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::CLANG_TOOLCHAIN_TYPEID) {
|
||||
if (path.contains(QLatin1String("lib/gcc/i686-apple-darwin")))
|
||||
return true;
|
||||
}
|
||||
|
||||
return CompilerOptionsBuilder::excludeHeaderPath(path);
|
||||
}
|
||||
|
||||
void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptions()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
|
||||
addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
|
||||
else
|
||||
addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
|
||||
}
|
||||
|
||||
void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForMsvc()
|
||||
{
|
||||
add(QLatin1String("-nostdinc"));
|
||||
add(QLatin1String("-undef"));
|
||||
}
|
||||
|
||||
void RefactoringCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc()
|
||||
{
|
||||
static const QString resourceDir = getClangIncludeDirectory();
|
||||
if (!resourceDir.isEmpty()) {
|
||||
add(QLatin1String("-nostdlibinc"));
|
||||
add(QLatin1String("-I") + resourceDir);
|
||||
add(QLatin1String("-undef"));
|
||||
}
|
||||
}
|
||||
|
||||
void RefactoringCompilerOptionsBuilder::addWrappedQtHeadersIncludePath()
|
||||
{
|
||||
static const QString wrappedQtHeaders = getCreatorResourcePath()
|
||||
+ QStringLiteral("/cplusplus/wrappedQtHeaders");
|
||||
|
||||
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
|
||||
add(QLatin1String("-I") + wrappedQtHeaders);
|
||||
add(QLatin1String("-I") + wrappedQtHeaders + QLatin1String("/QtCore"));
|
||||
}
|
||||
}
|
||||
|
||||
void RefactoringCompilerOptionsBuilder::addProjectConfigFileInclude()
|
||||
{
|
||||
if (!m_projectPart.projectConfigFile.isEmpty()) {
|
||||
add(QLatin1String("-include"));
|
||||
add(m_projectPart.projectConfigFile);
|
||||
}
|
||||
}
|
||||
|
||||
void RefactoringCompilerOptionsBuilder::addExtraOptions()
|
||||
{
|
||||
add(QLatin1String("-fmessage-length=0"));
|
||||
add(QLatin1String("-fdiagnostics-show-note-include-stack"));
|
||||
add(QLatin1String("-fmacro-backtrace-limit=0"));
|
||||
add(QLatin1String("-fretain-comments-from-system-headers"));
|
||||
add(QLatin1String("-ferror-limit=1000"));
|
||||
}
|
||||
|
||||
Utils::SmallStringVector RefactoringCompilerOptionsBuilder::build(CppTools::ProjectPart *projectPart,
|
||||
CppTools::ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage)
|
||||
{
|
||||
if (projectPart == nullptr)
|
||||
return Utils::SmallStringVector();
|
||||
|
||||
RefactoringCompilerOptionsBuilder optionsBuilder(projectPart);
|
||||
|
||||
optionsBuilder.addWordWidth();
|
||||
optionsBuilder.addTargetTriple();
|
||||
optionsBuilder.addLanguageOption(fileKind);
|
||||
optionsBuilder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
|
||||
optionsBuilder.enableExceptions();
|
||||
|
||||
optionsBuilder.addDefineFloat128ForMingw();
|
||||
optionsBuilder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
|
||||
optionsBuilder.addToolchainAndProjectDefines();
|
||||
optionsBuilder.undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
optionsBuilder.addPredefinedMacrosAndHeaderPathsOptions();
|
||||
optionsBuilder.addWrappedQtHeadersIncludePath();
|
||||
optionsBuilder.addHeaderPathOptions();
|
||||
optionsBuilder.addPrecompiledHeaderOptions(pchUsage);
|
||||
optionsBuilder.addProjectConfigFileInclude();
|
||||
|
||||
optionsBuilder.addMsvcCompatibilityVersion();
|
||||
|
||||
optionsBuilder.addExtraOptions();
|
||||
|
||||
return Utils::SmallStringVector(optionsBuilder.options());
|
||||
}
|
||||
|
||||
} // namespace ClangRefactoring
|
@@ -27,11 +27,11 @@
|
||||
|
||||
#include "projectpartutilities.h"
|
||||
|
||||
#include <refactoringcompileroptionsbuilder.h>
|
||||
|
||||
#include <refactoringserverinterface.h>
|
||||
#include <requestsourcelocationforrenamingmessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
@@ -56,13 +56,18 @@ void RefactoringEngine::startLocalRenaming(const QTextCursor &textCursor,
|
||||
CppTools::ProjectPart *projectPart,
|
||||
RenameCallback &&renameSymbolsCallback)
|
||||
{
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
|
||||
setUsable(false);
|
||||
|
||||
client.setLocalRenamingCallback(std::move(renameSymbolsCallback));
|
||||
|
||||
auto commandLine = RefactoringCompilerOptionsBuilder::build(projectPart,
|
||||
fileKindInProjectPart(projectPart, filePath.toString()),
|
||||
CppTools::getPchUsage());
|
||||
Utils::SmallStringVector commandLine{ClangCompilerOptionsBuilder::build(
|
||||
projectPart,
|
||||
fileKindInProjectPart(projectPart, filePath.toString()),
|
||||
CppTools::getPchUsage(),
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR)};
|
||||
|
||||
commandLine.push_back(filePath.toString());
|
||||
|
||||
|
165
src/plugins/cpptools/clangcompileroptionsbuilder.cpp
Normal file
165
src/plugins/cpptools/clangcompileroptionsbuilder.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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
|
||||
}
|
||||
|
||||
QStringList ClangCompilerOptionsBuilder::build(const CppTools::ProjectPart *projectPart,
|
||||
CppTools::ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage,
|
||||
const QString &clangVersion,
|
||||
const QString &clangResourceDirectory)
|
||||
{
|
||||
if (projectPart) {
|
||||
ClangCompilerOptionsBuilder builder(*projectPart, clangVersion, clangResourceDirectory);
|
||||
|
||||
builder.addWordWidth();
|
||||
builder.addTargetTriple();
|
||||
builder.addLanguageOption(fileKind);
|
||||
builder.addOptionsForLanguage(/*checkForBorlandExtensions*/ true);
|
||||
builder.enableExceptions();
|
||||
|
||||
builder.addDefineToAvoidIncludingGccOrMinGwIntrinsics();
|
||||
builder.addDefineFloat128ForMingw();
|
||||
builder.addToolchainAndProjectDefines();
|
||||
builder.undefineCppLanguageFeatureMacrosForMsvc2015();
|
||||
|
||||
builder.addPredefinedMacrosAndHeaderPathsOptions();
|
||||
builder.addWrappedQtHeadersIncludePath();
|
||||
builder.addPrecompiledHeaderOptions(pchUsage);
|
||||
builder.addHeaderPathOptions();
|
||||
builder.addProjectConfigFileInclude();
|
||||
|
||||
builder.addMsvcCompatibilityVersion();
|
||||
|
||||
builder.addExtraOptions();
|
||||
|
||||
return builder.options();
|
||||
}
|
||||
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (path.contains("lib/gcc/i686-apple-darwin"))
|
||||
return true;
|
||||
}
|
||||
|
||||
return CompilerOptionsBuilder::excludeHeaderPath(path);
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptions()
|
||||
{
|
||||
if (m_projectPart.toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID)
|
||||
addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
|
||||
else
|
||||
addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForMsvc()
|
||||
{
|
||||
add("-nostdinc");
|
||||
add("-undef");
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc()
|
||||
{
|
||||
static const QString resourceDir = clangIncludeDirectory();
|
||||
if (QTC_GUARD(!resourceDir.isEmpty())) {
|
||||
add("-nostdlibinc");
|
||||
add("-I" + QDir::toNativeSeparators(resourceDir));
|
||||
add("-undef");
|
||||
}
|
||||
}
|
||||
|
||||
void ClangCompilerOptionsBuilder::addWrappedQtHeadersIncludePath()
|
||||
{
|
||||
static const QString wrappedQtHeadersPath = creatorResourcePath()
|
||||
+ "/cplusplus/wrappedQtHeaders";
|
||||
|
||||
if (m_projectPart.qtVersion != CppTools::ProjectPart::NoQt) {
|
||||
const QString wrappedQtCoreHeaderPath = wrappedQtHeadersPath + "/QtCore";
|
||||
add("-I" + QDir::toNativeSeparators(wrappedQtHeadersPath));
|
||||
add("-I" + 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(creatorResourcePath() + "/clang/lib/clang/" + m_clangVersion + "/include");
|
||||
|
||||
if (!dir.exists() || !QFileInfo(dir, "stdint.h").exists())
|
||||
dir = QDir(m_clangResourceDirectory);
|
||||
|
||||
return dir.canonicalPath();
|
||||
}
|
||||
|
||||
} // namespace CppTools
|
@@ -25,35 +25,46 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cpptools_global.h"
|
||||
|
||||
#include <cpptools/compileroptionsbuilder.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
namespace CppTools {
|
||||
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
class RefactoringCompilerOptionsBuilder : public CppTools::CompilerOptionsBuilder
|
||||
class CPPTOOLS_EXPORT ClangCompilerOptionsBuilder : public CompilerOptionsBuilder
|
||||
{
|
||||
public:
|
||||
static Utils::SmallStringVector build(CppTools::ProjectPart *projectPart,
|
||||
CppTools::ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage);
|
||||
static QStringList build(const ProjectPart *projectPart,
|
||||
ProjectFile::Kind fileKind,
|
||||
PchUsage pchUsage,
|
||||
const QString &clangVersion,
|
||||
const QString &clangResourceDirectory);
|
||||
|
||||
private:
|
||||
RefactoringCompilerOptionsBuilder(CppTools::ProjectPart *projectPart);
|
||||
protected:
|
||||
ClangCompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||
const QString &clangVersion,
|
||||
const QString &clangResourceDirectory);
|
||||
|
||||
bool excludeHeaderPath(const QString &path) const override;
|
||||
|
||||
void addPredefinedMacrosAndHeaderPathsOptions();
|
||||
|
||||
void addPredefinedMacrosAndHeaderPathsOptionsForMsvc();
|
||||
|
||||
void addPredefinedMacrosAndHeaderPathsOptionsForNonMsvc();
|
||||
|
||||
void addWrappedQtHeadersIncludePath();
|
||||
|
||||
void addProjectConfigFileInclude();
|
||||
|
||||
void addExtraOptions();
|
||||
|
||||
private:
|
||||
QString clangIncludeDirectory() const;
|
||||
|
||||
private:
|
||||
QString m_clangVersion;
|
||||
QString m_clangResourceDirectory;
|
||||
};
|
||||
|
||||
} // namespace ClangRefactoring
|
||||
} // namespace CppTools
|
@@ -79,6 +79,7 @@ HEADERS += \
|
||||
compileroptionsbuilder.h \
|
||||
refactoringengineinterface.h \
|
||||
cppprojectfilecategorizer.h \
|
||||
clangcompileroptionsbuilder.h \
|
||||
cppprojectinterface.h \
|
||||
cppbaseprojectpartbuilder.h \
|
||||
|
||||
@@ -155,6 +156,7 @@ SOURCES += \
|
||||
compileroptionsbuilder.cpp \
|
||||
cppprojectfilecategorizer.cpp \
|
||||
cppbaseprojectpartbuilder.cpp \
|
||||
clangcompileroptionsbuilder.cpp
|
||||
|
||||
FORMS += \
|
||||
clangdiagnosticconfigswidget.ui \
|
||||
|
@@ -107,6 +107,7 @@ Project {
|
||||
"cppprojectfilecategorizer.cpp", "cppprojectfilecategorizer.h",
|
||||
"cppprojectinterface.h",
|
||||
"cppbaseprojectpartbuilder.cpp", "cppbaseprojectpartbuilder.h",
|
||||
"clangcompileroptionsbuilder.cpp", "clangcompileroptionsbuilder.h",
|
||||
]
|
||||
|
||||
Group {
|
||||
|
@@ -14,6 +14,7 @@ HEADERS += \
|
||||
$$PWD/projectpart.h \
|
||||
$$PWD/compileroptionsbuilder.h \
|
||||
$$PWD/cppprojectfilecategorizer.h \
|
||||
$$PWD/clangcompileroptionsbuilder.h \
|
||||
$$PWD/cppbaseprojectpartbuilder.h \
|
||||
$$PWD/projectinfo.h \
|
||||
$$PWD/cppprojectinterface.h \
|
||||
@@ -25,5 +26,6 @@ SOURCES += \
|
||||
$$PWD/projectpart.cpp \
|
||||
$$PWD/compileroptionsbuilder.cpp \
|
||||
$$PWD/cppprojectfilecategorizer.cpp \
|
||||
$$PWD/clangcompileroptionsbuilder.cpp \
|
||||
$$PWD/cppbaseprojectpartbuilder.cpp \
|
||||
$$PWD/projectinfo.cpp \
|
||||
|
@@ -31,11 +31,11 @@
|
||||
|
||||
#include <clangqueryprojectsfindfilter.h>
|
||||
#include <refactoringclient.h>
|
||||
#include <refactoringcompileroptionsbuilder.h>
|
||||
|
||||
#include <requestsourcelocationforrenamingmessage.h>
|
||||
#include <requestsourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
namespace {
|
||||
@@ -48,7 +48,7 @@ using ::testing::ReturnNew;
|
||||
using ::testing::DefaultValue;
|
||||
using ::testing::ByMove;
|
||||
|
||||
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
|
||||
class ClangQueryProjectFindFilter : public ::testing::Test
|
||||
{
|
||||
@@ -178,9 +178,12 @@ createCommandLines(const std::vector<CppTools::ProjectPart::Ptr> &projectParts)
|
||||
|
||||
for (const CppTools::ProjectPart::Ptr &projectPart : projectParts) {
|
||||
for (const CppTools::ProjectFile &projectFile : projectPart->files) {
|
||||
auto commandLine = RefactoringCompilerOptionsBuilder::build(projectPart.data(),
|
||||
projectFile.kind,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||
Utils::SmallStringVector commandLine{ClangCompilerOptionsBuilder::build(
|
||||
projectPart.data(),
|
||||
projectFile.kind,
|
||||
ClangCompilerOptionsBuilder::PchUsage::None,
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR)};
|
||||
commandLine.emplace_back(projectFile.path);
|
||||
commandLines.push_back(commandLine);
|
||||
}
|
||||
|
@@ -28,13 +28,13 @@
|
||||
#include "mocksearchhandle.h"
|
||||
|
||||
#include <refactoringclient.h>
|
||||
#include <refactoringcompileroptionsbuilder.h>
|
||||
#include <refactoringengine.h>
|
||||
#include <refactoringconnectionclient.h>
|
||||
|
||||
#include <sourcelocationsforrenamingmessage.h>
|
||||
#include <sourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
@@ -44,7 +44,8 @@
|
||||
|
||||
namespace {
|
||||
|
||||
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
|
||||
using ClangRefactoring::RefactoringEngine;
|
||||
|
||||
using ClangBackEnd::SourceLocationsForRenamingMessage;
|
||||
@@ -251,9 +252,12 @@ void RefactoringClient::SetUp()
|
||||
projectPart = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart);
|
||||
projectPart->files.push_back(projectFile);
|
||||
|
||||
commandLine = RefactoringCompilerOptionsBuilder::build(projectPart.data(),
|
||||
projectFile.kind,
|
||||
RefactoringCompilerOptionsBuilder::PchUsage::None);
|
||||
commandLine = Utils::SmallStringVector{ClangCompilerOptionsBuilder::build(
|
||||
projectPart.data(),
|
||||
projectFile.kind,
|
||||
ClangCompilerOptionsBuilder::PchUsage::None,
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR)};
|
||||
|
||||
client.setSearchHandle(&mockSearchHandle);
|
||||
client.setExpectedResultCount(1);
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include "mockrefactoringserver.h"
|
||||
#include "mockrefactoringclient.h"
|
||||
|
||||
#include <refactoringcompileroptionsbuilder.h>
|
||||
#include <refactoringengine.h>
|
||||
|
||||
#include <requestsourcelocationforrenamingmessage.h>
|
||||
@@ -36,8 +35,11 @@
|
||||
#include <sourcelocationsforrenamingmessage.h>
|
||||
#include <sourcerangesanddiagnosticsforquerymessage.h>
|
||||
|
||||
#include <cpptools/clangcompileroptionsbuilder.h>
|
||||
#include <cpptools/projectpart.h>
|
||||
|
||||
#include <utils/smallstringvector.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QTextDocument>
|
||||
|
||||
@@ -45,7 +47,7 @@ namespace {
|
||||
|
||||
using testing::_;
|
||||
|
||||
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
|
||||
using CppTools::ClangCompilerOptionsBuilder;
|
||||
|
||||
using ClangBackEnd::RequestSourceLocationsForRenamingMessage;
|
||||
|
||||
@@ -128,9 +130,12 @@ void RefactoringEngine::SetUp()
|
||||
projectPart = CppTools::ProjectPart::Ptr(new CppTools::ProjectPart);
|
||||
projectPart->files.push_back(projectFile);
|
||||
|
||||
commandLine = RefactoringCompilerOptionsBuilder::build(projectPart.data(),
|
||||
projectFile.kind,
|
||||
RefactoringCompilerOptionsBuilder::PchUsage::None);
|
||||
commandLine = Utils::SmallStringVector(ClangCompilerOptionsBuilder::build(
|
||||
projectPart.data(),
|
||||
projectFile.kind,
|
||||
CppTools::CompilerOptionsBuilder::PchUsage::None,
|
||||
CLANG_VERSION,
|
||||
CLANG_RESOURCE_DIR));
|
||||
commandLine.push_back(qStringFilePath);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user