cmFunctionCommand.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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
  15. * \brief subclass of function blocker
  16. *
  17. *
  18. */
  19. class cmFunctionFunctionBlocker : public cmFunctionBlocker
  20. {
  21. public:
  22. cmFunctionFunctionBlocker() {this->Depth=0;}
  23. virtual ~cmFunctionFunctionBlocker() {}
  24. virtual bool IsFunctionBlocked(const cmListFileFunction&,
  25. cmMakefile &mf,
  26. cmExecutionStatus &);
  27. virtual bool ShouldRemove(const cmListFileFunction&, cmMakefile &mf);
  28. std::vector<std::string> Args;
  29. std::vector<cmListFileFunction> Functions;
  30. int Depth;
  31. };
  32. /** \class cmFunctionCommand
  33. * \brief starts an if block
  34. *
  35. * cmFunctionCommand starts an if block
  36. */
  37. class cmFunctionCommand : public cmCommand
  38. {
  39. public:
  40. /**
  41. * This is a virtual constructor for the command.
  42. */
  43. virtual cmCommand* Clone()
  44. {
  45. return new cmFunctionCommand;
  46. }
  47. /**
  48. * This is called when the command is first encountered in
  49. * the CMakeLists.txt file.
  50. */
  51. virtual bool InitialPass(std::vector<std::string> const& args,
  52. cmExecutionStatus &status);
  53. /**
  54. * This determines if the command is invoked when in script mode.
  55. */
  56. virtual bool IsScriptable() { return true; }
  57. /**
  58. * The name of the command as specified in CMakeList.txt.
  59. */
  60. virtual const char* GetName() { return "function";}
  61. /**
  62. * Succinct documentation.
  63. */
  64. virtual const char* GetTerseDocumentation()
  65. {
  66. return "Start recording a function for later invocation as a command.";
  67. }
  68. /**
  69. * More documentation.
  70. */
  71. virtual const char* GetFullDocumentation()
  72. {
  73. return
  74. " function(<name> [arg1 [arg2 [arg3 ...]]])\n"
  75. " COMMAND1(ARGS ...)\n"
  76. " COMMAND2(ARGS ...)\n"
  77. " ...\n"
  78. " endfunction(<name>)\n"
  79. "Define a function named <name> that takes arguments named "
  80. "arg1 arg2 arg3 (...). Commands listed after function, but before "
  81. "the matching endfunction, are not invoked until the function "
  82. "is invoked. When it is invoked, the commands recorded in the "
  83. "function are first modified by replacing formal parameters (${arg1}) "
  84. "with the arguments passed, and then invoked as normal commands. In "
  85. "addition to referencing the formal parameters you can reference "
  86. "the variable ARGC which will be set to the number of arguments "
  87. "passed into the function as well as ARGV0 ARGV1 ARGV2 ... which "
  88. "will have the actual values of the arguments passed in. This "
  89. "facilitates creating functions with optional arguments. Additionally "
  90. "ARGV holds the list of all arguments given to the function and ARGN "
  91. "holds the list of argument past the last expected argument."
  92. "\n"
  93. "See the cmake_policy() command documentation for the behavior of "
  94. "policies inside functions."
  95. ;
  96. }
  97. cmTypeMacro(cmFunctionCommand, cmCommand);
  98. };
  99. #endif