diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 5c9bcaadd3f..0d2c6d9046d 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -623,7 +623,6 @@ namespace { if (condAttr) mCondition = condAttr; } - explicit Conditional(std::string condition) : mCondition(std::move(condition)) {} static void replaceAll(std::string &c, const std::string &from, const std::string &to) { std::string::size_type pos; @@ -818,10 +817,14 @@ namespace { bool useUnicode = false; }; + struct ExcludedFromBuild : Conditional { + explicit ExcludedFromBuild(const tinyxml2::XMLElement *efb) : Conditional(efb) {} + }; + struct ItemGroupClCompile { explicit ItemGroupClCompile(std::string filename) : mFilename(std::move(filename)) {} ItemGroupClCompile(const tinyxml2::XMLElement *element, std::string file) : mFilename(std::move(file)) { - for (const tinyxml2::XMLElement* childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement()) { + for (const tinyxml2::XMLElement *childElement = element->FirstChildElement(); childElement; childElement = childElement->NextSiblingElement()) { const char *name = childElement->Name(); if (!name) continue; @@ -830,23 +833,18 @@ namespace { const char *text = childElement->GetText(); if (!condition || !text || std::strcmp(text, "true") != 0) continue; - mConditions.emplace_back(condition); + mExcludedFromBuild.emplace_back(childElement); } - // TODO: ForcedIncludeFiles and PrecompiledHeaderFile + // TODO: ForcedIncludeFiles and AdditionalIncludeDirectories } } - bool exclude(const ProjectConfiguration& p, std::vector& errors) const { - if (mConditions.empty()) - return false; - for (const std::string& condition : mConditions) { - Conditional conditional(condition); - if (conditional.conditionIsTrue(p, mFilename, errors)) - return true; - } - return false; + bool excludedfromBuild(const ProjectConfiguration &pc, std::vector &errors) const { + return std::any_of(mExcludedFromBuild.cbegin(), mExcludedFromBuild.cend(), [&](const ExcludedFromBuild &excluded) { + return excluded.conditionIsTrue(pc, mFilename, errors); + }); } std::string mFilename; - std::list mConditions; + std::list mExcludedFromBuild; }; } @@ -1074,7 +1072,7 @@ bool ImportProject::importVcxproj(const std::string &filename, const tinyxml2::X } // check if the file should be excluded for this configuration - if (compile.exclude(p, errors)) + if (compile.excludedfromBuild(p, errors)) continue; FileSettings fs{ compile.mFilename, Standards::Language::None, 0}; // file will be identified later on