diff options
author | Sebastian Lipponer <mail@sebastianlipponer.de> | 2019-04-03 19:26:29 (GMT) |
---|---|---|
committer | Sebastian Lipponer <mail@sebastianlipponer.de> | 2019-04-08 17:57:22 (GMT) |
commit | 698f51abacb572508c5386b406c2c8a30f0be1e8 (patch) | |
tree | ec2714d513a14cc27ed669d3f51a99b5f3a67a7a /Source/cmGeneratorExpressionNode.cxx | |
parent | 4f07fdde26f1de59e2e8c2a32f0af7a2caff422d (diff) | |
download | CMake-698f51abacb572508c5386b406c2c8a30f0be1e8.zip CMake-698f51abacb572508c5386b406c2c8a30f0be1e8.tar.gz CMake-698f51abacb572508c5386b406c2c8a30f0be1e8.tar.bz2 |
Genex: Add $<FILTER:list,INCLUDE|EXCLUDE,regex>
Diffstat (limited to 'Source/cmGeneratorExpressionNode.cxx')
-rw-r--r-- | Source/cmGeneratorExpressionNode.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index cef36fc..d8e1c42 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -28,6 +28,7 @@ #include <algorithm> #include <assert.h> #include <errno.h> +#include <iterator> #include <map> #include <memory> // IWYU pragma: keep #include <set> @@ -327,6 +328,51 @@ static const struct InListNode : public cmGeneratorExpressionNode } } inListNode; +static const struct FilterNode : public cmGeneratorExpressionNode +{ + FilterNode() {} // NOLINT(modernize-use-equals-default) + + int NumExpectedParameters() const override { return 3; } + + std::string Evaluate( + const std::vector<std::string>& parameters, + cmGeneratorExpressionContext* context, + const GeneratorExpressionContent* content, + cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override + { + if (parameters.size() != 3) { + reportError(context, content->GetOriginalExpression(), + "$<FILTER:...> expression requires three parameters"); + return {}; + } + + if (parameters[1] != "INCLUDE" && parameters[1] != "EXCLUDE") { + reportError( + context, content->GetOriginalExpression(), + "$<FILTER:...> second parameter must be either INCLUDE or EXCLUDE"); + return {}; + } + + const bool exclude = parameters[1] == "EXCLUDE"; + + cmsys::RegularExpression re; + if (!re.compile(parameters[2])) { + reportError(context, content->GetOriginalExpression(), + "$<FILTER:...> failed to compile regex"); + return {}; + } + + std::vector<std::string> values, result; + cmSystemTools::ExpandListArgument(parameters.front(), values, true); + + std::copy_if(values.cbegin(), values.cend(), std::back_inserter(result), + [&re, exclude](std::string const& input) { + return exclude ^ re.find(input); + }); + return cmJoin(cmMakeRange(result.cbegin(), result.cend()), ";"); + } +} filterNode; + static const struct RemoveDuplicatesNode : public cmGeneratorExpressionNode { RemoveDuplicatesNode() {} // NOLINT(modernize-use-equals-default) @@ -2331,6 +2377,7 @@ const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode( { "STREQUAL", &strEqualNode }, { "EQUAL", &equalNode }, { "IN_LIST", &inListNode }, + { "FILTER", &filterNode }, { "REMOVE_DUPLICATES", &removeDuplicatesNode }, { "LOWER_CASE", &lowerCaseNode }, { "UPPER_CASE", &upperCaseNode }, |