cmFileCommand.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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(REMOVE [file1 ...])\n"
  70. " file(REMOVE_RECURSE [file1 ...])\n"
  71. " file(MAKE_DIRECTORY [directory1 directory2 ...])\n"
  72. " file(RELATIVE_PATH variable directory file)\n"
  73. " file(TO_CMAKE_PATH path result)\n"
  74. " file(TO_NATIVE_PATH path result)\n"
  75. " file(DOWNLOAD url file [TIMEOUT timeout] [STATUS status] [LOG log])\n"
  76. "WRITE will write a message into a file called 'filename'. It "
  77. "overwrites the file if it already exists, and creates the file "
  78. "if it does not exist.\n"
  79. "APPEND will write a message into a file same as WRITE, except "
  80. "it will append it to the end of the file\n"
  81. "READ will read the content of a file and store it into the "
  82. "variable. It will start at the given offset and read up to numBytes. "
  83. "If the argument HEX is given, the binary data will be converted to "
  84. "hexadecimal representation and this will be stored in the variable.\n"
  85. "STRINGS will parse a list of ASCII strings from a file and "
  86. "store it in a variable. Binary data in the file are ignored. Carriage "
  87. "return (CR) characters are ignored. It works also for Intel Hex and "
  88. "Motorola S-record files, which are automatically converted to binary "
  89. "format when reading them. Disable this using NO_HEX_CONVERSION.\n"
  90. "LIMIT_COUNT sets the maximum number of strings to return. "
  91. "LIMIT_INPUT sets the maximum number of bytes to read from "
  92. "the input file. "
  93. "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
  94. "output variable. "
  95. "LENGTH_MINIMUM sets the minimum length of a string to return. "
  96. "Shorter strings are ignored. "
  97. "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
  98. "strings are split into strings no longer than the maximum length. "
  99. "NEWLINE_CONSUME allows newlines to be included in strings instead "
  100. "of terminating them.\n"
  101. "REGEX specifies a regular expression that a string must match to be "
  102. "returned. Typical usage \n"
  103. " file(STRINGS myfile.txt myfile)\n"
  104. "stores a list in the variable \"myfile\" in which each item is "
  105. "a line from the input file.\n"
  106. "GLOB will generate a list of all files that match the globbing "
  107. "expressions and store it into the variable. Globbing expressions "
  108. "are similar to regular expressions, but much simpler. If RELATIVE "
  109. "flag is specified for an expression, the results will be returned "
  110. "as a relative path to the given path.\n"
  111. "Examples of globbing expressions include:\n"
  112. " *.cxx - match all files with extension cxx\n"
  113. " *.vt? - match all files with extension vta,...,vtz\n"
  114. " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
  115. "GLOB_RECURSE will generate a list similar to the regular GLOB, except "
  116. "it will traverse all the subdirectories of the matched directory and "
  117. "match the files. Subdirectories that are symlinks are only traversed "
  118. "if FOLLOW_SYMLINKS is given or cmake policy CMP0009 is not set to NEW. "
  119. "See cmake --help-policy CMP0009 for more information.\n"
  120. "Examples of recursive globbing include:\n"
  121. " /dir/*.py - match all python files in /dir and subdirectories\n"
  122. "MAKE_DIRECTORY will create the given directories, also if their parent "
  123. "directories don't exist yet\n"
  124. "REMOVE will remove the given files, also in subdirectories\n"
  125. "REMOVE_RECURSE will remove the given files and directories, also "
  126. "non-empty directories\n"
  127. "RELATIVE_PATH will determine relative path from directory to the given"
  128. " file.\n"
  129. "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
  130. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  131. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  132. " one argument.\n"
  133. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  134. " a cmake style path into the native path style \\ for windows and / "
  135. "for UNIX.\n"
  136. "DOWNLOAD will download the given URL to the given file. "
  137. "If LOG var is specified a log of the download will be put in var. "
  138. "If STATUS var is specified the status of the operation will"
  139. " be put in var. The status is returned in a list of length 2. "
  140. "The first element is the numeric return value for the operation, "
  141. "and the second element is a string value for the error. A 0 "
  142. "numeric error means no error in the operation. "
  143. "If TIMEOUT time is specified, the operation will "
  144. "timeout after time seconds, time can be specified as a float.\n";
  145. }
  146. cmTypeMacro(cmFileCommand, cmCommand);
  147. protected:
  148. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  149. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  150. bool HandleReadCommand(std::vector<std::string> const& args);
  151. bool HandleStringsCommand(std::vector<std::string> const& args);
  152. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  153. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  154. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  155. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  156. bool nativePath);
  157. bool HandleRPathChangeCommand(std::vector<std::string> const& args);
  158. bool HandleRPathCheckCommand(std::vector<std::string> const& args);
  159. bool HandleRPathRemoveCommand(std::vector<std::string> const& args);
  160. // file(INSTALL ...) related functions
  161. bool HandleInstallCommand(std::vector<std::string> const& args);
  162. bool ParseInstallArgs(std::vector<std::string> const& args,
  163. cmFileInstaller& installer,
  164. std::map<cmStdString, const char*>& properties,
  165. int& itype,
  166. std::string& destination,
  167. std::string& rename,
  168. std::vector<std::string>& files,
  169. bool& optional
  170. );
  171. bool DoInstall(cmFileInstaller& installer,
  172. const int itype,
  173. const std::string& rename,
  174. const std::string& destination,
  175. const std::vector<std::string>& files,
  176. const bool optional
  177. );
  178. bool HandleDownloadCommand(std::vector<std::string> const& args);
  179. void GetTargetTypeFromString(const std::string& stype, int& itype) const;
  180. bool HandleInstallDestination(cmFileInstaller& installer,
  181. std::string& destination);
  182. void HandleInstallPermissions(cmFileInstaller& installer,
  183. mode_t& permissions_file,
  184. mode_t& permissions_dir,
  185. int itype,
  186. bool use_given_permissions_file,
  187. bool use_given_permissions_dir,
  188. bool use_source_permissions) const;
  189. };
  190. #endif