cmPolicies.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 cmPolicies_h
  11. #define cmPolicies_h
  12. #include "cmCustomCommand.h"
  13. class cmake;
  14. class cmMakefile;
  15. class cmPolicy;
  16. /** \class cmPolicies
  17. * \brief Handles changes in CMake behavior and policies
  18. *
  19. * See the cmake wiki section on
  20. * <a href="http://www.cmake.org/Wiki/CMake/Policies">policies</a>
  21. * for an overview of this class's purpose
  22. */
  23. class cmPolicies
  24. {
  25. public:
  26. cmPolicies();
  27. ~cmPolicies();
  28. /// Status of a policy
  29. enum PolicyStatus {
  30. OLD, ///< Use old behavior
  31. WARN, ///< Use old behavior but issue a warning
  32. NEW, ///< Use new behavior
  33. /// Issue an error if user doesn't set policy status to NEW and hits the
  34. /// check
  35. REQUIRED_IF_USED,
  36. REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
  37. };
  38. static const char* PolicyStatusNames[];
  39. /// Policy identifiers
  40. enum PolicyID
  41. {
  42. CMP0000, ///< Policy version specification
  43. CMP0001, ///< Ignore old compatibility variable
  44. CMP0002, ///< Target names must be unique
  45. CMP0003, ///< Linking does not include extra -L paths
  46. CMP0004, ///< Libraries linked may not have leading or trailing whitespace
  47. CMP0005, ///< Definition value escaping
  48. CMP0006, ///< BUNDLE install rules needed for MACOSX_BUNDLE targets
  49. CMP0007, ///< list command handling of empty elements
  50. CMP0008, ///< Full-path libraries must be a valid library file name
  51. CMP0009, ///< GLOB_RECURSE should not follow symlinks by default
  52. CMP0010, ///< Bad variable reference syntax is an error
  53. CMP0011, ///< Strong policy scope for include and find_package
  54. CMP0012, ///< Recognize numbers and boolean constants in if()
  55. CMP0013, ///< Duplicate binary directories not allowed
  56. CMP0014, ///< Input directories must have CMakeLists.txt
  57. CMP0015, ///< link_directories() treats paths relative to source dir
  58. /// target_link_libraries() fails if only argument is not a target
  59. CMP0016,
  60. CMP0017, ///< Prefer files in CMAKE_ROOT when including from CMAKE_ROOT
  61. CMP0018, ///< Ignore language flags for shared libs, and adhere to
  62. /// POSITION_INDEPENDENT_CODE property and *_COMPILE_OPTIONS_PI{E,C}
  63. /// instead.
  64. CMP0019, ///< No variable re-expansion in include and link info
  65. CMP0020, ///< Automatically link Qt executables to qtmain target
  66. CMP0021, ///< Fatal error on relative paths in INCLUDE_DIRECTORIES
  67. /// target property
  68. CMP0022, ///< INTERFACE_LINK_LIBRARIES defines the link interface
  69. CMP0023, ///< Disallow mixing keyword and plain tll signatures
  70. CMP0024, ///< Disallow including export() result.
  71. CMP0025, ///< Compiler id for Apple Clang is now AppleClang
  72. CMP0026, ///< Disallow use of the LOCATION target property.
  73. CMP0027, ///< Conditionally linked imported targets with missing include
  74. /// directories.
  75. CMP0028, ///< Double colon in target name means ALIAS or IMPORTED target.
  76. CMP0029, ///< Disallow command: subdir_depends
  77. CMP0030, ///< Disallow command: use_mangled_mesa
  78. CMP0031, ///< Disallow command: load_command
  79. CMP0032, ///< Disallow command: output_required_files
  80. CMP0033, ///< Disallow command: export_library_dependencies
  81. CMP0034, ///< Disallow command: utility_source
  82. CMP0035, ///< Disallow command: variable_requires
  83. CMP0036, ///< Disallow command: build_name
  84. CMP0037, ///< Target names should not be reserved and
  85. /// should match a validity pattern.
  86. CMP0038, ///< Targets may not link directly to themselves
  87. CMP0039, ///< Utility targets may not have link dependencies
  88. CMP0040, ///< The target in the TARGET signature of
  89. /// add_custom_command() must exist.
  90. CMP0041, ///< Error on relative include with generator expression
  91. CMP0042, ///< Enable MACOSX_RPATH by default
  92. /** \brief Always the last entry.
  93. *
  94. * Useful mostly to avoid adding a comma the last policy when adding a new
  95. * one.
  96. */
  97. CMPCOUNT
  98. };
  99. ///! convert a string policy ID into a number
  100. bool GetPolicyID(const char *id, /* out */ cmPolicies::PolicyID &pid);
  101. std::string GetPolicyIDString(cmPolicies::PolicyID pid);
  102. ///! Get the default status for a policy
  103. cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
  104. ///! Define a Policy for CMake
  105. void DefinePolicy(cmPolicies::PolicyID id,
  106. const char *stringID,
  107. const char *shortDescription,
  108. unsigned int majorVersionIntroduced,
  109. unsigned int minorVersionIntroduced,
  110. unsigned int patchVersionIntroduced,
  111. unsigned int tweakVersionIntroduced,
  112. cmPolicies::PolicyStatus status);
  113. ///! Set a policy level for this listfile
  114. bool ApplyPolicyVersion(cmMakefile *mf, const char *version);
  115. ///! return a warning string for a given policy
  116. std::string GetPolicyWarning(cmPolicies::PolicyID id);
  117. ///! return an error string for when a required policy is unspecified
  118. std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
  119. ///! return an error string for when a required policy is unspecified
  120. std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
  121. /** Represent a set of policy values. */
  122. typedef std::map<PolicyID, PolicyStatus> PolicyMap;
  123. private:
  124. // might have to make these internal for VS6 not sure yet
  125. std::map<PolicyID,cmPolicy *> Policies;
  126. std::map<std::string,PolicyID> PolicyStringMap;
  127. void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
  128. unsigned int majorVer, unsigned int minorVer,
  129. unsigned int patchVer, cmMakefile* mf);
  130. bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
  131. cmPolicies::PolicyStatus* defaultStatus);
  132. };
  133. #endif