summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmCMakeCommand.cxx25
-rw-r--r--Source/cmCMakeCommand.h4
-rw-r--r--Tests/RunCMake/cmake_command/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments-stderr.txt6
-rw-r--r--Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments.cmake12
5 files changed, 40 insertions, 8 deletions
diff --git a/Source/cmCMakeCommand.cxx b/Source/cmCMakeCommand.cxx
index c11a003..da15b1a 100644
--- a/Source/cmCMakeCommand.cxx
+++ b/Source/cmCMakeCommand.cxx
@@ -4,6 +4,9 @@
#include <algorithm>
#include <cstddef>
+#include <iosfwd>
+#include <memory>
+#include <string>
#include "cmExecutionStatus.h"
#include "cmListFileCache.h"
@@ -11,7 +14,14 @@
#include "cmRange.h"
#include "cmStringAlgorithms.h"
-bool cmCMakeCommand(std::vector<std::string> const& args,
+inline std::ostream& operator<<(std::ostream& os,
+ cmListFileArgument const& arg)
+{
+ os << arg.Value;
+ return os;
+}
+
+bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
if (args.empty()) {
@@ -24,7 +34,7 @@ bool cmCMakeCommand(std::vector<std::string> const& args,
bool result = false;
- if (args[0] == "INVOKE") {
+ if (args[0].Value == "INVOKE") {
if (args.size() == 1) {
status.SetError("called with incorrect number of arguments");
return false;
@@ -32,26 +42,29 @@ bool cmCMakeCommand(std::vector<std::string> const& args,
// First argument is the name of the function to call
cmListFileFunction func;
- func.Name = args[1];
+ func.Name = args[1].Value;
func.Line = context.Line;
// The rest of the arguments are passed to the function call above
func.Arguments.resize(args.size() - 1);
for (size_t i = 2; i < args.size(); ++i) {
cmListFileArgument lfarg;
+ lfarg.Delim = args[i].Delim;
lfarg.Line = context.Line;
- lfarg.Value = args[i];
+ lfarg.Value = args[i].Value;
func.Arguments.emplace_back(lfarg);
}
result = makefile.ExecuteCommand(func, status);
- } else if (args[0] == "EVAL") {
+ } else if (args[0].Value == "EVAL") {
if (args.size() < 2) {
status.SetError("called with incorrect number of arguments");
return false;
}
- auto code_iter = std::find(args.begin(), args.end(), "CODE");
+ auto code_iter = std::find_if(
+ args.begin(), args.end(),
+ [](cmListFileArgument const& arg) { return arg.Value == "CODE"; });
if (code_iter == args.end()) {
status.SetError("called without CODE argument");
return false;
diff --git a/Source/cmCMakeCommand.h b/Source/cmCMakeCommand.h
index cf9f4c3..7dbecff 100644
--- a/Source/cmCMakeCommand.h
+++ b/Source/cmCMakeCommand.h
@@ -5,16 +5,16 @@
#include "cmConfigure.h" // IWYU pragma: keep
-#include <string>
#include <vector>
class cmExecutionStatus;
+struct cmListFileArgument;
/**
* \brief Calls a scripted or build-in command
*
*/
-bool cmCMakeCommand(std::vector<std::string> const& args,
+bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status);
#endif
diff --git a/Tests/RunCMake/cmake_command/RunCMakeTest.cmake b/Tests/RunCMake/cmake_command/RunCMakeTest.cmake
index 2b6e7a2..0f12b80 100644
--- a/Tests/RunCMake/cmake_command/RunCMakeTest.cmake
+++ b/Tests/RunCMake/cmake_command/RunCMakeTest.cmake
@@ -5,6 +5,7 @@ run_cmake(cmake_command_unknown_meta_operation)
run_cmake(cmake_command_invoke_message)
run_cmake(cmake_command_invoke_message_fatal_error)
run_cmake(cmake_command_invoke_no_parameters)
+run_cmake(cmake_command_invoke_preserve_arguments)
run_cmake(cmake_command_invoke_unknown_function)
run_cmake(cmake_command_eval_message)
run_cmake(cmake_command_eval_message_fatal_error)
diff --git a/Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments-stderr.txt b/Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments-stderr.txt
new file mode 100644
index 0000000..4670e60
--- /dev/null
+++ b/Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments-stderr.txt
@@ -0,0 +1,6 @@
+foo\(...\)
+\[a;b\]
+\[c;d\]
+cmake_command\(INVOKE foo ...\)
+\[a;b\]
+\[c;d\]
diff --git a/Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments.cmake b/Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments.cmake
new file mode 100644
index 0000000..53ac2e6
--- /dev/null
+++ b/Tests/RunCMake/cmake_command/cmake_command_invoke_preserve_arguments.cmake
@@ -0,0 +1,12 @@
+function(foo arg1 arg2)
+ math(EXPR last "${ARGC} - 1")
+ foreach(i RANGE 0 ${last})
+ message("[${ARGV${i}}]")
+ endforeach()
+endfunction()
+
+message("foo(...)")
+foo("a;b" "c;d")
+
+message("cmake_command(INVOKE foo ...)")
+cmake_command(INVOKE foo "a;b" "c;d")