cmFileCommand.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmFileCommand_h
  14. #define cmFileCommand_h
  15. #include "cmCommand.h"
  16. struct cmFileInstaller;
  17. /** \class cmFileCommand
  18. * \brief Command for manipulation of files
  19. *
  20. */
  21. class cmFileCommand : public cmCommand
  22. {
  23. public:
  24. /**
  25. * This is a virtual constructor for the command.
  26. */
  27. virtual cmCommand* Clone()
  28. {
  29. return new cmFileCommand;
  30. }
  31. /**
  32. * This is called when the command is first encountered in
  33. * the CMakeLists.txt file.
  34. */
  35. virtual bool InitialPass(std::vector<std::string> const& args,
  36. cmExecutionStatus &status);
  37. /**
  38. * This determines if the command is invoked when in script mode.
  39. */
  40. virtual bool IsScriptable() { return true; }
  41. /**
  42. * The name of the command as specified in CMakeList.txt.
  43. */
  44. virtual const char* GetName() { return "file";}
  45. /**
  46. * Succinct documentation.
  47. */
  48. virtual const char* GetTerseDocumentation()
  49. {
  50. return "File manipulation command.";
  51. }
  52. /**
  53. * More documentation.
  54. */
  55. virtual const char* GetFullDocumentation()
  56. {
  57. return
  58. " file(WRITE filename \"message to write\"... )\n"
  59. " file(APPEND filename \"message to write\"... )\n"
  60. " file(READ filename variable [LIMIT numBytes] [OFFSET offset] [HEX])\n"
  61. " file(STRINGS filename variable [LIMIT_COUNT num]\n"
  62. " [LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]\n"
  63. " [LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]\n"
  64. " [NEWLINE_CONSUME] [REGEX regex]\n"
  65. " [NO_HEX_CONVERSION])\n"
  66. " file(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
  67. " file(GLOB_RECURSE variable [RELATIVE path] \n"
  68. " [FOLLOW_SYMLINKS] [globbing expressions]...)\n"
  69. " file(RENAME <oldname> <newname>)\n"
  70. " file(REMOVE [file1 ...])\n"
  71. " file(REMOVE_RECURSE [file1 ...])\n"
  72. " file(MAKE_DIRECTORY [directory1 directory2 ...])\n"
  73. " file(RELATIVE_PATH variable directory file)\n"
  74. " file(TO_CMAKE_PATH path result)\n"
  75. " file(TO_NATIVE_PATH path result)\n"
  76. " file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log])\n"
  77. "WRITE will write a message into a file called 'filename'. It "
  78. "overwrites the file if it already exists, and creates the file "
  79. "if it does not exist.\n"
  80. "APPEND will write a message into a file same as WRITE, except "
  81. "it will append it to the end of the file\n"
  82. "READ will read the content of a file and store it into the "
  83. "variable. It will start at the given offset and read up to numBytes. "
  84. "If the argument HEX is given, the binary data will be converted to "
  85. "hexadecimal representation and this will be stored in the variable.\n"
  86. "STRINGS will parse a list of ASCII strings from a file and "
  87. "store it in a variable. Binary data in the file are ignored. Carriage "
  88. "return (CR) characters are ignored. It works also for Intel Hex and "
  89. "Motorola S-record files, which are automatically converted to binary "
  90. "format when reading them. Disable this using NO_HEX_CONVERSION.\n"
  91. "LIMIT_COUNT sets the maximum number of strings to return. "
  92. "LIMIT_INPUT sets the maximum number of bytes to read from "
  93. "the input file. "
  94. "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
  95. "output variable. "
  96. "LENGTH_MINIMUM sets the minimum length of a string to return. "
  97. "Shorter strings are ignored. "
  98. "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
  99. "strings are split into strings no longer than the maximum length. "
  100. "NEWLINE_CONSUME allows newlines to be included in strings instead "
  101. "of terminating them.\n"
  102. "REGEX specifies a regular expression that a string must match to be "
  103. "returned. Typical usage \n"
  104. " file(STRINGS myfile.txt myfile)\n"
  105. "stores a list in the variable \"myfile\" in which each item is "
  106. "a line from the input file.\n"
  107. "GLOB will generate a list of all files that match the globbing "
  108. "expressions and store it into the variable. Globbing expressions "
  109. "are similar to regular expressions, but much simpler. If RELATIVE "
  110. "flag is specified for an expression, the results will be returned "
  111. "as a relative path to the given path.\n"
  112. "Examples of globbing expressions include:\n"
  113. " *.cxx - match all files with extension cxx\n"
  114. " *.vt? - match all files with extension vta,...,vtz\n"
  115. " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
  116. "GLOB_RECURSE will generate a list similar to the regular GLOB, except "
  117. "it will traverse all the subdirectories of the matched directory and "
  118. "match the files. Subdirectories that are symlinks are only traversed "
  119. "if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. "
  120. "See cmake --help-policy CMP0009 for more information.\n"
  121. "Examples of recursive globbing include:\n"
  122. " /dir/*.py - match all python files in /dir and subdirectories\n"
  123. "MAKE_DIRECTORY will create the given directories, also if their parent "
  124. "directories don't exist yet\n"
  125. "RENAME moves a file or directory within a filesystem, "
  126. "replacing the destination atomically."
  127. "\n"
  128. "REMOVE will remove the given files, also in subdirectories\n"
  129. "REMOVE_RECURSE will remove the given files and directories, also "
  130. "non-empty directories\n"
  131. "RELATIVE_PATH will determine relative path from directory to the given"
  132. " file.\n"
  133. "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
  134. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  135. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  136. " one argument.\n"
  137. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  138. " a cmake style path into the native path style \\ for windows and / "
  139. "for UNIX.\n"
  140. "DOWNLOAD will download the given URL to the given file. "
  141. "If LOG var is specified a log of the download will be put in var. "
  142. "If STATUS var is specified the status of the operation will"
  143. " be put in var. The status is returned in a list of length 2. "
  144. "The first element is the numeric return value for the operation, "
  145. "and the second element is a string value for the error. A 0 "
  146. "numeric error means no error in the operation. "
  147. "If TIMEOUT time is specified, the operation will "
  148. "timeout after time seconds, time can be specified as a float.\n";
  149. }
  150. cmTypeMacro(cmFileCommand, cmCommand);
  151. protected:
  152. bool HandleRename(std::vector<std::string> const& args);
  153. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  154. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  155. bool HandleReadCommand(std::vector<std::string> const& args);
  156. bool HandleStringsCommand(std::vector<std::string> const& args);
  157. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  158. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  159. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  160. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  161. bool nativePath);
  162. bool HandleRPathChangeCommand(std::vector<std::string> const& args);
  163. bool HandleRPathCheckCommand(std::vector<std::string> const& args);
  164. bool HandleRPathRemoveCommand(std::vector<std::string> const& args);
  165. bool HandleDifferentCommand(std::vector<std::string> const& args);
  166. // file(INSTALL ...) related functions
  167. bool HandleInstallCommand(std::vector<std::string> const& args);
  168. bool ParseInstallArgs(std::vector<std::string> const& args,
  169. cmFileInstaller& installer,
  170. std::map<cmStdString, const char*>& properties,
  171. int& itype,
  172. std::string& destination,
  173. std::string& rename,
  174. std::vector<std::string>& files,
  175. bool& optional
  176. );
  177. bool DoInstall(cmFileInstaller& installer,
  178. const int itype,
  179. const std::string& rename,
  180. const std::string& destination,
  181. const std::vector<std::string>& files,
  182. const bool optional
  183. );
  184. bool HandleDownloadCommand(std::vector<std::string> const& args);
  185. void GetTargetTypeFromString(const std::string& stype, int& itype) const;
  186. bool HandleInstallDestination(cmFileInstaller& installer,
  187. std::string& destination);
  188. void HandleInstallPermissions(cmFileInstaller& installer,
  189. mode_t& permissions_file,
  190. mode_t& permissions_dir,
  191. int itype,
  192. bool use_given_permissions_file,
  193. bool use_given_permissions_dir,
  194. bool use_source_permissions) const;
  195. };
  196. #endif