Procházet zdrojové kódy

cmStringCommand: Add GENEX_STRIP subcommand.

Strip out any generator expressions in the input string.
Stephen Kelly před 11 roky
rodič
revize
28e1d2f8fc

+ 5 - 0
Help/command/string.rst

@@ -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``.

+ 6 - 0
Help/release/dev/string-GENEX_STRIP.rst

@@ -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)>`.

+ 25 - 0
Source/cmStringCommand.cxx

@@ -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)

+ 1 - 0
Source/cmStringCommand.h

@@ -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
   {
   {

+ 6 - 0
Tests/StringFileTest/CMakeLists.txt

@@ -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()