Imported Upstream version 2.8.11.2
[platform/upstream/cmake.git] / Source / cmPolicies.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #ifndef cmPolicies_h
13 #define cmPolicies_h
14
15 #include "cmCustomCommand.h"
16
17 class cmake;
18 class cmMakefile;
19 class cmPolicy;
20
21 /** \class cmPolicies
22  * \brief Handles changes in CMake behavior and policies
23  *
24  * See the cmake wiki section on
25  * <a href="http://www.cmake.org/Wiki/CMake/Policies">policies</a>
26  * for an overview of this class's purpose
27  */
28 class cmPolicies
29 {
30 public:
31   cmPolicies();
32   ~cmPolicies();
33
34   /// Status of a policy
35   enum PolicyStatus {
36     OLD, ///< Use old behavior
37     WARN, ///< Use old behavior but issue a warning
38     NEW, ///< Use new behavior
39     /// Issue an error if user doesn't set policy status to NEW and hits the
40     /// check
41     REQUIRED_IF_USED,
42     REQUIRED_ALWAYS ///< Issue an error unless user sets policy status to NEW.
43   };
44   static const char* PolicyStatusNames[];
45
46   /// Policy identifiers
47   enum PolicyID
48   {
49     CMP0000, ///< Policy version specification
50     CMP0001, ///< Ignore old compatibility variable
51     CMP0002, ///< Target names must be unique
52     CMP0003, ///< Linking does not include extra -L paths
53     CMP0004, ///< Libraries linked may not have leading or trailing whitespace
54     CMP0005, ///< Definition value escaping
55     CMP0006, ///< BUNDLE install rules needed for MACOSX_BUNDLE targets
56     CMP0007, ///< list command handling of empty elements
57     CMP0008, ///< Full-path libraries must be a valid library file name
58     CMP0009, ///< GLOB_RECURSE should not follow symlinks by default
59     CMP0010, ///< Bad variable reference syntax is an error
60     CMP0011, ///< Strong policy scope for include and find_package
61     CMP0012, ///< Recognize numbers and boolean constants in if()
62     CMP0013, ///< Duplicate binary directories not allowed
63     CMP0014, ///< Input directories must have CMakeLists.txt
64     CMP0015, ///< link_directories() treats paths relative to source dir
65     /// target_link_libraries() fails if only argument is not a target
66     CMP0016,
67     CMP0017, ///< Prefer files in CMAKE_ROOT when including from CMAKE_ROOT
68     CMP0018, ///< Ignore language flags for shared libs, and adhere to
69     /// POSITION_INDEPENDENT_CODE property and *_COMPILE_OPTIONS_PI{E,C}
70     /// instead.
71     CMP0019, ///< No variable re-expansion in include and link info
72     CMP0020, ///< Automatically link Qt executables to qtmain target
73
74     /** \brief Always the last entry.
75      *
76      * Useful mostly to avoid adding a comma the last policy when adding a new
77      * one.
78      */
79     CMPCOUNT
80   };
81
82   ///! convert a string policy ID into a number
83   bool GetPolicyID(const char *id, /* out */ cmPolicies::PolicyID &pid);
84   std::string GetPolicyIDString(cmPolicies::PolicyID pid);
85
86   ///! Get the default status for a policy
87   cmPolicies::PolicyStatus GetPolicyStatus(cmPolicies::PolicyID id);
88
89   ///! Define a Policy for CMake
90   void DefinePolicy(cmPolicies::PolicyID id,
91                     const char *stringID,
92                     const char *shortDescription,
93                     const char *longDescription,
94                     unsigned int majorVersionIntroduced,
95                     unsigned int minorVersionIntroduced,
96                     unsigned int patchVersionIntroduced,
97                     unsigned int tweakVersionIntroduced,
98                     cmPolicies::PolicyStatus status);
99
100   ///! Set a policy level for this listfile
101   bool ApplyPolicyVersion(cmMakefile *mf, const char *version);
102
103   ///! return a warning string for a given policy
104   std::string GetPolicyWarning(cmPolicies::PolicyID id);
105
106   ///! return an error string for when a required policy is unspecified
107   std::string GetRequiredPolicyError(cmPolicies::PolicyID id);
108
109   ///! return an error string for when a required policy is unspecified
110   std::string GetRequiredAlwaysPolicyError(cmPolicies::PolicyID id);
111
112   ///! Get docs for policies
113   void GetDocumentation(std::vector<cmDocumentationEntry>& v);
114
115   /** Represent a set of policy values.  */
116   typedef std::map<PolicyID, PolicyStatus> PolicyMap;
117
118   private:
119   // might have to make these internal for VS6 not sure yet
120   std::map<PolicyID,cmPolicy *> Policies;
121   std::map<std::string,PolicyID> PolicyStringMap;
122
123   void DiagnoseAncientPolicies(std::vector<PolicyID> const& ancient,
124                                unsigned int majorVer, unsigned int minorVer,
125                                unsigned int patchVer, cmMakefile* mf);
126
127   bool GetPolicyDefault(cmMakefile* mf, std::string const& policy,
128                         cmPolicies::PolicyStatus* defaultStatus);
129
130 };
131
132 #endif