cmRuleMaker.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #ifndef cmRuleMaker_h
  12. #define cmRuleMaker_h
  13. #include "cmStandardIncludes.h"
  14. #include "cmMakefile.h"
  15. /** \class cmRuleMaker
  16. * \brief Superclass for all rules in CMake.
  17. *
  18. * cmRuleMaker is the base class for all rules in CMake.
  19. * cmRuleMaker defines the API for rules with such features
  20. * as enable/disable, inheritance, documentation, and construction.
  21. */
  22. class cmRuleMaker
  23. {
  24. public:
  25. /**
  26. * Construct the rule enabled with no makefile.
  27. * the input file.
  28. */
  29. cmRuleMaker()
  30. {m_Makefile = 0; m_Enabled = true;}
  31. /**
  32. * Specify the makefile.
  33. */
  34. void SetMakefile(cmMakefile*m)
  35. {m_Makefile = m; }
  36. /**
  37. * This is called when the rule is first encountered in
  38. * the CMakeLists.txt file.
  39. */
  40. virtual bool Invoke(std::vector<std::string>& args) = 0;
  41. /**
  42. * This is called at the end after all the information
  43. * specified by the rules is accumulated.
  44. */
  45. virtual void FinalPass() = 0;
  46. /**
  47. * This is called to let the rule check the cache.
  48. */
  49. virtual void LoadCache() {}
  50. /**
  51. * This is a virtual constructor for the rule.
  52. */
  53. virtual cmRuleMaker* Clone() = 0;
  54. /**
  55. * This determines if the rule gets propagated down
  56. * to makefiles located in subdirectories.
  57. */
  58. virtual bool IsInherited()
  59. {
  60. return false;
  61. }
  62. /**
  63. * The name of the rule as specified in CMakeList.txt.
  64. */
  65. virtual const char* GetName() = 0;
  66. /**
  67. * Succinct documentation.
  68. */
  69. virtual const char* TerseDocumentation() = 0;
  70. /**
  71. * More documentation.
  72. */
  73. virtual const char* FullDocumentation() = 0;
  74. /**
  75. * Enable the rule.
  76. */
  77. void EnabledOn()
  78. {m_Enabled = true;}
  79. /**
  80. * Disable the rule.
  81. */
  82. void EnabledOff()
  83. {m_Enabled = false;}
  84. /**
  85. * Query whether the rule is enabled.
  86. */
  87. bool GetEnabled()
  88. {return m_Enabled;}
  89. /**
  90. * Return the last error string.
  91. */
  92. const char* GetError()
  93. {return m_Error.c_str();}
  94. protected:
  95. void SetError(const char* e)
  96. {
  97. m_Error = this->GetName();
  98. m_Error += " ";
  99. m_Error += e;
  100. }
  101. cmMakefile* m_Makefile;
  102. private:
  103. bool m_Enabled;
  104. std::string m_Error;
  105. };
  106. #endif