cmCMakePolicyCommand.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 cmCMakePolicyCommand_h
  11. #define cmCMakePolicyCommand_h
  12. #include "cmCommand.h"
  13. /** \class cmCMakePolicyCommand
  14. * \brief Set how CMake should handle policies
  15. *
  16. * cmCMakePolicyCommand sets how CMake should deal with backwards
  17. * compatibility policies.
  18. */
  19. class cmCMakePolicyCommand : public cmCommand
  20. {
  21. public:
  22. /**
  23. * This is a virtual constructor for the command.
  24. */
  25. virtual cmCommand* Clone()
  26. {
  27. return new cmCMakePolicyCommand;
  28. }
  29. /**
  30. * This is called when the command is first encountered in
  31. * the CMakeLists.txt file.
  32. */
  33. virtual bool InitialPass(std::vector<std::string> const& args,
  34. cmExecutionStatus &status);
  35. /**
  36. * This determines if the command is invoked when in script mode.
  37. */
  38. virtual bool IsScriptable() { return true; }
  39. /**
  40. * The name of the command as specified in CMakeList.txt.
  41. */
  42. virtual const char* GetName() {return "cmake_policy";}
  43. /**
  44. * Succinct documentation.
  45. */
  46. virtual const char* GetTerseDocumentation()
  47. {
  48. return "Manage CMake Policy settings.";
  49. }
  50. /**
  51. * More documentation.
  52. */
  53. virtual const char* GetFullDocumentation()
  54. {
  55. return
  56. "As CMake evolves it is sometimes necessary to change existing "
  57. "behavior in order to fix bugs or improve implementations of "
  58. "existing features. "
  59. "The CMake Policy mechanism is designed to help keep existing projects "
  60. "building as new versions of CMake introduce changes in behavior. "
  61. "Each new policy (behavioral change) is given an identifier of "
  62. "the form \"CMP<NNNN>\" where \"<NNNN>\" is an integer index. "
  63. "Documentation associated with each policy describes the OLD and NEW "
  64. "behavior and the reason the policy was introduced. "
  65. "Projects may set each policy to select the desired behavior. "
  66. "When CMake needs to know which behavior to use it checks for "
  67. "a setting specified by the project. "
  68. "If no setting is available the OLD behavior is assumed and a warning "
  69. "is produced requesting that the policy be set.\n"
  70. "The cmake_policy command is used to set policies to OLD or NEW "
  71. "behavior. "
  72. "While setting policies individually is supported, we encourage "
  73. "projects to set policies based on CMake versions.\n"
  74. " cmake_policy(VERSION major.minor[.patch[.tweak]])\n"
  75. "Specify that the current CMake list file is written for the "
  76. "given version of CMake. "
  77. "All policies introduced in the specified version or earlier "
  78. "will be set to use NEW behavior. "
  79. "All policies introduced after the specified version will be unset "
  80. "(unless variable CMAKE_POLICY_DEFAULT_CMP<NNNN> sets a default). "
  81. "This effectively requests behavior preferred as of a given CMake "
  82. "version and tells newer CMake versions to warn about their new "
  83. "policies. "
  84. "The policy version specified must be at least 2.4 or the command "
  85. "will report an error. "
  86. "In order to get compatibility features supporting versions earlier "
  87. "than 2.4 see documentation of policy CMP0001."
  88. "\n"
  89. " cmake_policy(SET CMP<NNNN> NEW)\n"
  90. " cmake_policy(SET CMP<NNNN> OLD)\n"
  91. "Tell CMake to use the OLD or NEW behavior for a given policy. "
  92. "Projects depending on the old behavior of a given policy may "
  93. "silence a policy warning by setting the policy state to OLD. "
  94. "Alternatively one may fix the project to work with the new behavior "
  95. "and set the policy state to NEW."
  96. "\n"
  97. " cmake_policy(GET CMP<NNNN> <variable>)\n"
  98. "Check whether a given policy is set to OLD or NEW behavior. "
  99. "The output variable value will be \"OLD\" or \"NEW\" if the "
  100. "policy is set, and empty otherwise."
  101. "\n"
  102. "CMake keeps policy settings on a stack, so changes made by the "
  103. "cmake_policy command affect only the top of the stack. "
  104. "A new entry on the policy stack is managed automatically for each "
  105. "subdirectory to protect its parents and siblings. "
  106. "CMake also manages a new entry for scripts loaded by include() and "
  107. "find_package() commands except when invoked with the NO_POLICY_SCOPE "
  108. "option (see also policy CMP0011). "
  109. "The cmake_policy command provides an interface to manage custom "
  110. "entries on the policy stack:\n"
  111. " cmake_policy(PUSH)\n"
  112. " cmake_policy(POP)\n"
  113. "Each PUSH must have a matching POP to erase any changes. "
  114. "This is useful to make temporary changes to policy settings."
  115. "\n"
  116. "Functions and macros record policy settings when they are created "
  117. "and use the pre-record policies when they are invoked. "
  118. "If the function or macro implementation sets policies, the changes "
  119. "automatically propagate up through callers until they reach the "
  120. "closest nested policy stack entry."
  121. ;
  122. }
  123. cmTypeMacro(cmCMakePolicyCommand, cmCommand);
  124. private:
  125. bool HandleSetMode(std::vector<std::string> const& args);
  126. bool HandleGetMode(std::vector<std::string> const& args);
  127. bool HandleVersionMode(std::vector<std::string> const& args);
  128. };
  129. #endif