cmStringCommand: Add GENEX_STRIP subcommand.

Strip out any generator expressions in the input string.
This commit is contained in:
Stephen Kelly 2014-03-18 16:21:08 +01:00
parent bf98cc252f
commit 28e1d2f8fc
5 changed files with 43 additions and 0 deletions

View File

@ -35,6 +35,7 @@ String operations.
string(FIND <string> <substring> <output variable> [REVERSE]) string(FIND <string> <substring> <output variable> [REVERSE])
string(TIMESTAMP <output variable> [<format string>] [UTC]) string(TIMESTAMP <output variable> [<format string>] [UTC])
string(MAKE_C_IDENTIFIER <input string> <output variable>) 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 REGEX MATCH will match the regular expression once and store the match
in the output variable. 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 MAKE_C_IDENTIFIER will write a string which can be used as an
identifier in C. 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``.

View File

@ -0,0 +1,6 @@
string-GENEX_STRIP
------------------
* The :command:`string` command learned a new ``GENEX_STRIP`` subcommand
which removes
:manual:`generator expression <cmake-generator-expressions(7)>`.

View File

@ -101,6 +101,10 @@ bool cmStringCommand
{ {
return this->HandleMakeCIdentifierCommand(args); return this->HandleMakeCIdentifierCommand(args);
} }
else if(subCommand == "GENEX_STRIP")
{
return this->HandleGenexStripCommand(args);
}
std::string e = "does not recognize sub-command "+subCommand; std::string e = "does not recognize sub-command "+subCommand;
this->SetError(e); this->SetError(e);
@ -809,6 +813,27 @@ bool cmStringCommand
return true; 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,
cmGeneratorExpression::StripAllGeneratorExpressions);
const std::string& variableName = args[2];
this->Makefile->AddDefinition(variableName, result.c_str());
return true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmStringCommand::HandleStripCommand( bool cmStringCommand::HandleStripCommand(
std::vector<std::string> const& args) std::vector<std::string> const& args)

View File

@ -75,6 +75,7 @@ protected:
bool HandleFindCommand(std::vector<std::string> const& args); bool HandleFindCommand(std::vector<std::string> const& args);
bool HandleTimestampCommand(std::vector<std::string> const& args); bool HandleTimestampCommand(std::vector<std::string> const& args);
bool HandleMakeCIdentifierCommand(std::vector<std::string> const& args); bool HandleMakeCIdentifierCommand(std::vector<std::string> const& args);
bool HandleGenexStripCommand(std::vector<std::string> const& args);
class RegexReplacement class RegexReplacement
{ {

View File

@ -286,3 +286,9 @@ string(MAKE_C_IDENTIFIER "1one-two$" MCI_1)
if(NOT MCI_1 STREQUAL _1one_two_) if(NOT MCI_1 STREQUAL _1one_two_)
message(SEND_ERROR "MAKE_C_IDENTIFIER did not create expected result.") message(SEND_ERROR "MAKE_C_IDENTIFIER did not create expected result.")
endif() endif()
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}")
endif()