summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2014-03-18 15:21:08 (GMT)
committerStephen Kelly <steveire@gmail.com>2014-03-31 21:18:44 (GMT)
commit28e1d2f8fc08516e8fc3a009777437d3e086b8e6 (patch)
tree6706855db40e1726ad1d5e29bf8c763c7286156e
parentbf98cc252f18e761ed9a57d2f7a9304bfbb621de (diff)
downloadCMake-28e1d2f8fc08516e8fc3a009777437d3e086b8e6.zip
CMake-28e1d2f8fc08516e8fc3a009777437d3e086b8e6.tar.gz
CMake-28e1d2f8fc08516e8fc3a009777437d3e086b8e6.tar.bz2
cmStringCommand: Add GENEX_STRIP subcommand.
Strip out any generator expressions in the input string.
-rw-r--r--Help/command/string.rst5
-rw-r--r--Help/release/dev/string-GENEX_STRIP.rst6
-rw-r--r--Source/cmStringCommand.cxx25
-rw-r--r--Source/cmStringCommand.h1
-rw-r--r--Tests/StringFileTest/CMakeLists.txt6
5 files changed, 43 insertions, 0 deletions
diff --git a/Help/command/string.rst b/Help/command/string.rst
index af18825..abde6ee 100644
--- a/Help/command/string.rst
+++ b/Help/command/string.rst
@@ -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``.
diff --git a/Help/release/dev/string-GENEX_STRIP.rst b/Help/release/dev/string-GENEX_STRIP.rst
new file mode 100644
index 0000000..b5b1074
--- /dev/null
+++ b/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)>`.
diff --git a/Source/cmStringCommand.cxx b/Source/cmStringCommand.cxx
index 7bc7b05..ea762eb 100644
--- a/Source/cmStringCommand.cxx
+++ b/Source/cmStringCommand.cxx
@@ -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;
this->SetError(e);
@@ -810,6 +814,27 @@ bool cmStringCommand
}
//----------------------------------------------------------------------------
+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(
std::vector<std::string> const& args)
{
diff --git a/Source/cmStringCommand.h b/Source/cmStringCommand.h
index b8053c5..5b7412d 100644
--- a/Source/cmStringCommand.h
+++ b/Source/cmStringCommand.h
@@ -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
{
diff --git a/Tests/StringFileTest/CMakeLists.txt b/Tests/StringFileTest/CMakeLists.txt
index 00383ab..be6d8fe 100644
--- a/Tests/StringFileTest/CMakeLists.txt
+++ b/Tests/StringFileTest/CMakeLists.txt
@@ -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.")
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()