cmCMakeCommand.cxx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCMakeCommand.h"
  4. #include <algorithm>
  5. #include <cstddef>
  6. #include "cmExecutionStatus.h"
  7. #include "cmListFileCache.h"
  8. #include "cmMakefile.h"
  9. #include "cmRange.h"
  10. #include "cmStringAlgorithms.h"
  11. bool cmCMakeCommand(std::vector<std::string> const& args,
  12. cmExecutionStatus& status)
  13. {
  14. if (args.empty()) {
  15. status.SetError("called with incorrect number of arguments");
  16. return false;
  17. }
  18. cmMakefile& makefile = status.GetMakefile();
  19. cmListFileContext context = makefile.GetExecutionContext();
  20. bool result = false;
  21. if (args[0] == "INVOKE") {
  22. if (args.size() == 1) {
  23. status.SetError("called with incorrect number of arguments");
  24. return false;
  25. }
  26. // First argument is the name of the function to call
  27. cmListFileFunction func;
  28. func.Name = args[1];
  29. func.Line = context.Line;
  30. // The rest of the arguments are passed to the function call above
  31. func.Arguments.resize(args.size() - 1);
  32. for (size_t i = 2; i < args.size(); ++i) {
  33. cmListFileArgument lfarg;
  34. lfarg.Line = context.Line;
  35. lfarg.Value = args[i];
  36. func.Arguments.emplace_back(lfarg);
  37. }
  38. result = makefile.ExecuteCommand(func, status);
  39. } else if (args[0] == "EVAL") {
  40. if (args.size() < 2) {
  41. status.SetError("called with incorrect number of arguments");
  42. return false;
  43. }
  44. auto code_iter = std::find(args.begin(), args.end(), "CODE");
  45. if (code_iter == args.end()) {
  46. status.SetError("called without CODE argument");
  47. return false;
  48. }
  49. const std::string code = cmJoin(cmMakeRange(++code_iter, args.end()), " ");
  50. result = makefile.ReadListFileAsString(
  51. code, cmStrCat(context.FilePath, ":", context.Line, ":EVAL"));
  52. } else {
  53. status.SetError("called with unknown meta-operation");
  54. }
  55. return result;
  56. }