cmFileCommand.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. /**
  37. * This determines if the command is invoked when in script mode.
  38. */
  39. virtual bool IsScriptable() { return true; }
  40. /**
  41. * The name of the command as specified in CMakeList.txt.
  42. */
  43. virtual const char* GetName() { return "FILE";}
  44. /**
  45. * Succinct documentation.
  46. */
  47. virtual const char* GetTerseDocumentation()
  48. {
  49. return "File manipulation command.";
  50. }
  51. /**
  52. * More documentation.
  53. */
  54. virtual const char* GetFullDocumentation()
  55. {
  56. return
  57. " FILE(WRITE filename \"message to write\"... )\n"
  58. " FILE(APPEND filename \"message to write\"... )\n"
  59. " FILE(READ filename variable [LIMIT numBytes])\n"
  60. " FILE(STRINGS filename variable [LIMIT_COUNT num]\n"
  61. " [LIMIT_INPUT numBytes] [LIMIT_OUTPUT numBytes]\n"
  62. " [LENGTH_MINIMUM numBytes] [LENGTH_MAXIMUM numBytes]\n"
  63. " [NEWLINE_CONSUME] [REGEX regex]\n"
  64. " [NO_HEX_CONVERSION])\n"
  65. " FILE(HEX_TO_BIN inputfile outputfile)\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 [directory]...)\n"
  70. " FILE(REMOVE_RECURSE [directory]...)\n"
  71. " FILE(MAKE_DIRECTORY [directory]...)\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.\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. /* "HEX_TO_BIN will convert an Intel hex file or Motorola S-record file "
  92. "to a binary file. If the input file is no such file it will simply "
  93. "be copied. \n"*/
  94. "LIMIT_COUNT sets the maximum number of strings to return. "
  95. "LIMIT_INPUT sets the maximum number of bytes to read from "
  96. "the input file. "
  97. "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
  98. "output variable. "
  99. "LENGTH_MINIMUM sets the minimum length of a string to return. "
  100. "Shorter strings are ignored. "
  101. "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
  102. "strings are split into strings no longer than the maximum length. "
  103. "NEWLINE_CONSUME allows newlines to be included in strings instead "
  104. "of terminating them. "
  105. "REGEX specifies a regular expression that a string must match to be "
  106. "returned. "
  107. "Typical usage \n"
  108. " FILE(STRINGS myfile.txt myfile)\n"
  109. "stores a list in the variable \"myfile\" in which each item is "
  110. "a line from the input file.\n"
  111. "GLOB will generate a list of all files that match the globbing "
  112. "expressions and store it into the variable. Globbing expressions "
  113. "are similar to regular expressions, but much simpler. If RELATIVE "
  114. "flag is specified for an expression, the results will be returned "
  115. "as a relative path to the given path.\n"
  116. "Examples of globbing expressions include:\n"
  117. " *.cxx - match all files with extension cxx\n"
  118. " *.vt? - match all files with extension vta,...,vtz\n"
  119. " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
  120. "GLOB_RECURSE will generate similar list as the regular GLOB, except "
  121. "it will traverse all the subdirectories of the matched directory and "
  122. "match the files.\n"
  123. "Examples of recursive globbing include:\n"
  124. " /dir/*.py - match all python files in /dir and subdirectories\n"
  125. "MAKE_DIRECTORY will create a directory at the specified location\n"
  126. "RELATIVE_PATH will determine relative path from directory to the given"
  127. " file.\n"
  128. "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
  129. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  130. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  131. " one argument.\n"
  132. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  133. " a cmake style path into the native path style \\ for windows and / "
  134. "for UNIX.";
  135. }
  136. cmTypeMacro(cmFileCommand, cmCommand);
  137. protected:
  138. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  139. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  140. bool HandleReadCommand(std::vector<std::string> const& args);
  141. bool HandleStringsCommand(std::vector<std::string> const& args);
  142. // bool HandleHex2BinCommand(std::vector<std::string> const& args);
  143. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  144. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  145. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  146. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  147. bool nativePath);
  148. void ComputeVersionedName(std::string& name, const char* version);
  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::set<cmStdString>& components,
  154. std::set<cmStdString>& configurations,
  155. std::map<cmStdString, const char*>& properties,
  156. int& itype,
  157. std::string& destination,
  158. std::string& rename,
  159. std::vector<std::string>& files,
  160. bool& optional
  161. );
  162. bool DoInstall(cmFileInstaller& installer,
  163. const std::set<cmStdString>& components,
  164. const std::set<cmStdString>& configurations,
  165. std::map<cmStdString, const char*>& properties,
  166. const int itype,
  167. const std::string& rename,
  168. const std::string& destination,
  169. const std::vector<std::string>& files,
  170. const bool optional
  171. );
  172. void GetTargetTypeFromString(const std::string& stype, int& itype) const;
  173. bool HandleInstallDestination(cmFileInstaller& installer,
  174. std::string& destination);
  175. void HandleInstallPermissions(cmFileInstaller& installer,
  176. mode_t& permissions_file,
  177. mode_t& permissions_dir,
  178. int itype,
  179. bool use_given_permissions_file,
  180. bool use_given_permissions_dir,
  181. bool use_source_permissions) const;
  182. };
  183. #endif