cmFileCommand.h 14 KB

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