cmCMakePolicyCommand.h 5.2 KB

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