1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallCommand.h,v $
6 Date: $Date: 2008/02/04 22:03:48 $
7 Version: $Revision: 1.29 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmInstallCommand_h
18 #define cmInstallCommand_h
20 #include "cmCommand.h"
22 /** \class cmInstallCommand
23 * \brief Specifies where to install some files
25 * cmInstallCommand is a general-purpose interface command for
26 * specifying install rules.
28 class cmInstallCommand
: public cmCommand
32 * This is a virtual constructor for the command.
34 virtual cmCommand
* Clone()
36 return new cmInstallCommand
;
40 * This is called when the command is first encountered in
41 * the CMakeLists.txt file.
43 virtual bool InitialPass(std::vector
<std::string
> const& args
,
44 cmExecutionStatus
&status
);
47 * The name of the command as specified in CMakeList.txt.
49 virtual const char* GetName() { return "install";}
52 * Succinct documentation.
54 virtual const char* GetTerseDocumentation()
56 return "Specify rules to run at install time.";
62 virtual const char* GetFullDocumentation()
65 "This command generates installation rules for a project. "
66 "Rules specified by calls to this command within a source directory "
67 "are executed in order during installation. "
68 "The order across directories is not defined."
70 "There are multiple signatures for this command. Some of them define "
71 "installation properties for files and targets. Properties common to "
72 "multiple signatures are covered here but they are valid only for "
73 "signatures that specify them.\n"
74 "DESTINATION arguments specify "
75 "the directory on disk to which a file will be installed. "
76 "If a full path (with a leading slash or drive letter) is given it "
77 "is used directly. If a relative path is given it is interpreted "
78 "relative to the value of CMAKE_INSTALL_PREFIX.\n"
79 "PERMISSIONS arguments specify permissions for installed files. "
80 "Valid permissions are "
81 "OWNER_READ, OWNER_WRITE, OWNER_EXECUTE, "
82 "GROUP_READ, GROUP_WRITE, GROUP_EXECUTE, "
83 "WORLD_READ, WORLD_WRITE, WORLD_EXECUTE, "
84 "SETUID, and SETGID. "
85 "Permissions that do not make sense on certain platforms are ignored "
86 "on those platforms.\n"
87 "The CONFIGURATIONS argument specifies a list of build configurations "
88 "for which the install rule applies (Debug, Release, etc.).\n"
89 "The COMPONENT argument specifies an installation component name "
90 "with which the install rule is associated, such as \"runtime\" or "
91 "\"development\". During component-specific installation only "
92 "install rules associated with the given component name will be "
93 "executed. During a full installation all components are installed.\n"
94 "The RENAME argument specifies a name for an installed file that "
95 "may be different from the original file. Renaming is allowed only "
96 "when a single file is installed by the command.\n"
97 "The OPTIONAL argument specifies that it is not an error if the "
98 "file to be installed does not exist. "
100 "The TARGETS signature:\n"
101 " install(TARGETS targets... [EXPORT <export-name>]\n"
102 " [[ARCHIVE|LIBRARY|RUNTIME|FRAMEWORK|BUNDLE|\n"
103 " PRIVATE_HEADER|PUBLIC_HEADER|RESOURCE]\n"
104 " [DESTINATION <dir>]\n"
105 " [PERMISSIONS permissions...]\n"
106 " [CONFIGURATIONS [Debug|Release|...]]\n"
107 " [COMPONENT <component>]\n"
108 " [OPTIONAL] [NAMELINK_ONLY|NAMELINK_SKIP]\n"
110 "The TARGETS form specifies rules for installing targets from a "
111 "project. There are five kinds of target files that may be "
112 "installed: archive, library, runtime, framework, and bundle. "
114 "Executables are treated as runtime targets, except that those "
115 "marked with the MACOSX_BUNDLE property are treated as bundle "
117 "Static libraries are always treated as archive targets. "
118 "Module libraries are always treated as library targets. "
119 "For non-DLL platforms shared libraries are treated as library "
120 "targets, except that those marked with the FRAMEWORK property "
121 "are treated as framework targets on OS X. "
122 "For DLL platforms the DLL part of a shared library is treated as "
123 "a runtime target and the corresponding import library is treated as "
124 "an archive target. "
125 "All Windows-based systems including Cygwin are DLL platforms. "
126 "The ARCHIVE, LIBRARY, RUNTIME, and FRAMEWORK "
127 "arguments change the type of target to which the subsequent "
129 "apply. If none is given the installation properties apply to "
130 "all target types. If only one is given then only targets of that "
131 "type will be installed (which can be used to install just a DLL or "
132 "just an import library)."
134 "The PRIVATE_HEADER, PUBLIC_HEADER, and RESOURCE arguments cause "
135 "subsequent properties to be applied to installing a FRAMEWORK "
136 "shared library target's associated files on non-Apple platforms. "
137 "Rules defined by these arguments are ignored on Apple platforms "
138 "because the associated files are installed into the appropriate "
139 "locations inside the framework folder. "
140 "See documentation of the PRIVATE_HEADER, PUBLIC_HEADER, and RESOURCE "
141 "target properties for details."
143 "Either NAMELINK_ONLY or NAMELINK_SKIP may be specified as a LIBRARY "
145 "On some platforms a versioned shared library has a symbolic link "
147 " lib<name>.so -> lib<name>.so.1\n"
148 "where \"lib<name>.so.1\" is the soname of the library and "
149 "\"lib<name>.so\" is a \"namelink\" allowing linkers to find the "
150 "library when given \"-l<name>\". "
151 "The NAMELINK_ONLY option causes installation of only the namelink "
152 "when a library target is installed. "
153 "The NAMELINK_SKIP option causes installation of library files other "
154 "than the namelink when a library target is installed. "
155 "When neither option is given both portions are installed. "
156 "On platforms where versioned shared libraries do not have namelinks "
157 "or when a library is not versioned the NAMELINK_SKIP option installs "
158 "the library and the NAMELINK_ONLY option installs nothing. "
159 "See the VERSION and SOVERSION target properties for details on "
160 "creating versioned shared libraries."
162 "One or more groups of properties may be specified in a single call "
163 "to the TARGETS form of this command. A target may be installed more "
164 "than once to different locations. Consider hypothetical "
165 "targets \"myExe\", \"mySharedLib\", and \"myStaticLib\". The code\n"
166 " install(TARGETS myExe mySharedLib myStaticLib\n"
167 " RUNTIME DESTINATION bin\n"
168 " LIBRARY DESTINATION lib\n"
169 " ARCHIVE DESTINATION lib/static)\n"
170 " install(TARGETS mySharedLib DESTINATION /some/full/path)\n"
171 "will install myExe to <prefix>/bin and myStaticLib to "
172 "<prefix>/lib/static. "
173 "On non-DLL platforms mySharedLib will be installed to <prefix>/lib "
174 "and /some/full/path. On DLL platforms the mySharedLib DLL will be "
175 "installed to <prefix>/bin and /some/full/path and its import library "
176 "will be installed to <prefix>/lib/static and /some/full/path. "
177 "On non-DLL platforms mySharedLib will be installed to <prefix>/lib "
178 "and /some/full/path."
180 "The EXPORT option associates the installed target files with an "
181 "export called <export-name>. "
182 "It must appear before any RUNTIME, LIBRARY, or ARCHIVE options. "
183 "See documentation of the install(EXPORT ...) signature below for "
186 "Installing a target with EXCLUDE_FROM_ALL set to true has "
187 "undefined behavior."
189 "The FILES signature:\n"
190 " install(FILES files... DESTINATION <dir>\n"
191 " [PERMISSIONS permissions...]\n"
192 " [CONFIGURATIONS [Debug|Release|...]]\n"
193 " [COMPONENT <component>]\n"
194 " [RENAME <name>] [OPTIONAL])\n"
195 "The FILES form specifies rules for installing files for a "
196 "project. File names given as relative paths are interpreted with "
197 "respect to the current source directory. Files installed by this "
198 "form are by default given permissions OWNER_WRITE, OWNER_READ, "
199 "GROUP_READ, and WORLD_READ if no PERMISSIONS argument is given."
201 "The PROGRAMS signature:\n"
202 " install(PROGRAMS files... DESTINATION <dir>\n"
203 " [PERMISSIONS permissions...]\n"
204 " [CONFIGURATIONS [Debug|Release|...]]\n"
205 " [COMPONENT <component>]\n"
206 " [RENAME <name>] [OPTIONAL])\n"
207 "The PROGRAMS form is identical to the FILES form except that the "
208 "default permissions for the installed file also include "
209 "OWNER_EXECUTE, GROUP_EXECUTE, and WORLD_EXECUTE. "
210 "This form is intended to install programs that are not targets, "
211 "such as shell scripts. Use the TARGETS form to install targets "
212 "built within the project."
214 "The DIRECTORY signature:\n"
215 " install(DIRECTORY dirs... DESTINATION <dir>\n"
216 " [FILE_PERMISSIONS permissions...]\n"
217 " [DIRECTORY_PERMISSIONS permissions...]\n"
218 " [USE_SOURCE_PERMISSIONS]\n"
219 " [CONFIGURATIONS [Debug|Release|...]]\n"
220 " [COMPONENT <component>] [FILES_MATCHING]\n"
221 " [[PATTERN <pattern> | REGEX <regex>]\n"
222 " [EXCLUDE] [PERMISSIONS permissions...]] [...])\n"
223 "The DIRECTORY form installs contents of one or more directories "
224 "to a given destination. "
225 "The directory structure is copied verbatim to the destination. "
226 "The last component of each directory name is appended to the "
227 "destination directory but a trailing slash may be used to "
228 "avoid this because it leaves the last component empty. "
229 "Directory names given as relative paths are interpreted with "
230 "respect to the current source directory. "
231 "If no input directory names are given the destination directory "
232 "will be created but nothing will be installed into it. "
233 "The FILE_PERMISSIONS and DIRECTORY_PERMISSIONS options specify "
234 "permissions given to files and directories in the destination. "
235 "If USE_SOURCE_PERMISSIONS is specified and FILE_PERMISSIONS is not, "
236 "file permissions will be copied from the source directory structure. "
237 "If no permissions are specified files will be given the default "
238 "permissions specified in the FILES form of the command, and the "
239 "directories will be given the default permissions specified in the "
240 "PROGRAMS form of the command.\n"
242 "Installation of directories may be controlled with fine granularity "
243 "using the PATTERN or REGEX options. These \"match\" options specify a "
244 "globbing pattern or regular expression to match directories or files "
245 "encountered within input directories. They may be used to apply "
246 "certain options (see below) to a subset of the files and directories "
248 "The full path to each input file or directory "
249 "(with forward slashes) is matched against the expression. "
250 "A PATTERN will match only complete file names: the portion of the "
251 "full path matching the pattern must occur at the end of the file name "
252 "and be preceded by a slash. "
253 "A REGEX will match any portion of the full path but it may use "
254 "'/' and '$' to simulate the PATTERN behavior. "
255 "By default all files and directories are installed whether "
256 "or not they are matched. "
257 "The FILES_MATCHING option may be given before the first match option "
258 "to disable installation of files (but not directories) not matched by "
259 "any expression. For example, the code\n"
260 " install(DIRECTORY src/ DESTINATION include/myproj\n"
261 " FILES_MATCHING PATTERN \"*.h\")\n"
262 "will extract and install header files from a source tree.\n"
263 "Some options may follow a PATTERN or REGEX expression and are "
264 "applied only to files or directories matching them. "
265 "The EXCLUDE option will skip the matched file or directory. "
266 "The PERMISSIONS option overrides the permissions setting for the "
267 "matched file or directory. "
268 "For example the code\n"
269 " install(DIRECTORY icons scripts/ DESTINATION share/myproj\n"
270 " PATTERN \"CVS\" EXCLUDE\n"
271 " PATTERN \"scripts/*\"\n"
272 " PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ\n"
273 " GROUP_EXECUTE GROUP_READ)\n"
274 "will install the icons directory to share/myproj/icons and the "
275 "scripts directory to share/myproj. The icons will get default file "
276 "permissions, the scripts will be given specific permissions, and "
277 "any CVS directories will be excluded."
279 "The SCRIPT and CODE signature:\n"
280 " install([[SCRIPT <file>] [CODE <code>]] [...])\n"
281 "The SCRIPT form will invoke the given CMake script files during "
282 "installation. If the script file name is a relative path "
283 "it will be interpreted with respect to the current source directory. "
284 "The CODE form will invoke the given CMake code during installation. "
285 "Code is specified as a single argument inside a double-quoted string. "
286 "For example, the code\n"
287 " install(CODE \"MESSAGE(\\\"Sample install message.\\\")\")\n"
288 "will print a message during installation.\n"
290 "The EXPORT signature:\n"
291 " install(EXPORT <export-name> DESTINATION <dir>\n"
292 " [NAMESPACE <namespace>] [FILE <name>.cmake]\n"
293 " [PERMISSIONS permissions...]\n"
294 " [CONFIGURATIONS [Debug|Release|...]]\n"
295 " [COMPONENT <component>])\n"
296 "The EXPORT form generates and installs a CMake file containing code "
297 "to import targets from the installation tree into another project. "
298 "Target installations are associated with the export <export-name> "
299 "using the EXPORT option of the install(TARGETS ...) signature "
300 "documented above. The NAMESPACE option will prepend <namespace> to "
301 "the target names as they are written to the import file. "
302 "By default the generated file will be called <export-name>.cmake but "
303 "the FILE option may be used to specify a different name. The value "
304 "given to the FILE option must be a file name with the \".cmake\" "
306 "If a CONFIGURATIONS option is given then the file will only be "
307 "installed when one of the named configurations is installed. "
308 "Additionally, the generated import file will reference only the "
309 "matching target configurations. "
310 "If a COMPONENT option is specified that does not match that given "
311 "to the targets associated with <export-name> the behavior is "
313 "If a library target is included in the export but "
314 "a target to which it links is not included the behavior is "
317 "The EXPORT form is useful to help outside projects use targets built "
318 "and installed by the current project. For example, the code\n"
319 " install(TARGETS myexe EXPORT myproj DESTINATION bin)\n"
320 " install(EXPORT myproj NAMESPACE mp_ DESTINATION lib/myproj)\n"
321 "will install the executable myexe to <prefix>/bin and code to import "
322 "it in the file \"<prefix>/lib/myproj/myproj.cmake\". "
323 "An outside project may load this file with the include command "
324 "and reference the myexe executable from the installation tree using "
325 "the imported target name mp_myexe as if the target were built "
328 "NOTE: This command supercedes the INSTALL_TARGETS command and the "
329 "target properties PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT. "
330 "It also replaces the FILES forms of the INSTALL_FILES and "
331 "INSTALL_PROGRAMS commands. "
332 "The processing order of these install rules relative to those "
333 "generated by INSTALL_TARGETS, INSTALL_FILES, and INSTALL_PROGRAMS "
334 "commands is not defined.\n"
338 cmTypeMacro(cmInstallCommand
, cmCommand
);
341 bool HandleScriptMode(std::vector
<std::string
> const& args
);
342 bool HandleTargetsMode(std::vector
<std::string
> const& args
);
343 bool HandleFilesMode(std::vector
<std::string
> const& args
);
344 bool HandleDirectoryMode(std::vector
<std::string
> const& args
);
345 bool HandleExportMode(std::vector
<std::string
> const& args
);
346 bool MakeFilesFullPath(const char* modeName
,
347 const std::vector
<std::string
>& relFiles
,
348 std::vector
<std::string
>& absFiles
);