MCPcopy Create free account
hub / github.com/Kitware/CMake / operator()

Method operator()

Source/cmFunctionCommand.cxx:54–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52};
53
54bool cmFunctionHelperCommand::operator()(
55 std::vector<cmListFileArgument> const& args,
56 cmExecutionStatus& inStatus) const
57{
58 cmMakefile& makefile = inStatus.GetMakefile();
59
60 // Expand the argument list to the function.
61 std::vector<std::string> expandedArgs;
62 makefile.ExpandArguments(args, expandedArgs);
63
64 // make sure the number of arguments passed is at least the number
65 // required by the signature
66 if (expandedArgs.size() < this->Args.size() - 1) {
67 auto const errorMsg = cmStrCat(
68 "Function invoked with incorrect arguments for function named: ",
69 this->Args.front());
70 inStatus.SetError(errorMsg);
71 return false;
72 }
73
74 cmMakefile::FunctionPushPop functionScope(&makefile, this->FilePath,
75 this->Policies);
76
77 // set the value of argc
78 makefile.AddDefinition(ARGC, std::to_string(expandedArgs.size()));
79 makefile.MarkVariableAsUsed(ARGC);
80
81 // set the values for ARGV0 ARGV1 ...
82 for (auto t = 0u; t < expandedArgs.size(); ++t) {
83 auto const value = cmStrCat(ARGV, t);
84 makefile.AddDefinition(value, expandedArgs[t]);
85 makefile.MarkVariableAsUsed(value);
86 }
87
88 // define the formal arguments
89 for (auto j = 1u; j < this->Args.size(); ++j) {
90 makefile.AddDefinition(this->Args[j], expandedArgs[j - 1]);
91 }
92
93 // define ARGV and ARGN
94 auto const argvDef = cmList::to_string(expandedArgs);
95 auto const expIt = expandedArgs.begin() + (this->Args.size() - 1);
96 auto const argnDef =
97 cmList::to_string(cmMakeRange(expIt, expandedArgs.end()));
98 makefile.AddDefinition(ARGV, argvDef);
99 makefile.MarkVariableAsUsed(ARGV);
100 makefile.AddDefinition(ARGN, argnDef);
101 makefile.MarkVariableAsUsed(ARGN);
102
103 makefile.AddDefinition(CMAKE_CURRENT_FUNCTION, this->Args.front());
104 makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION);
105 makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_FILE, this->FilePath);
106 makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_FILE);
107 makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_DIR,
108 cmSystemTools::GetFilenamePath(this->FilePath));
109 makefile.MarkVariableAsUsed(CMAKE_CURRENT_FUNCTION_LIST_DIR);
110 makefile.AddDefinition(CMAKE_CURRENT_FUNCTION_LIST_LINE,
111 std::to_string(this->Line));

Callers

nothing calls this directly

Calls 15

to_stringFunction · 0.85
cmMakeRangeFunction · 0.85
ExpandArgumentsMethod · 0.80
MarkVariableAsUsedMethod · 0.80
ExecuteCommandMethod · 0.80
GetNestedErrorMethod · 0.80
SetNestedErrorMethod · 0.80
GetReturnInvokedMethod · 0.80
HasExitCodeMethod · 0.80
SetExitCodeMethod · 0.80
GetExitCodeMethod · 0.80
cmStrCatFunction · 0.70

Tested by

no test coverage detected