forked from qt-creator/qt-creator
Don't remove __cplusplus
For the indexing we need all tool chain macros. Originally it was a fix because the C++ version of the project part and __cplusplus could be different but now they should be the same. They will be now removed in the compiler options builder. Change-Id: I7ae8721a29632473e76ecedb411a6c9001e5e199 Task-number: QTCREATORBUG-21265 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -70,6 +70,7 @@ public:
|
|||||||
: CompilerOptionsBuilder(projectPart,
|
: CompilerOptionsBuilder(projectPart,
|
||||||
UseSystemHeader::No,
|
UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::No,
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
QString(CLANG_VERSION),
|
QString(CLANG_VERSION),
|
||||||
QString(CLANG_RESOURCE_DIR))
|
QString(CLANG_RESOURCE_DIR))
|
||||||
{
|
{
|
||||||
|
@@ -194,6 +194,7 @@ static AnalyzeUnits toAnalyzeUnits(const FileInfos &fileInfos)
|
|||||||
CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart,
|
CompilerOptionsBuilder optionsBuilder(*fileInfo.projectPart,
|
||||||
CppTools::UseSystemHeader::No,
|
CppTools::UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::No,
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
QString(CLANG_VERSION),
|
QString(CLANG_VERSION),
|
||||||
QString(CLANG_RESOURCE_DIR));
|
QString(CLANG_RESOURCE_DIR));
|
||||||
QStringList arguments = extraClangToolsPrependOptions();
|
QStringList arguments = extraClangToolsPrependOptions();
|
||||||
|
@@ -44,13 +44,15 @@ namespace CppTools {
|
|||||||
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
UseSystemHeader useSystemHeader,
|
UseSystemHeader useSystemHeader,
|
||||||
SkipBuiltIn skipBuiltInHeaderPathsAndDefines,
|
SkipBuiltIn skipBuiltInHeaderPathsAndDefines,
|
||||||
|
SkipLanguageDefines skipLanguageDefines,
|
||||||
QString clangVersion,
|
QString clangVersion,
|
||||||
QString clangResourceDirectory)
|
QString clangResourceDirectory)
|
||||||
: m_projectPart(projectPart)
|
: m_projectPart(projectPart)
|
||||||
, m_useSystemHeader(useSystemHeader)
|
|
||||||
, m_clangVersion(clangVersion)
|
, m_clangVersion(clangVersion)
|
||||||
, m_clangResourceDirectory(clangResourceDirectory)
|
, m_clangResourceDirectory(clangResourceDirectory)
|
||||||
|
, m_useSystemHeader(useSystemHeader)
|
||||||
, m_skipBuiltInHeaderPathsAndDefines(skipBuiltInHeaderPathsAndDefines)
|
, m_skipBuiltInHeaderPathsAndDefines(skipBuiltInHeaderPathsAndDefines)
|
||||||
|
, m_skipLanguageDefines(skipLanguageDefines)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,8 +603,18 @@ bool CompilerOptionsBuilder::excludeDefineDirective(const ProjectExplorer::Macro
|
|||||||
{
|
{
|
||||||
// Avoid setting __cplusplus & co as this might conflict with other command line flags.
|
// Avoid setting __cplusplus & co as this might conflict with other command line flags.
|
||||||
// Clang should set __cplusplus based on -std= and -fms-compatibility-version version.
|
// Clang should set __cplusplus based on -std= and -fms-compatibility-version version.
|
||||||
QTC_ASSERT(macro.key != "__cplusplus", return true);
|
static const auto languageDefines = {"__cplusplus",
|
||||||
QTC_ASSERT(macro.key != "__STDC_VERSION__", return true);
|
"__STDC_VERSION__",
|
||||||
|
"_MSC_BUILD",
|
||||||
|
"_MSVC_LANG",
|
||||||
|
"_MSC_FULL_VER",
|
||||||
|
"_MSC_VER"};
|
||||||
|
if (m_skipLanguageDefines == SkipLanguageDefines::Yes
|
||||||
|
&& std::find(languageDefines.begin(),
|
||||||
|
languageDefines.end(),
|
||||||
|
macro.key) != languageDefines.end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Ignore for all compiler toolchains since LLVM has it's own implementation for
|
// Ignore for all compiler toolchains since LLVM has it's own implementation for
|
||||||
// __has_include(STR) and __has_include_next(STR)
|
// __has_include(STR) and __has_include_next(STR)
|
||||||
|
@@ -31,13 +31,19 @@
|
|||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
|
|
||||||
enum class UseSystemHeader
|
enum class UseSystemHeader : char
|
||||||
{
|
{
|
||||||
Yes,
|
Yes,
|
||||||
No
|
No
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SkipBuiltIn
|
enum class SkipBuiltIn : char
|
||||||
|
{
|
||||||
|
Yes,
|
||||||
|
No
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class SkipLanguageDefines : char
|
||||||
{
|
{
|
||||||
Yes,
|
Yes,
|
||||||
No
|
No
|
||||||
@@ -54,6 +60,7 @@ public:
|
|||||||
CompilerOptionsBuilder(const ProjectPart &projectPart,
|
CompilerOptionsBuilder(const ProjectPart &projectPart,
|
||||||
UseSystemHeader useSystemHeader = UseSystemHeader::No,
|
UseSystemHeader useSystemHeader = UseSystemHeader::No,
|
||||||
SkipBuiltIn skipBuiltInHeaderPathsAndDefines = SkipBuiltIn::No,
|
SkipBuiltIn skipBuiltInHeaderPathsAndDefines = SkipBuiltIn::No,
|
||||||
|
SkipLanguageDefines skipLanguageDefines = SkipLanguageDefines::Yes,
|
||||||
QString clangVersion = QString(),
|
QString clangVersion = QString(),
|
||||||
QString clangResourceDirectory = QString());
|
QString clangResourceDirectory = QString());
|
||||||
|
|
||||||
@@ -107,12 +114,13 @@ private:
|
|||||||
void addWrappedQtHeadersIncludePath(QStringList &list);
|
void addWrappedQtHeadersIncludePath(QStringList &list);
|
||||||
|
|
||||||
QStringList m_options;
|
QStringList m_options;
|
||||||
UseSystemHeader m_useSystemHeader;
|
|
||||||
|
|
||||||
QString m_clangVersion;
|
QString m_clangVersion;
|
||||||
QString m_clangResourceDirectory;
|
QString m_clangResourceDirectory;
|
||||||
|
|
||||||
|
UseSystemHeader m_useSystemHeader;
|
||||||
SkipBuiltIn m_skipBuiltInHeaderPathsAndDefines;
|
SkipBuiltIn m_skipBuiltInHeaderPathsAndDefines;
|
||||||
|
SkipLanguageDefines m_skipLanguageDefines;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
@@ -158,12 +158,6 @@ bool static hasFlagEffectOnMacros(const QString &flag)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QVector<QByteArray>, unwantedMacrosMsvc,
|
|
||||||
({"_MSVC_LANG",
|
|
||||||
"_MSC_BUILD",
|
|
||||||
"_MSC_FULL_VER",
|
|
||||||
"_MSC_VER"}))
|
|
||||||
|
|
||||||
ToolChain::MacroInspectionRunner AbstractMsvcToolChain::createMacroInspectionRunner() const
|
ToolChain::MacroInspectionRunner AbstractMsvcToolChain::createMacroInspectionRunner() const
|
||||||
{
|
{
|
||||||
Utils::Environment env(m_lastEnvironment);
|
Utils::Environment env(m_lastEnvironment);
|
||||||
@@ -182,11 +176,8 @@ ToolChain::MacroInspectionRunner AbstractMsvcToolChain::createMacroInspectionRun
|
|||||||
return cachedMacros.value();
|
return cachedMacros.value();
|
||||||
|
|
||||||
const Macros macros = msvcPredefinedMacros(filteredFlags, env);
|
const Macros macros = msvcPredefinedMacros(filteredFlags, env);
|
||||||
const QVector<Macro> filteredMacros = Utils::filtered(macros, [](const Macro &m) {
|
|
||||||
return !ToolChain::isUnwantedMacro(m) && !unwantedMacrosMsvc->contains(m.key);
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto report = MacroInspectionReport{filteredMacros,
|
const auto report = MacroInspectionReport{macros,
|
||||||
languageVersionForMsvc(lang, macros)};
|
languageVersionForMsvc(lang, macros)};
|
||||||
macroCache->insert(filteredFlags, report);
|
macroCache->insert(filteredFlags, report);
|
||||||
|
|
||||||
|
@@ -441,16 +441,13 @@ ToolChain::MacroInspectionRunner GccToolChain::createMacroInspectionRunner() con
|
|||||||
const Macros macros = gccPredefinedMacros(findLocalCompiler(compilerCommand, env),
|
const Macros macros = gccPredefinedMacros(findLocalCompiler(compilerCommand, env),
|
||||||
arguments,
|
arguments,
|
||||||
env.toStringList());
|
env.toStringList());
|
||||||
const QVector<Macro> filteredMacros = Utils::filtered(macros, [](const Macro &m) {
|
|
||||||
return !isUnwantedMacro(m);
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto report = MacroInspectionReport{filteredMacros, languageVersion(lang, macros)};
|
const auto report = MacroInspectionReport{macros, languageVersion(lang, macros)};
|
||||||
macroCache->insert(arguments, report);
|
macroCache->insert(arguments, report);
|
||||||
|
|
||||||
qCDebug(gccLog) << "MacroInspectionReport for code model:";
|
qCDebug(gccLog) << "MacroInspectionReport for code model:";
|
||||||
qCDebug(gccLog) << "Language version:" << static_cast<int>(report.languageVersion);
|
qCDebug(gccLog) << "Language version:" << static_cast<int>(report.languageVersion);
|
||||||
for (const Macro &m : filteredMacros) {
|
for (const Macro &m : macros) {
|
||||||
qCDebug(gccLog) << compilerCommand.toUserOutput()
|
qCDebug(gccLog) << compilerCommand.toUserOutput()
|
||||||
<< (lang == Constants::CXX_LANGUAGE_ID ? ": C++ [" : ": C [")
|
<< (lang == Constants::CXX_LANGUAGE_ID ? ": C++ [" : ": C [")
|
||||||
<< arguments.join(", ") << "]"
|
<< arguments.join(", ") << "]"
|
||||||
|
@@ -345,14 +345,6 @@ LanguageVersion ToolChain::languageVersion(const Core::Id &language, const Macro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(const QVector<QByteArray>, unwantedMacros,
|
|
||||||
({"__cplusplus", "__STDC_VERSION__"}))
|
|
||||||
|
|
||||||
bool ToolChain::isUnwantedMacro(const Macro ¯o)
|
|
||||||
{
|
|
||||||
return unwantedMacros->contains(macro.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Used by the tool chain kit information to validate the kit.
|
Used by the tool chain kit information to validate the kit.
|
||||||
*/
|
*/
|
||||||
|
@@ -151,7 +151,6 @@ public:
|
|||||||
void setLanguage(Core::Id language);
|
void setLanguage(Core::Id language);
|
||||||
static LanguageVersion cxxLanguageVersion(const QByteArray &cplusplusMacroValue);
|
static LanguageVersion cxxLanguageVersion(const QByteArray &cplusplusMacroValue);
|
||||||
static LanguageVersion languageVersion(const Core::Id &language, const Macros ¯os);
|
static LanguageVersion languageVersion(const Core::Id &language, const Macros ¯os);
|
||||||
static bool isUnwantedMacro(const Macro ¯o);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit ToolChain(Core::Id typeId, Detection d);
|
explicit ToolChain(Core::Id typeId, Detection d);
|
||||||
|
@@ -43,8 +43,9 @@ MATCHER_P(IsPartOfHeader, headerPart, std::string(negation ? "isn't " : "is ") +
|
|||||||
{
|
{
|
||||||
return arg.contains(QString::fromStdString(headerPart));
|
return arg.contains(QString::fromStdString(headerPart));
|
||||||
}
|
}
|
||||||
|
namespace {
|
||||||
|
|
||||||
class CompilerOptionsBuilderTest : public ::testing::Test
|
class CompilerOptionsBuilder : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
void SetUp() final
|
void SetUp() final
|
||||||
@@ -57,7 +58,13 @@ protected:
|
|||||||
projectPart.extraCodeModelFlags = QStringList{"-arch", "x86_64"};
|
projectPart.extraCodeModelFlags = QStringList{"-arch", "x86_64"};
|
||||||
|
|
||||||
projectPart.precompiledHeaders = QStringList{TESTDATA_DIR "/compileroptionsbuilder.pch"};
|
projectPart.precompiledHeaders = QStringList{TESTDATA_DIR "/compileroptionsbuilder.pch"};
|
||||||
projectPart.toolChainMacros = {ProjectExplorer::Macro{"foo", "bar"}};
|
projectPart.toolChainMacros = {ProjectExplorer::Macro{"foo", "bar"},
|
||||||
|
ProjectExplorer::Macro{"__cplusplus", "2"},
|
||||||
|
ProjectExplorer::Macro{"__STDC_VERSION__", "2"},
|
||||||
|
ProjectExplorer::Macro{"_MSVC_LANG", "2"},
|
||||||
|
ProjectExplorer::Macro{"_MSC_BUILD", "2"},
|
||||||
|
ProjectExplorer::Macro{"_MSC_FULL_VER", "1900"},
|
||||||
|
ProjectExplorer::Macro{"_MSC_VER", "19"}};
|
||||||
projectPart.projectMacros = {ProjectExplorer::Macro{"projectFoo", "projectBar"}};
|
projectPart.projectMacros = {ProjectExplorer::Macro{"projectFoo", "projectBar"}};
|
||||||
projectPart.qtVersion = ProjectPart::Qt5;
|
projectPart.qtVersion = ProjectPart::Qt5;
|
||||||
|
|
||||||
@@ -68,31 +75,51 @@ protected:
|
|||||||
|
|
||||||
std::unique_ptr<Project> project{std::make_unique<ProjectExplorer::Project>()};
|
std::unique_ptr<Project> project{std::make_unique<ProjectExplorer::Project>()};
|
||||||
ProjectPart projectPart;
|
ProjectPart projectPart;
|
||||||
CompilerOptionsBuilder compilerOptionsBuilder{projectPart};
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder{projectPart};
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddToolchainAndProjectMacros)
|
TEST_F(CompilerOptionsBuilder, AddToolchainAndProjectMacros)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addToolchainAndProjectMacros();
|
compilerOptionsBuilder.addToolchainAndProjectMacros();
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-Dfoo=bar", "-DprojectFoo=projectBar"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-Dfoo=bar", "-DprojectFoo=projectBar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddWordWidth)
|
TEST_F(CompilerOptionsBuilder, AddToolchainAndProjectMacrosWithoutSkipingLanguageDefines)
|
||||||
|
{
|
||||||
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder{projectPart,
|
||||||
|
CppTools::UseSystemHeader::No,
|
||||||
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools:: SkipLanguageDefines::No};
|
||||||
|
|
||||||
|
compilerOptionsBuilder.addToolchainAndProjectMacros();
|
||||||
|
|
||||||
|
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||||
|
ElementsAre("-Dfoo=bar",
|
||||||
|
"-D__cplusplus=2",
|
||||||
|
"-D__STDC_VERSION__=2",
|
||||||
|
"-D_MSVC_LANG=2",
|
||||||
|
"-D_MSC_BUILD=2",
|
||||||
|
"-D_MSC_FULL_VER=1900",
|
||||||
|
"-D_MSC_VER=19",
|
||||||
|
"-DprojectFoo=projectBar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(CompilerOptionsBuilder, AddWordWidth)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addWordWidth();
|
compilerOptionsBuilder.addWordWidth();
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-m64"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-m64"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddToolchainFlags)
|
TEST_F(CompilerOptionsBuilder, AddToolchainFlags)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addToolchainFlags();
|
compilerOptionsBuilder.addToolchainFlags();
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-undef"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-undef"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, HeaderPathOptionsOrder)
|
TEST_F(CompilerOptionsBuilder, HeaderPathOptionsOrder)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addHeaderPathOptions();
|
compilerOptionsBuilder.addHeaderPathOptions();
|
||||||
|
|
||||||
@@ -103,9 +130,9 @@ TEST_F(CompilerOptionsBuilderTest, HeaderPathOptionsOrder)
|
|||||||
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, UseSystemHeader)
|
TEST_F(CompilerOptionsBuilder, UseSystemHeader)
|
||||||
{
|
{
|
||||||
CompilerOptionsBuilder compilerOptionsBuilder(projectPart, CppTools::UseSystemHeader::Yes);
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart, CppTools::UseSystemHeader::Yes);
|
||||||
|
|
||||||
compilerOptionsBuilder.addHeaderPathOptions();
|
compilerOptionsBuilder.addHeaderPathOptions();
|
||||||
|
|
||||||
@@ -116,11 +143,12 @@ TEST_F(CompilerOptionsBuilderTest, UseSystemHeader)
|
|||||||
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, ClangHeadersPath)
|
TEST_F(CompilerOptionsBuilder, ClangHeadersPath)
|
||||||
{
|
{
|
||||||
CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
||||||
CppTools::UseSystemHeader::No,
|
CppTools::UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::No,
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
"7.0.0",
|
"7.0.0",
|
||||||
"");
|
"");
|
||||||
|
|
||||||
@@ -135,7 +163,7 @@ TEST_F(CompilerOptionsBuilderTest, ClangHeadersPath)
|
|||||||
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, ClangHeadersAndCppIncludesPathsOrderMacOs)
|
TEST_F(CompilerOptionsBuilder, ClangHeadersAndCppIncludesPathsOrderMacOs)
|
||||||
{
|
{
|
||||||
auto defaultPaths = projectPart.headerPaths;
|
auto defaultPaths = projectPart.headerPaths;
|
||||||
projectPart.headerPaths = {HeaderPath{"/usr/include/c++/4.2.1", HeaderPathType::BuiltIn},
|
projectPart.headerPaths = {HeaderPath{"/usr/include/c++/4.2.1", HeaderPathType::BuiltIn},
|
||||||
@@ -146,9 +174,10 @@ TEST_F(CompilerOptionsBuilderTest, ClangHeadersAndCppIncludesPathsOrderMacOs)
|
|||||||
HeaderPath{"/usr/include", HeaderPathType::BuiltIn}
|
HeaderPath{"/usr/include", HeaderPathType::BuiltIn}
|
||||||
};
|
};
|
||||||
projectPart.headerPaths.append(defaultPaths);
|
projectPart.headerPaths.append(defaultPaths);
|
||||||
CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
||||||
CppTools::UseSystemHeader::No,
|
CppTools::UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::No,
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
"7.0.0",
|
"7.0.0",
|
||||||
"");
|
"");
|
||||||
|
|
||||||
@@ -168,7 +197,7 @@ TEST_F(CompilerOptionsBuilderTest, ClangHeadersAndCppIncludesPathsOrderMacOs)
|
|||||||
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
"-isystem", QDir::toNativeSeparators("/tmp/builtin_path")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, ClangHeadersAndCppIncludesPathsOrderLinux)
|
TEST_F(CompilerOptionsBuilder, ClangHeadersAndCppIncludesPathsOrderLinux)
|
||||||
{
|
{
|
||||||
projectPart.headerPaths = {HeaderPath{"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8", HeaderPathType::BuiltIn},
|
projectPart.headerPaths = {HeaderPath{"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8", HeaderPathType::BuiltIn},
|
||||||
HeaderPath{"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward", HeaderPathType::BuiltIn},
|
HeaderPath{"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward", HeaderPathType::BuiltIn},
|
||||||
@@ -179,9 +208,10 @@ TEST_F(CompilerOptionsBuilderTest, ClangHeadersAndCppIncludesPathsOrderLinux)
|
|||||||
HeaderPath{"/usr/include", HeaderPathType::BuiltIn}
|
HeaderPath{"/usr/include", HeaderPathType::BuiltIn}
|
||||||
};
|
};
|
||||||
projectPart.toolChainTargetTriple = "x86_64-linux-gnu";
|
projectPart.toolChainTargetTriple = "x86_64-linux-gnu";
|
||||||
CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
CppTools::CompilerOptionsBuilder compilerOptionsBuilder(projectPart,
|
||||||
CppTools::UseSystemHeader::No,
|
CppTools::UseSystemHeader::No,
|
||||||
CppTools::SkipBuiltIn::No,
|
CppTools::SkipBuiltIn::No,
|
||||||
|
CppTools::SkipLanguageDefines::Yes,
|
||||||
"7.0.0",
|
"7.0.0",
|
||||||
"");
|
"");
|
||||||
|
|
||||||
@@ -200,36 +230,36 @@ TEST_F(CompilerOptionsBuilderTest, ClangHeadersAndCppIncludesPathsOrderLinux)
|
|||||||
"-isystem", QDir::toNativeSeparators("/usr/include")));
|
"-isystem", QDir::toNativeSeparators("/usr/include")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, NoPrecompiledHeader)
|
TEST_F(CompilerOptionsBuilder, NoPrecompiledHeader)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addPrecompiledHeaderOptions(CompilerOptionsBuilder::PchUsage::None);
|
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options().empty(), true);
|
ASSERT_THAT(compilerOptionsBuilder.options().empty(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, UsePrecompiledHeader)
|
TEST_F(CompilerOptionsBuilder, UsePrecompiledHeader)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addPrecompiledHeaderOptions(CompilerOptionsBuilder::PchUsage::Use);
|
compilerOptionsBuilder.addPrecompiledHeaderOptions(CppTools::CompilerOptionsBuilder::PchUsage::Use);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(),
|
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||||
ElementsAre("-include", QDir::toNativeSeparators(TESTDATA_DIR "/compileroptionsbuilder.pch")));
|
ElementsAre("-include", QDir::toNativeSeparators(TESTDATA_DIR "/compileroptionsbuilder.pch")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddMacros)
|
TEST_F(CompilerOptionsBuilder, AddMacros)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addMacros(ProjectExplorer::Macros{ProjectExplorer::Macro{"key", "value"}});
|
compilerOptionsBuilder.addMacros(ProjectExplorer::Macros{ProjectExplorer::Macro{"key", "value"}});
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-Dkey=value"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-Dkey=value"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddTargetTriple)
|
TEST_F(CompilerOptionsBuilder, AddTargetTriple)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.addTargetTriple();
|
compilerOptionsBuilder.addTargetTriple();
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-target", "x86_64-apple-darwin10"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-target", "x86_64-apple-darwin10"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, EnableCExceptions)
|
TEST_F(CompilerOptionsBuilder, EnableCExceptions)
|
||||||
{
|
{
|
||||||
projectPart.languageVersion = ProjectExplorer::LanguageVersion::C99;
|
projectPart.languageVersion = ProjectExplorer::LanguageVersion::C99;
|
||||||
|
|
||||||
@@ -238,28 +268,28 @@ TEST_F(CompilerOptionsBuilderTest, EnableCExceptions)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fexceptions"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fexceptions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, EnableCXXExceptions)
|
TEST_F(CompilerOptionsBuilder, EnableCXXExceptions)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.enableExceptions();
|
compilerOptionsBuilder.enableExceptions();
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fcxx-exceptions", "-fexceptions"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fcxx-exceptions", "-fexceptions"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, InsertWrappedQtHeaders)
|
TEST_F(CompilerOptionsBuilder, InsertWrappedQtHeaders)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.insertWrappedQtHeaders();
|
compilerOptionsBuilder.insertWrappedQtHeaders();
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(IsPartOfHeader("wrappedQtHeaders")));
|
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(IsPartOfHeader("wrappedQtHeaders")));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, SetLanguageVersion)
|
TEST_F(CompilerOptionsBuilder, SetLanguageVersion)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.updateLanguageOption(ProjectFile::CXXSource);
|
compilerOptionsBuilder.updateLanguageOption(ProjectFile::CXXSource);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-x", "c++"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-x", "c++"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, HandleLanguageExtension)
|
TEST_F(CompilerOptionsBuilder, HandleLanguageExtension)
|
||||||
{
|
{
|
||||||
projectPart.languageExtensions = ProjectExplorer::LanguageExtension::ObjectiveC;
|
projectPart.languageExtensions = ProjectExplorer::LanguageExtension::ObjectiveC;
|
||||||
|
|
||||||
@@ -268,7 +298,7 @@ TEST_F(CompilerOptionsBuilderTest, HandleLanguageExtension)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-x", "objective-c++"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-x", "objective-c++"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, UpdateLanguageVersion)
|
TEST_F(CompilerOptionsBuilder, UpdateLanguageVersion)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.updateLanguageOption(ProjectFile::CXXSource);
|
compilerOptionsBuilder.updateLanguageOption(ProjectFile::CXXSource);
|
||||||
|
|
||||||
@@ -277,7 +307,7 @@ TEST_F(CompilerOptionsBuilderTest, UpdateLanguageVersion)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-x", "c++-header"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-x", "c++-header"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddMsvcCompatibilityVersion)
|
TEST_F(CompilerOptionsBuilder, AddMsvcCompatibilityVersion)
|
||||||
{
|
{
|
||||||
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
||||||
projectPart.toolChainMacros.append(ProjectExplorer::Macro{"_MSC_FULL_VER", "190000000"});
|
projectPart.toolChainMacros.append(ProjectExplorer::Macro{"_MSC_FULL_VER", "190000000"});
|
||||||
@@ -287,7 +317,7 @@ TEST_F(CompilerOptionsBuilderTest, AddMsvcCompatibilityVersion)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fms-compatibility-version=19.00"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fms-compatibility-version=19.00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, UndefineCppLanguageFeatureMacrosForMsvc2015)
|
TEST_F(CompilerOptionsBuilder, UndefineCppLanguageFeatureMacrosForMsvc2015)
|
||||||
{
|
{
|
||||||
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
||||||
projectPart.isMsvc2015Toolchain = true;
|
projectPart.isMsvc2015Toolchain = true;
|
||||||
@@ -297,7 +327,7 @@ TEST_F(CompilerOptionsBuilderTest, UndefineCppLanguageFeatureMacrosForMsvc2015)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(QString{"-U__cpp_aggregate_bases"}));
|
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(QString{"-U__cpp_aggregate_bases"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddDefineFunctionMacrosMsvc)
|
TEST_F(CompilerOptionsBuilder, AddDefineFunctionMacrosMsvc)
|
||||||
{
|
{
|
||||||
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
||||||
|
|
||||||
@@ -306,7 +336,7 @@ TEST_F(CompilerOptionsBuilderTest, AddDefineFunctionMacrosMsvc)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(QString{"-D__FUNCTION__=\"\""}));
|
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(QString{"-D__FUNCTION__=\"\""}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, AddProjectConfigFileInclude)
|
TEST_F(CompilerOptionsBuilder, AddProjectConfigFileInclude)
|
||||||
{
|
{
|
||||||
projectPart.projectConfigFile = "dummy_file.h";
|
projectPart.projectConfigFile = "dummy_file.h";
|
||||||
|
|
||||||
@@ -315,7 +345,7 @@ TEST_F(CompilerOptionsBuilderTest, AddProjectConfigFileInclude)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-include", "dummy_file.h"));
|
ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-include", "dummy_file.h"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, UndefineClangVersionMacrosForMsvc)
|
TEST_F(CompilerOptionsBuilder, UndefineClangVersionMacrosForMsvc)
|
||||||
{
|
{
|
||||||
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
projectPart.toolchainType = ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID;
|
||||||
|
|
||||||
@@ -324,9 +354,9 @@ TEST_F(CompilerOptionsBuilderTest, UndefineClangVersionMacrosForMsvc)
|
|||||||
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(QString{"-U__clang__"}));
|
ASSERT_THAT(compilerOptionsBuilder.options(), Contains(QString{"-U__clang__"}));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CompilerOptionsBuilderTest, BuildAllOptions)
|
TEST_F(CompilerOptionsBuilder, BuildAllOptions)
|
||||||
{
|
{
|
||||||
compilerOptionsBuilder.build(ProjectFile::CXXSource, CompilerOptionsBuilder::PchUsage::None);
|
compilerOptionsBuilder.build(ProjectFile::CXXSource, CppTools::CompilerOptionsBuilder::PchUsage::None);
|
||||||
|
|
||||||
ASSERT_THAT(compilerOptionsBuilder.options(),
|
ASSERT_THAT(compilerOptionsBuilder.options(),
|
||||||
ElementsAre(
|
ElementsAre(
|
||||||
@@ -341,3 +371,4 @@ TEST_F(CompilerOptionsBuilderTest, BuildAllOptions)
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user