mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-03 21:00:01 -05:00
+51
-21
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iosfwd>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -14,13 +13,6 @@
|
|||||||
#include "cmRange.h"
|
#include "cmRange.h"
|
||||||
#include "cmStringAlgorithms.h"
|
#include "cmStringAlgorithms.h"
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& os,
|
|
||||||
cmListFileArgument const& arg)
|
|
||||||
{
|
|
||||||
os << arg.Value;
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
|
bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
|
||||||
cmExecutionStatus& status)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
@@ -34,20 +26,50 @@ bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
|
|||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
if (args[0].Value == "INVOKE") {
|
std::vector<std::string> dispatchExpandedArgs;
|
||||||
if (args.size() == 1) {
|
std::vector<cmListFileArgument> dispatchArgs;
|
||||||
|
dispatchArgs.emplace_back(args[0]);
|
||||||
|
makefile.ExpandArguments(dispatchArgs, dispatchExpandedArgs);
|
||||||
|
|
||||||
|
if (dispatchExpandedArgs.empty()) {
|
||||||
|
status.SetError("called with incorrect number of arguments");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dispatchExpandedArgs[0] == "INVOKE") {
|
||||||
|
if ((args.size() == 1 && dispatchExpandedArgs.size() != 2) ||
|
||||||
|
dispatchExpandedArgs.size() > 2) {
|
||||||
status.SetError("called with incorrect number of arguments");
|
status.SetError("called with incorrect number of arguments");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First argument is the name of the function to call
|
// First argument is the name of the function to call
|
||||||
|
std::string invokeCommand;
|
||||||
|
size_t startArg;
|
||||||
|
if (dispatchExpandedArgs.size() == 1) {
|
||||||
|
std::vector<std::string> functionExpandedArg;
|
||||||
|
std::vector<cmListFileArgument> functionArg;
|
||||||
|
functionArg.emplace_back(args[1]);
|
||||||
|
makefile.ExpandArguments(functionArg, functionExpandedArg);
|
||||||
|
|
||||||
|
if (functionExpandedArg.size() != 1) {
|
||||||
|
status.SetError("called with incorrect number of arguments");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
invokeCommand = functionExpandedArg[0];
|
||||||
|
startArg = 2;
|
||||||
|
} else {
|
||||||
|
invokeCommand = dispatchExpandedArgs[1];
|
||||||
|
startArg = 1;
|
||||||
|
}
|
||||||
|
|
||||||
cmListFileFunction func;
|
cmListFileFunction func;
|
||||||
func.Name = args[1].Value;
|
func.Name = invokeCommand;
|
||||||
func.Line = context.Line;
|
func.Line = context.Line;
|
||||||
|
|
||||||
// The rest of the arguments are passed to the function call above
|
// The rest of the arguments are passed to the function call above
|
||||||
func.Arguments.resize(args.size() - 1);
|
for (size_t i = startArg; i < args.size(); ++i) {
|
||||||
for (size_t i = 2; i < args.size(); ++i) {
|
|
||||||
cmListFileArgument lfarg;
|
cmListFileArgument lfarg;
|
||||||
lfarg.Delim = args[i].Delim;
|
lfarg.Delim = args[i].Delim;
|
||||||
lfarg.Line = context.Line;
|
lfarg.Line = context.Line;
|
||||||
@@ -56,21 +78,29 @@ bool cmCMakeCommand(std::vector<cmListFileArgument> const& args,
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = makefile.ExecuteCommand(func, status);
|
result = makefile.ExecuteCommand(func, status);
|
||||||
} else if (args[0].Value == "EVAL") {
|
} else if (dispatchExpandedArgs[0] == "EVAL") {
|
||||||
if (args.size() < 2) {
|
std::vector<std::string> expandedArgs;
|
||||||
|
makefile.ExpandArguments(args, expandedArgs);
|
||||||
|
|
||||||
|
if (expandedArgs.size() < 2) {
|
||||||
status.SetError("called with incorrect number of arguments");
|
status.SetError("called with incorrect number of arguments");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto code_iter = std::find_if(
|
if (expandedArgs[1] != "CODE") {
|
||||||
args.begin(), args.end(),
|
auto code_iter =
|
||||||
[](cmListFileArgument const& arg) { return arg.Value == "CODE"; });
|
std::find(expandedArgs.begin() + 2, expandedArgs.end(), "CODE");
|
||||||
if (code_iter == args.end()) {
|
if (code_iter == expandedArgs.end()) {
|
||||||
status.SetError("called without CODE argument");
|
status.SetError("called without CODE argument");
|
||||||
|
} else {
|
||||||
|
status.SetError(
|
||||||
|
"called with unsupported arguments between EVAL and CODE arguments");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string code = cmJoin(cmMakeRange(++code_iter, args.end()), " ");
|
const std::string code =
|
||||||
|
cmJoin(cmMakeRange(expandedArgs.begin() + 2, expandedArgs.end()), " ");
|
||||||
result = makefile.ReadListFileAsString(
|
result = makefile.ReadListFileAsString(
|
||||||
code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL"));
|
code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -2,11 +2,20 @@ include(RunCMake)
|
|||||||
|
|
||||||
run_cmake(cmake_command_no_parameters)
|
run_cmake(cmake_command_no_parameters)
|
||||||
run_cmake(cmake_command_unknown_meta_operation)
|
run_cmake(cmake_command_unknown_meta_operation)
|
||||||
|
run_cmake(cmake_command_invoke_double_evaluation)
|
||||||
|
run_cmake(cmake_command_invoke_expanded_command)
|
||||||
|
run_cmake(cmake_command_invoke_expanded_command_and_arguments)
|
||||||
|
run_cmake(cmake_command_invoke_expanded_command_with_explicit_argument)
|
||||||
|
run_cmake(cmake_command_invoke_expand_command_name)
|
||||||
|
run_cmake(cmake_command_invoke_expand_function_name)
|
||||||
run_cmake(cmake_command_invoke_message)
|
run_cmake(cmake_command_invoke_message)
|
||||||
run_cmake(cmake_command_invoke_message_fatal_error)
|
run_cmake(cmake_command_invoke_message_fatal_error)
|
||||||
run_cmake(cmake_command_invoke_no_parameters)
|
run_cmake(cmake_command_invoke_no_parameters)
|
||||||
run_cmake(cmake_command_invoke_preserve_arguments)
|
run_cmake(cmake_command_invoke_preserve_arguments)
|
||||||
run_cmake(cmake_command_invoke_unknown_function)
|
run_cmake(cmake_command_invoke_unknown_function)
|
||||||
|
run_cmake(cmake_command_eval_expand_command_name)
|
||||||
|
run_cmake(cmake_command_eval_expanded_command_and_arguments)
|
||||||
|
run_cmake(cmake_command_eval_extra_parameters_between_eval_and_code)
|
||||||
run_cmake(cmake_command_eval_message)
|
run_cmake(cmake_command_eval_message)
|
||||||
run_cmake(cmake_command_eval_message_fatal_error)
|
run_cmake(cmake_command_eval_message_fatal_error)
|
||||||
run_cmake(cmake_command_eval_no_code)
|
run_cmake(cmake_command_eval_no_code)
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
OK!
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
set (my_eval "EVAL")
|
||||||
|
cmake_command (${my_eval} CODE message("OK!"))
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK!
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
set(cmd EVAL CODE [[message("OK!")]])
|
||||||
|
cmake_command(${cmd})
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
CMake Error at cmake_command_eval_extra_parameters_between_eval_and_code.cmake:1 \(cmake_command\):
|
||||||
|
cmake_command called with unsupported arguments between EVAL and CODE
|
||||||
|
arguments
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
cmake_command(EVAL BAD CODE "message(BAD CODE)")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
var='\${foo}'
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
set(var [[${foo}]])
|
||||||
|
cmake_command(INVOKE cmake_command INVOKE message "var='${var}'")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
OK!
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
set (my_invoke "INVOKE")
|
||||||
|
cmake_command (${my_invoke} message "OK!")
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
function(some_function_1)
|
||||||
|
message(1)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(some_function_2)
|
||||||
|
message(2)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
set(function_version 1)
|
||||||
|
|
||||||
|
cmake_command(INVOKE some_function_${function_version})
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
OK!
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
function (itsok)
|
||||||
|
message(OK!)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
set (cmd INVOKE itsok)
|
||||||
|
cmake_command (${cmd})
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
1
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
CMake Error at cmake_command_invoke_expanded_command_and_arguments.cmake:2 \(cmake_command\):
|
||||||
|
cmake_command called with incorrect number of arguments
|
||||||
|
Call Stack \(most recent call first\):
|
||||||
|
CMakeLists.txt:3 \(include\)
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
set(invoke_message INVOKE message a b)
|
||||||
|
cmake_command(${invoke_message})
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
OK!
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
set (cmd INVOKE message)
|
||||||
|
cmake_command (${cmd} "OK!")
|
||||||
Reference in New Issue
Block a user