Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmSetCommand.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 cmSetCommand_h
13 #define cmSetCommand_h
14
15 #include "cmCommand.h"
16
17 /** \class cmSetCommand
18  * \brief Set a CMAKE variable
19  *
20  * cmSetCommand sets a variable to a value with expansion.  
21  */
22 class cmSetCommand : public cmCommand
23 {
24 public:
25   /**
26    * This is a virtual constructor for the command.
27    */
28   virtual cmCommand* Clone() 
29     {
30     return new cmSetCommand;
31     }
32
33   /**
34    * This is called when the command is first encountered in
35    * the CMakeLists.txt file.
36    */
37   virtual bool InitialPass(std::vector<std::string> const& args,
38                            cmExecutionStatus &status);
39
40   /**
41    * This determines if the command is invoked when in script mode.
42    */
43   virtual bool IsScriptable() const { return true; }
44
45   /**
46    * The name of the command as specified in CMakeList.txt.
47    */
48   virtual const char* GetName() const {return "set";}
49   
50   /**
51    * Succinct documentation.
52    */
53   virtual const char* GetTerseDocumentation() const
54     {
55     return "Set a CMake, cache or environment variable to a given value.";
56     }
57   
58   /**
59    * More documentation.
60    */
61   virtual const char* GetFullDocumentation() const
62     {
63     return
64       "  set(<variable> <value>\n"
65       "      [[CACHE <type> <docstring> [FORCE]] | PARENT_SCOPE])\n"
66       "Within CMake sets <variable> to the value <value>.  "
67       "<value> is expanded before <variable> is set to it.  "
68       "Normally, set will set a regular CMake variable. "
69       "If CACHE is present, then the <variable> is put in the cache "
70       "instead, unless it is already in the cache. "
71       "See section 'Variable types in CMake' below for details of "
72       "regular and cache variables and their interactions. "
73       "If CACHE is used, <type> and <docstring> are required. <type> is used "
74       "by the CMake GUI to choose a widget with which the user sets a value. "
75       "The value for <type> may be one of\n"
76       "  FILEPATH = File chooser dialog.\n"
77       "  PATH     = Directory chooser dialog.\n"
78       "  STRING   = Arbitrary string.\n"
79       "  BOOL     = Boolean ON/OFF checkbox.\n"
80       "  INTERNAL = No GUI entry (used for persistent variables).\n"
81       "If <type> is INTERNAL, the cache variable is marked as internal, "
82       "and will not be shown to the user in tools like cmake-gui. "
83       "This is intended for values that should be persisted in the cache, "
84       "but which users should not normally change. INTERNAL implies FORCE."
85       "\n"
86       "Normally, set(...CACHE...) creates cache variables, but does not "
87       "modify them. "
88       "If FORCE is specified, the value of the cache variable is set, even "
89       "if the variable is already in the cache. This should normally be "
90       "avoided, as it will remove any changes to the cache variable's value "
91       "by the user.\n"
92       "If PARENT_SCOPE is present, the variable will be set in the scope "
93       "above the current scope. Each new directory or function creates a new "
94       "scope. This command will set the value of a variable into the parent "
95       "directory or calling function (whichever is applicable to the case at "
96       "hand). PARENT_SCOPE cannot be combined with CACHE.\n"
97       "If <value> is not specified then the variable is removed "
98       "instead of set.  See also: the unset() command.\n"
99       "  set(<variable> <value1> ... <valueN>)\n"
100       "In this case <variable> is set to a semicolon separated list of "
101       "values.\n"
102       "<variable> can be an environment variable such as:\n"
103       "  set( ENV{PATH} /home/martink )\n"
104       "in which case the environment variable will be set.\n"
105       "*** Variable types in CMake ***\n"
106       "In CMake there are two types of variables: normal variables and cache "
107       "variables. Normal variables are meant for the internal use of the "
108       "script (just like variables in most programming languages); they are "
109       "not persisted across CMake runs. "
110       "Cache variables (unless set with INTERNAL) are mostly intended for "
111       "configuration settings where the first CMake run determines a "
112       "suitable default value, which the user can then override, by editing "
113       "the cache with tools such as ccmake or cmake-gui. "
114       "Cache variables are stored in the CMake cache file, and "
115       "are persisted across CMake runs. \n"
116       "Both types can exist at the same time with the same name "
117       "but different values. "
118       "When ${FOO} is evaluated, CMake first looks for "
119       "a normal variable 'FOO' in scope and uses it if set. "
120       "If and only if no normal variable exists then it falls back to the "
121       "cache variable 'FOO'.\n"
122       "Some examples:\n"
123       "The code 'set(FOO \"x\")' sets the normal variable 'FOO'. It does not "
124       "touch the cache, but it will hide any existing cache value 'FOO'.\n"
125       "The code 'set(FOO \"x\" CACHE ...)' checks for 'FOO' in the cache, "
126       "ignoring any normal variable of the same name. If 'FOO' is in the "
127       "cache then nothing happens to either the normal variable or the cache "
128       "variable. If 'FOO' is not in the cache, then it is added to the "
129       "cache.\n"
130       "Finally, whenever a cache variable is added or modified by a command, "
131       "CMake also *removes* the normal variable of the same name from the "
132       "current scope so that an immediately following evaluation of "
133       "it will expose the newly cached value.\n"
134       "Normally projects should avoid using normal and cache variables of "
135       "the same name, as this interaction can be hard to follow. "
136       "However, in some situations it can be useful. "
137       "One example (used by some projects):"
138       "\n"
139       "A project has a subproject in its source tree. The child project has "
140       "its own CMakeLists.txt, which is included from the parent "
141       "CMakeLists.txt using add_subdirectory(). "
142       "Now, if the parent and the child project provide the same option "
143       "(for example a compiler option), the parent gets the first chance "
144       "to add a user-editable option to the cache. "
145       "Normally, the child would then use the same value "
146       "that the parent uses. "
147       "However, it may be necessary to hard-code the value for the child "
148       "project's option while still allowing the user to edit the value used "
149       "by the parent project. The parent project can achieve this simply by "
150       "setting a normal variable with the same name as the option in a scope "
151       "sufficient to hide the option's cache variable from the child "
152       "completely. The parent has already set the cache variable,  so the "
153       "child's set(...CACHE...) will do nothing, and evaluating the option "
154       "variable will use the value from the normal variable, which hides the "
155       "cache variable.";
156     }
157   
158   cmTypeMacro(cmSetCommand, cmCommand);
159 };
160
161
162
163 #endif