cmFileCommand.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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() { return true; }
  38. /**
  39. * The name of the command as specified in CMakeList.txt.
  40. */
  41. virtual const char* GetName() { return "file";}
  42. /**
  43. * Succinct documentation.
  44. */
  45. virtual const char* GetTerseDocumentation()
  46. {
  47. return "File manipulation command.";
  48. }
  49. /**
  50. * More documentation.
  51. */
  52. virtual const char* GetFullDocumentation()
  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(STRINGS filename variable [LIMIT_COUNT num]\n"
  59. " [LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]\n"
  60. " [LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]\n"
  61. " [NEWLINE_CONSUME] [REGEX regex]\n"
  62. " [NO_HEX_CONVERSION])\n"
  63. " file(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
  64. " file(GLOB_RECURSE variable [RELATIVE path] \n"
  65. " [FOLLOW_SYMLINKS] [globbing expressions]...)\n"
  66. " file(RENAME <oldname> <newname>)\n"
  67. " file(REMOVE [file1 ...])\n"
  68. " file(REMOVE_RECURSE [file1 ...])\n"
  69. " file(MAKE_DIRECTORY [directory1 directory2 ...])\n"
  70. " file(RELATIVE_PATH variable directory file)\n"
  71. " file(TO_CMAKE_PATH path result)\n"
  72. " file(TO_NATIVE_PATH path result)\n"
  73. " file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log]\n"
  74. " [EXPECTED_MD5 sum] [SHOW_PROGRESS])\n"
  75. "WRITE will write a message into a file called 'filename'. It "
  76. "overwrites the file if it already exists, and creates the file "
  77. "if it does not exist.\n"
  78. "APPEND will write a message into a file same as WRITE, except "
  79. "it will append it to the end of the file\n"
  80. "READ will read the content of a file and store it into the "
  81. "variable. It will start at the given offset and read up to numBytes. "
  82. "If the argument HEX is given, the binary data will be converted to "
  83. "hexadecimal representation and this will be stored in the variable.\n"
  84. "STRINGS will parse a list of ASCII strings from a file and "
  85. "store it in a variable. Binary data in the file are ignored. Carriage "
  86. "return (CR) characters are ignored. It works also for Intel Hex and "
  87. "Motorola S-record files, which are automatically converted to binary "
  88. "format when reading them. Disable this using NO_HEX_CONVERSION.\n"
  89. "LIMIT_COUNT sets the maximum number of strings to return. "
  90. "LIMIT_INPUT sets the maximum number of bytes to read from "
  91. "the input file. "
  92. "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
  93. "output variable. "
  94. "LENGTH_MINIMUM sets the minimum length of a string to return. "
  95. "Shorter strings are ignored. "
  96. "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
  97. "strings are split into strings no longer than the maximum length. "
  98. "NEWLINE_CONSUME allows newlines to be included in strings instead "
  99. "of terminating them.\n"
  100. "REGEX specifies a regular expression that a string must match to be "
  101. "returned. Typical usage \n"
  102. " file(STRINGS myfile.txt myfile)\n"
  103. "stores a list in the variable \"myfile\" in which each item is "
  104. "a line from the input file.\n"
  105. "GLOB will generate a list of all files that match the globbing "
  106. "expressions and store it into the variable. Globbing expressions "
  107. "are similar to regular expressions, but much simpler. If RELATIVE "
  108. "flag is specified for an expression, the results will be returned "
  109. "as a relative path to the given path.\n"
  110. "Examples of globbing expressions include:\n"
  111. " *.cxx - match all files with extension cxx\n"
  112. " *.vt? - match all files with extension vta,...,vtz\n"
  113. " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
  114. "GLOB_RECURSE will generate a list similar to the regular GLOB, except "
  115. "it will traverse all the subdirectories of the matched directory and "
  116. "match the files. Subdirectories that are symlinks are only traversed "
  117. "if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. "
  118. "See cmake --help-policy CMP0009 for more information.\n"
  119. "Examples of recursive globbing include:\n"
  120. " /dir/*.py - match all python files in /dir and subdirectories\n"
  121. "MAKE_DIRECTORY will create the given directories, also if their parent "
  122. "directories don't exist yet\n"
  123. "RENAME moves a file or directory within a filesystem, "
  124. "replacing the destination atomically."
  125. "\n"
  126. "REMOVE will remove the given files, also in subdirectories\n"
  127. "REMOVE_RECURSE will remove the given files and directories, also "
  128. "non-empty directories\n"
  129. "RELATIVE_PATH will determine relative path from directory to the given"
  130. " file.\n"
  131. "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
  132. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  133. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  134. " one argument.\n"
  135. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  136. " a cmake style path into the native path style \\ for windows and / "
  137. "for UNIX.\n"
  138. "DOWNLOAD will download the given URL to the given file. "
  139. "If LOG var is specified a log of the download will be put in var. "
  140. "If STATUS var is specified the status of the operation will"
  141. " be put in var. The status is returned in a list of length 2. "
  142. "The first element is the numeric return value for the operation, "
  143. "and the second element is a string value for the error. A 0 "
  144. "numeric error means no error in the operation. "
  145. "If TIMEOUT time is specified, the operation will "
  146. "timeout after time seconds, time should be specified as an integer. "
  147. "If EXPECTED_MD5 sum is specified, the operation will verify that the "
  148. "downloaded file's actual md5 sum matches the expected value. If it "
  149. "does not match, the operation fails with an error. "
  150. "If SHOW_PROGRESS is specified, progress information will be printed "
  151. "as status messages until the operation is complete."
  152. "\n"
  153. "The file() command also provides COPY and INSTALL signatures:\n"
  154. " file(<COPY|INSTALL> files... DESTINATION <dir>\n"
  155. " [FILE_PERMISSIONS permissions...]\n"
  156. " [DIRECTORY_PERMISSIONS permissions...]\n"
  157. " [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]\n"
  158. " [FILES_MATCHING]\n"
  159. " [[PATTERN <pattern> | REGEX <regex>]\n"
  160. " [EXCLUDE] [PERMISSIONS permissions...]] [...])\n"
  161. "The COPY signature copies files, directories, and symlinks to a "
  162. "destination folder. "
  163. "Relative input paths are evaluated with respect to the current "
  164. "source directory, and a relative destination is evaluated with "
  165. "respect to the current build directory. "
  166. "Copying preserves input file timestamps, and optimizes out a file "
  167. "if it exists at the destination with the same timestamp. "
  168. "Copying preserves input permissions unless explicit permissions or "
  169. "NO_SOURCE_PERMISSIONS are given (default is USE_SOURCE_PERMISSIONS). "
  170. "See the install(DIRECTORY) command for documentation of permissions, "
  171. "PATTERN, REGEX, and EXCLUDE options. "
  172. "\n"
  173. "The INSTALL signature differs slightly from COPY: "
  174. "it prints status messages, and NO_SOURCE_PERMISSIONS is default. "
  175. "Installation scripts generated by the install() command use this "
  176. "signature (with some undocumented options for internal use)."
  177. // Undocumented INSTALL options:
  178. // - RENAME <name>
  179. // - OPTIONAL
  180. // - FILES keyword to re-enter files... list
  181. // - PERMISSIONS before REGEX is alias for FILE_PERMISSIONS
  182. // - DIR_PERMISSIONS is alias for DIRECTORY_PERMISSIONS
  183. // - TYPE <FILE|DIRECTORY|EXECUTABLE|PROGRAM|
  184. // STATIC_LIBRARY|SHARED_LIBRARY|MODULE>
  185. // - COMPONENTS, CONFIGURATIONS, PROPERTIES (ignored for compat)
  186. ;
  187. }
  188. cmTypeMacro(cmFileCommand, cmCommand);
  189. protected:
  190. bool HandleRename(std::vector<std::string> const& args);
  191. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  192. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  193. bool HandleReadCommand(std::vector<std::string> const& args);
  194. bool HandleStringsCommand(std::vector<std::string> const& args);
  195. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  196. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  197. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  198. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  199. bool nativePath);
  200. bool HandleRPathChangeCommand(std::vector<std::string> const& args);
  201. bool HandleRPathCheckCommand(std::vector<std::string> const& args);
  202. bool HandleRPathRemoveCommand(std::vector<std::string> const& args);
  203. bool HandleDifferentCommand(std::vector<std::string> const& args);
  204. bool HandleCopyCommand(std::vector<std::string> const& args);
  205. bool HandleInstallCommand(std::vector<std::string> const& args);
  206. bool HandleDownloadCommand(std::vector<std::string> const& args);
  207. };
  208. #endif