Commit 28e1d2f8 authored by Stephen Kelly's avatar Stephen Kelly
Browse files

cmStringCommand: Add GENEX_STRIP subcommand.

Strip out any generator expressions in the input string.
parent bf98cc25
......@@ -35,6 +35,7 @@ String operations.
string(FIND <string> <substring> <output variable> [REVERSE])
string(TIMESTAMP <output variable> [<format string>] [UTC])
string(MAKE_C_IDENTIFIER <input string> <output variable>)
string(GENEX_STRIP <input string> <output variable>)
REGEX MATCH will match the regular expression once and store the match
in the output variable.
......@@ -154,3 +155,7 @@ If no explicit <format string> is given it will default to:
MAKE_C_IDENTIFIER will write a string which can be used as an
identifier in C.
``GENEX_STRIP`` will strip any
:manual:`generator expressions <cmake-generator-expressions(7)>` from the
``input string`` and store the result in the ``output variable``.
* The :command:`string` command learned a new ``GENEX_STRIP`` subcommand
which removes
:manual:`generator expression <cmake-generator-expressions(7)>`.
......@@ -101,6 +101,10 @@ bool cmStringCommand
return this->HandleMakeCIdentifierCommand(args);
else if(subCommand == "GENEX_STRIP")
return this->HandleGenexStripCommand(args);
std::string e = "does not recognize sub-command "+subCommand;
......@@ -809,6 +813,27 @@ bool cmStringCommand
return true;
bool cmStringCommand
::HandleGenexStripCommand(std::vector<std::string> const& args)
if(args.size() != 3)
this->SetError("sub-command GENEX_STRIP requires two arguments.");
return false;
const std::string& input = args[1];
std::string result = cmGeneratorExpression::Preprocess(input,
const std::string& variableName = args[2];
this->Makefile->AddDefinition(variableName, result.c_str());
return true;
bool cmStringCommand::HandleStripCommand(
std::vector<std::string> const& args)
......@@ -75,6 +75,7 @@ protected:
bool HandleFindCommand(std::vector<std::string> const& args);
bool HandleTimestampCommand(std::vector<std::string> const& args);
bool HandleMakeCIdentifierCommand(std::vector<std::string> const& args);
bool HandleGenexStripCommand(std::vector<std::string> const& args);
class RegexReplacement
......@@ -286,3 +286,9 @@ string(MAKE_C_IDENTIFIER "1one-two$" MCI_1)
if(NOT MCI_1 STREQUAL _1one_two_)
message(SEND_ERROR "MAKE_C_IDENTIFIER did not create expected result.")
string(GENEX_STRIP "one;$<1:two;three>;four;$<TARGET_OBJECTS:some_target>" strip_result)
if (NOT strip_result STREQUAL "one;four")
message(SEND_ERROR "GENEX_STRIP did not create expected result: ${strip_result}")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment