1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 cmFileCommand_h
13 #define cmFileCommand_h
15 #include "cmCommand.h"
17 struct cmFileInstaller;
19 /** \class cmFileCommand
20 * \brief Command for manipulation of files
23 class cmFileCommand : public cmCommand
27 * This is a virtual constructor for the command.
29 virtual cmCommand* Clone()
31 return new cmFileCommand;
35 * This is called when the command is first encountered in
36 * the CMakeLists.txt file.
38 virtual bool InitialPass(std::vector<std::string> const& args,
39 cmExecutionStatus &status);
42 * This determines if the command is invoked when in script mode.
44 virtual bool IsScriptable() const { return true; }
47 * The name of the command as specified in CMakeList.txt.
49 virtual const char* GetName() const { return "file";}
52 * Succinct documentation.
54 virtual const char* GetTerseDocumentation() const
56 return "File manipulation command.";
62 virtual const char* GetFullDocumentation() const
65 " file(WRITE filename \"message to write\"... )\n"
66 " file(APPEND filename \"message to write\"... )\n"
67 " file(READ filename variable [LIMIT numBytes] [OFFSET offset] [HEX])\n"
68 " file(<MD5|SHA1|SHA224|SHA256|SHA384|SHA512> filename variable)\n"
69 " file(STRINGS filename variable [LIMIT_COUNT num]\n"
70 " [LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]\n"
71 " [LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]\n"
72 " [NEWLINE_CONSUME] [REGEX regex]\n"
73 " [NO_HEX_CONVERSION])\n"
74 " file(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
75 " file(GLOB_RECURSE variable [RELATIVE path] \n"
76 " [FOLLOW_SYMLINKS] [globbing expressions]...)\n"
77 " file(RENAME <oldname> <newname>)\n"
78 " file(REMOVE [file1 ...])\n"
79 " file(REMOVE_RECURSE [file1 ...])\n"
80 " file(MAKE_DIRECTORY [directory1 directory2 ...])\n"
81 " file(RELATIVE_PATH variable directory file)\n"
82 " file(TO_CMAKE_PATH path result)\n"
83 " file(TO_NATIVE_PATH path result)\n"
84 " file(DOWNLOAD url file [INACTIVITY_TIMEOUT timeout]\n"
85 " [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS]\n"
86 " [EXPECTED_MD5 sum])\n"
87 " file(UPLOAD filename url [INACTIVITY_TIMEOUT timeout]\n"
88 " [TIMEOUT timeout] [STATUS status] [LOG log] [SHOW_PROGRESS])\n"
89 "WRITE will write a message into a file called 'filename'. It "
90 "overwrites the file if it already exists, and creates the file "
91 "if it does not exist.\n"
92 "APPEND will write a message into a file same as WRITE, except "
93 "it will append it to the end of the file\n"
94 "READ will read the content of a file and store it into the "
95 "variable. It will start at the given offset and read up to numBytes. "
96 "If the argument HEX is given, the binary data will be converted to "
97 "hexadecimal representation and this will be stored in the variable.\n"
98 "MD5, SHA1, SHA224, SHA256, SHA384, and SHA512 "
99 "will compute a cryptographic hash of the content of a file.\n"
100 "STRINGS will parse a list of ASCII strings from a file and "
101 "store it in a variable. Binary data in the file are ignored. Carriage "
102 "return (CR) characters are ignored. It works also for Intel Hex and "
103 "Motorola S-record files, which are automatically converted to binary "
104 "format when reading them. Disable this using NO_HEX_CONVERSION.\n"
105 "LIMIT_COUNT sets the maximum number of strings to return. "
106 "LIMIT_INPUT sets the maximum number of bytes to read from "
108 "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
110 "LENGTH_MINIMUM sets the minimum length of a string to return. "
111 "Shorter strings are ignored. "
112 "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
113 "strings are split into strings no longer than the maximum length. "
114 "NEWLINE_CONSUME allows newlines to be included in strings instead "
115 "of terminating them.\n"
116 "REGEX specifies a regular expression that a string must match to be "
117 "returned. Typical usage \n"
118 " file(STRINGS myfile.txt myfile)\n"
119 "stores a list in the variable \"myfile\" in which each item is "
120 "a line from the input file.\n"
121 "GLOB will generate a list of all files that match the globbing "
122 "expressions and store it into the variable. Globbing expressions "
123 "are similar to regular expressions, but much simpler. If RELATIVE "
124 "flag is specified for an expression, the results will be returned "
125 "as a relative path to the given path. "
126 "(We do not recommend using GLOB to collect a list of source files "
127 "from your source tree. If no CMakeLists.txt file changes when a "
128 "source is added or removed then the generated build system cannot "
129 "know when to ask CMake to regenerate.)"
131 "Examples of globbing expressions include:\n"
132 " *.cxx - match all files with extension cxx\n"
133 " *.vt? - match all files with extension vta,...,vtz\n"
134 " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
135 "GLOB_RECURSE will generate a list similar to the regular GLOB, except "
136 "it will traverse all the subdirectories of the matched directory and "
137 "match the files. Subdirectories that are symlinks are only traversed "
138 "if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. "
139 "See cmake --help-policy CMP0009 for more information.\n"
140 "Examples of recursive globbing include:\n"
141 " /dir/*.py - match all python files in /dir and subdirectories\n"
142 "MAKE_DIRECTORY will create the given directories, also if their parent "
143 "directories don't exist yet\n"
144 "RENAME moves a file or directory within a filesystem, "
145 "replacing the destination atomically."
147 "REMOVE will remove the given files, also in subdirectories\n"
148 "REMOVE_RECURSE will remove the given files and directories, also "
149 "non-empty directories\n"
150 "RELATIVE_PATH will determine relative path from directory to the given"
152 "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
153 " The input can be a single path or a system path like \"$ENV{PATH}\". "
154 " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
155 " one argument. This command will also convert the native list"
156 " delimiters for a list of paths like the PATH environment variable.\n"
157 "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
158 " a cmake style path into the native path style \\ for windows and / "
160 "DOWNLOAD will download the given URL to the given file. "
161 "If LOG var is specified a log of the download will be put in var. "
162 "If STATUS var is specified the status of the operation will"
163 " be put in var. The status is returned in a list of length 2. "
164 "The first element is the numeric return value for the operation, "
165 "and the second element is a string value for the error. A 0 "
166 "numeric error means no error in the operation. "
167 "If TIMEOUT time is specified, the operation will "
168 "timeout after time seconds, time should be specified as an integer. "
169 "The INACTIVITY_TIMEOUT specifies an integer number of seconds of "
170 "inactivity after which the operation should terminate. "
171 "If EXPECTED_MD5 sum is specified, the operation will verify that the "
172 "downloaded file's actual md5 sum matches the expected value. If it "
173 "does not match, the operation fails with an error. "
174 "If SHOW_PROGRESS is specified, progress information will be printed "
175 "as status messages until the operation is complete."
177 "UPLOAD will upload the given file to the given URL. "
178 "If LOG var is specified a log of the upload will be put in var. "
179 "If STATUS var is specified the status of the operation will"
180 " be put in var. The status is returned in a list of length 2. "
181 "The first element is the numeric return value for the operation, "
182 "and the second element is a string value for the error. A 0 "
183 "numeric error means no error in the operation. "
184 "If TIMEOUT time is specified, the operation will "
185 "timeout after time seconds, time should be specified as an integer. "
186 "The INACTIVITY_TIMEOUT specifies an integer number of seconds of "
187 "inactivity after which the operation should terminate. "
188 "If SHOW_PROGRESS is specified, progress information will be printed "
189 "as status messages until the operation is complete."
191 "The file() command also provides COPY and INSTALL signatures:\n"
192 " file(<COPY|INSTALL> files... DESTINATION <dir>\n"
193 " [FILE_PERMISSIONS permissions...]\n"
194 " [DIRECTORY_PERMISSIONS permissions...]\n"
195 " [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]\n"
196 " [FILES_MATCHING]\n"
197 " [[PATTERN <pattern> | REGEX <regex>]\n"
198 " [EXCLUDE] [PERMISSIONS permissions...]] [...])\n"
199 "The COPY signature copies files, directories, and symlinks to a "
200 "destination folder. "
201 "Relative input paths are evaluated with respect to the current "
202 "source directory, and a relative destination is evaluated with "
203 "respect to the current build directory. "
204 "Copying preserves input file timestamps, and optimizes out a file "
205 "if it exists at the destination with the same timestamp. "
206 "Copying preserves input permissions unless explicit permissions or "
207 "NO_SOURCE_PERMISSIONS are given (default is USE_SOURCE_PERMISSIONS). "
208 "See the install(DIRECTORY) command for documentation of permissions, "
209 "PATTERN, REGEX, and EXCLUDE options. "
211 "The INSTALL signature differs slightly from COPY: "
212 "it prints status messages, and NO_SOURCE_PERMISSIONS is default. "
213 "Installation scripts generated by the install() command use this "
214 "signature (with some undocumented options for internal use)."
215 // Undocumented INSTALL options:
218 // - FILES keyword to re-enter files... list
219 // - PERMISSIONS before REGEX is alias for FILE_PERMISSIONS
220 // - DIR_PERMISSIONS is alias for DIRECTORY_PERMISSIONS
221 // - TYPE <FILE|DIRECTORY|EXECUTABLE|PROGRAM|
222 // STATIC_LIBRARY|SHARED_LIBRARY|MODULE>
223 // - COMPONENTS, CONFIGURATIONS, PROPERTIES (ignored for compat)
227 cmTypeMacro(cmFileCommand, cmCommand);
230 bool HandleRename(std::vector<std::string> const& args);
231 bool HandleRemove(std::vector<std::string> const& args, bool recurse);
232 bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
233 bool HandleReadCommand(std::vector<std::string> const& args);
234 bool HandleHashCommand(std::vector<std::string> const& args);
235 bool HandleStringsCommand(std::vector<std::string> const& args);
236 bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
237 bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
239 bool HandleRelativePathCommand(std::vector<std::string> const& args);
240 bool HandleCMakePathCommand(std::vector<std::string> const& args,
242 bool HandleRPathChangeCommand(std::vector<std::string> const& args);
243 bool HandleRPathCheckCommand(std::vector<std::string> const& args);
244 bool HandleRPathRemoveCommand(std::vector<std::string> const& args);
245 bool HandleDifferentCommand(std::vector<std::string> const& args);
247 bool HandleCopyCommand(std::vector<std::string> const& args);
248 bool HandleInstallCommand(std::vector<std::string> const& args);
249 bool HandleDownloadCommand(std::vector<std::string> const& args);
250 bool HandleUploadCommand(std::vector<std::string> const& args);