cmFileCommand.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. " [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. "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. "NOTE: When using file WRITE and file APPEND, the produced file "
  81. "cannot be used as an input to CMake (configure_file, source file ...) "
  82. "because it will lead to an infinite loop. Use configure_file if you "
  83. "want to generate input files to CMake.\n"
  84. "READ will read the content of a file and store it into the "
  85. "variable. It will start at the given offset and read up to numBytes. "
  86. "If the argument HEX is given, the binary data will be converted to "
  87. "hexadecimal representation and this will be stored in the variable.\n"
  88. "STRINGS will parse a list of ASCII strings from a file and "
  89. "store it in a variable. Binary data in the file are ignored. Carriage "
  90. "return (CR) characters are ignored. It works also for Intel Hex and "
  91. "Motorola S-record files, which are automatically converted to binary "
  92. "format when reading them. Disable this using NO_HEX_CONVERSION.\n"
  93. "LIMIT_COUNT sets the maximum number of strings to return. "
  94. "LIMIT_INPUT sets the maximum number of bytes to read from "
  95. "the input file. "
  96. "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
  97. "output variable. "
  98. "LENGTH_MINIMUM sets the minimum length of a string to return. "
  99. "Shorter strings are ignored. "
  100. "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
  101. "strings are split into strings no longer than the maximum length. "
  102. "NEWLINE_CONSUME allows newlines to be included in strings instead "
  103. "of terminating them.\n"
  104. "REGEX specifies a regular expression that a string must match to be "
  105. "returned. Typical usage \n"
  106. " file(STRINGS myfile.txt myfile)\n"
  107. "stores a list in the variable \"myfile\" in which each item is "
  108. "a line from the input file.\n"
  109. "GLOB will generate a list of all files that match the globbing "
  110. "expressions and store it into the variable. Globbing expressions "
  111. "are similar to regular expressions, but much simpler. If RELATIVE "
  112. "flag is specified for an expression, the results will be returned "
  113. "as a relative path to the given path.\n"
  114. "Examples of globbing expressions include:\n"
  115. " *.cxx - match all files with extension cxx\n"
  116. " *.vt? - match all files with extension vta,...,vtz\n"
  117. " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
  118. "GLOB_RECURSE will generate similar list as the regular GLOB, except "
  119. "it will traverse all the subdirectories of the matched directory and "
  120. "match the files.\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. "REMOVE will remove the given files, also in subdirectories\n"
  126. "REMOVE_RECURSE will remove the given files and directories, also "
  127. "non-empty directories\n"
  128. "RELATIVE_PATH will determine relative path from directory to the given"
  129. " file.\n"
  130. "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
  131. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  132. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  133. " one argument.\n"
  134. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  135. " a cmake style path into the native path style \\ for windows and / "
  136. "for UNIX.";
  137. }
  138. cmTypeMacro(cmFileCommand, cmCommand);
  139. protected:
  140. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  141. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  142. bool HandleReadCommand(std::vector<std::string> const& args);
  143. bool HandleStringsCommand(std::vector<std::string> const& args);
  144. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  145. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  146. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  147. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  148. bool nativePath);
  149. // file(INSTALL ...) related functions
  150. bool HandleInstallCommand(std::vector<std::string> const& args);
  151. bool ParseInstallArgs(std::vector<std::string> const& args,
  152. cmFileInstaller& installer,
  153. std::map<cmStdString, const char*>& properties,
  154. int& itype,
  155. std::string& destination,
  156. std::string& rename,
  157. std::vector<std::string>& files,
  158. bool& optional
  159. );
  160. bool DoInstall(cmFileInstaller& installer,
  161. const int itype,
  162. const std::string& rename,
  163. const std::string& destination,
  164. const std::vector<std::string>& files,
  165. const bool optional
  166. );
  167. void GetTargetTypeFromString(const std::string& stype, int& itype) const;
  168. bool HandleInstallDestination(cmFileInstaller& installer,
  169. std::string& destination);
  170. void HandleInstallPermissions(cmFileInstaller& installer,
  171. mode_t& permissions_file,
  172. mode_t& permissions_dir,
  173. int itype,
  174. bool use_given_permissions_file,
  175. bool use_given_permissions_dir,
  176. bool use_source_permissions) const;
  177. };
  178. #endif