cmFunctionCommand.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmFunctionCommand_h
  11. #define cmFunctionCommand_h
  12. #include "cmCommand.h"
  13. #include "cmFunctionBlocker.h"
  14. class cmFunctionFunctionBlocker : public cmFunctionBlocker
  15. {
  16. public:
  17. cmFunctionFunctionBlocker() {this->Depth=0;}
  18. virtual ~cmFunctionFunctionBlocker() {}
  19. virtual bool IsFunctionBlocked(const cmListFileFunction&,
  20. cmMakefile &mf,
  21. cmExecutionStatus &);
  22. virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
  23. std::vector<std::string> Args;
  24. std::vector<cmListFileFunction> Functions;
  25. int Depth;
  26. };
  27. /// Starts function() ... endfunction() block
  28. class cmFunctionCommand : public cmCommand
  29. {
  30. public:
  31. /**
  32. * This is a virtual constructor for the command.
  33. */
  34. virtual cmCommand* Clone()
  35. {
  36. return new cmFunctionCommand;
  37. }
  38. /**
  39. * This is called when the command is first encountered in
  40. * the CMakeLists.txt file.
  41. */
  42. virtual bool InitialPass(std::vector<std::string> const& args,
  43. cmExecutionStatus &status);
  44. /**
  45. * This determines if the command is invoked when in script mode.
  46. */
  47. virtual bool IsScriptable() const { return true; }
  48. /**
  49. * The name of the command as specified in CMakeList.txt.
  50. */
  51. virtual const char* GetName() const { return "function";}
  52. /**
  53. * Succinct documentation.
  54. */
  55. virtual const char* GetTerseDocumentation() const
  56. {
  57. return "Start recording a function for later invocation as a command.";
  58. }
  59. /**
  60. * More documentation.
  61. */
  62. virtual const char* GetFullDocumentation() const
  63. {
  64. return
  65. " function(<name> [arg1 [arg2 [arg3 ...]]])\n"
  66. " COMMAND1(ARGS ...)\n"
  67. " COMMAND2(ARGS ...)\n"
  68. " ...\n"
  69. " endfunction(<name>)\n"
  70. "Define a function named <name> that takes arguments named "
  71. "arg1 arg2 arg3 (...). Commands listed after function, but before "
  72. "the matching endfunction, are not invoked until the function "
  73. "is invoked. When it is invoked, the commands recorded in the "
  74. "function are first modified by replacing formal parameters (${arg1}) "
  75. "with the arguments passed, and then invoked as normal commands. In "
  76. "addition to referencing the formal parameters you can reference "
  77. "the variable ARGC which will be set to the number of arguments "
  78. "passed into the function as well as ARGV0 ARGV1 ARGV2 ... which "
  79. "will have the actual values of the arguments passed in. This "
  80. "facilitates creating functions with optional arguments. Additionally "
  81. "ARGV holds the list of all arguments given to the function and ARGN "
  82. "holds the list of arguments past the last expected argument."
  83. "\n"
  84. "A function opens a new scope: see set(var PARENT_SCOPE) for details."
  85. "\n"
  86. "See the cmake_policy() command documentation for the behavior of "
  87. "policies inside functions."
  88. ;
  89. }
  90. cmTypeMacro(cmFunctionCommand, cmCommand);
  91. };
  92. #endif