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