| 52 | }; |
| 53 | |
| 54 | bool 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)); |
nothing calls this directly
no test coverage detected