cmFunctionCommand.h 3.5 KB

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