cmFileCommand.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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(GLOB variable [RELATIVE path] [globbing expressions]...)\n"
  66. " file(GLOB_RECURSE variable [RELATIVE path] \n"
  67. " [globbing expressions]...)\n"
  68. " file(REMOVE [file1 ...])\n"
  69. " file(REMOVE_RECURSE [file1 ...])\n"
  70. " file(MAKE_DIRECTORY [directory1 directory2 ...])\n"
  71. " file(RELATIVE_PATH variable directory file)\n"
  72. " file(TO_CMAKE_PATH path result)\n"
  73. " file(TO_NATIVE_PATH path result)\n"
  74. "WRITE will write a message into a file called 'filename'. It "
  75. "overwrites the file if it already exists, and creates the file "
  76. "if it does not exist.\n"
  77. "APPEND will write a message into a file same as WRITE, except "
  78. "it will append it to the end of the file\n"
  79. "NOTE: When using file WRITE and file APPEND, the produced file "
  80. "cannot be used as an input to CMake (configure_file, source file ...) "
  81. "because it will lead to an infinite loop. Use configure_file if you "
  82. "want to generate input files to CMake.\n"
  83. "READ will read the content of a file and store it into the "
  84. "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 similar list as the regular GLOB, except "
  116. "it will traverse all the subdirectories of the matched directory and "
  117. "match the files.\n"
  118. "Examples of recursive globbing include:\n"
  119. " /dir/*.py - match all python files in /dir and subdirectories\n"
  120. "MAKE_DIRECTORY will create the given directories, also if their parent "
  121. "directories don't exist yet\n"
  122. "REMOVE will remove the given files, also in subdirectories\n"
  123. "REMOVE_RECURSE will remove the given files and directories, also "
  124. "non-empty directories\n"
  125. "RELATIVE_PATH will determine relative path from directory to the given"
  126. " file.\n"
  127. "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
  128. " The input can be a single path or a system path like \"$ENV{PATH}\". "
  129. " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
  130. " one argument.\n"
  131. "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
  132. " a cmake style path into the native path style \\ for windows and / "
  133. "for UNIX.";
  134. }
  135. cmTypeMacro(cmFileCommand, cmCommand);
  136. protected:
  137. bool HandleRemove(std::vector<std::string> const& args, bool recurse);
  138. bool HandleWriteCommand(std::vector<std::string> const& args, bool append);
  139. bool HandleReadCommand(std::vector<std::string> const& args);
  140. bool HandleStringsCommand(std::vector<std::string> const& args);
  141. bool HandleGlobCommand(std::vector<std::string> const& args, bool recurse);
  142. bool HandleMakeDirectoryCommand(std::vector<std::string> const& args);
  143. bool HandleRelativePathCommand(std::vector<std::string> const& args);
  144. bool HandleCMakePathCommand(std::vector<std::string> const& args,
  145. bool nativePath);
  146. // file(INSTALL ...) related functions
  147. bool HandleInstallCommand(std::vector<std::string> const& args);
  148. bool ParseInstallArgs(std::vector<std::string> const& args,
  149. cmFileInstaller& installer,
  150. std::map<cmStdString, const char*>& properties,
  151. int& itype,
  152. std::string& destination,
  153. std::string& rename,
  154. std::vector<std::string>& files,
  155. bool& optional
  156. );
  157. bool DoInstall(cmFileInstaller& installer,
  158. const int itype,
  159. const std::string& rename,
  160. const std::string& destination,
  161. const std::vector<std::string>& files,
  162. const bool optional
  163. );
  164. void GetTargetTypeFromString(const std::string& stype, int& itype) const;
  165. bool HandleInstallDestination(cmFileInstaller& installer,
  166. std::string& destination);
  167. void HandleInstallPermissions(cmFileInstaller& installer,
  168. mode_t& permissions_file,
  169. mode_t& permissions_dir,
  170. int itype,
  171. bool use_given_permissions_file,
  172. bool use_given_permissions_dir,
  173. bool use_source_permissions) const;
  174. };
  175. #endif