1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmFileCommand.h,v $
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.32 $
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 " [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 "WRITE will write a message into a file called 'filename'. It "
88 "overwrites the file if it already exists, and creates the file "
89 "if it does not exist.\n"
90 "APPEND will write a message into a file same as WRITE, except "
91 "it will append it to the end of the file\n"
92 "NOTE: When using file WRITE and file APPEND, the produced file "
93 "cannot be used as an input to CMake (configure_file, source file ...) "
94 "because it will lead to an infinite loop. Use configure_file if you "
95 "want to generate input files to CMake.\n"
96 "READ will read the content of a file and store it into the "
97 "variable. It will start at the given offset and read up to numBytes. "
98 "If the argument HEX is given, the binary data will be converted to "
99 "hexadecimal representation and this will be stored in the variable.\n"
100 "STRINGS will parse a list of ASCII strings from a file and "
101 "store it in a variable. Binary data in the file are ignored. Carriage "
102 "return (CR) characters are ignored. It works also for Intel Hex and "
103 "Motorola S-record files, which are automatically converted to binary "
104 "format when reading them. Disable this using NO_HEX_CONVERSION.\n"
105 "LIMIT_COUNT sets the maximum number of strings to return. "
106 "LIMIT_INPUT sets the maximum number of bytes to read from "
108 "LIMIT_OUTPUT sets the maximum number of bytes to store in the "
110 "LENGTH_MINIMUM sets the minimum length of a string to return. "
111 "Shorter strings are ignored. "
112 "LENGTH_MAXIMUM sets the maximum length of a string to return. Longer "
113 "strings are split into strings no longer than the maximum length. "
114 "NEWLINE_CONSUME allows newlines to be included in strings instead "
115 "of terminating them.\n"
116 "REGEX specifies a regular expression that a string must match to be "
117 "returned. Typical usage \n"
118 " file(STRINGS myfile.txt myfile)\n"
119 "stores a list in the variable \"myfile\" in which each item is "
120 "a line from the input file.\n"
121 "GLOB will generate a list of all files that match the globbing "
122 "expressions and store it into the variable. Globbing expressions "
123 "are similar to regular expressions, but much simpler. If RELATIVE "
124 "flag is specified for an expression, the results will be returned "
125 "as a relative path to the given path.\n"
126 "Examples of globbing expressions include:\n"
127 " *.cxx - match all files with extension cxx\n"
128 " *.vt? - match all files with extension vta,...,vtz\n"
129 " f[3-5].txt - match files f3.txt, f4.txt, f5.txt\n"
130 "GLOB_RECURSE will generate similar list as the regular GLOB, except "
131 "it will traverse all the subdirectories of the matched directory and "
133 "Examples of recursive globbing include:\n"
134 " /dir/*.py - match all python files in /dir and subdirectories\n"
135 "MAKE_DIRECTORY will create the given directories, also if their parent "
136 "directories don't exist yet\n"
137 "REMOVE will remove the given files, also in subdirectories\n"
138 "REMOVE_RECURSE will remove the given files and directories, also "
139 "non-empty directories\n"
140 "RELATIVE_PATH will determine relative path from directory to the given"
142 "TO_CMAKE_PATH will convert path into a cmake style path with unix /. "
143 " The input can be a single path or a system path like \"$ENV{PATH}\". "
144 " Note the double quotes around the ENV call TO_CMAKE_PATH only takes "
146 "TO_NATIVE_PATH works just like TO_CMAKE_PATH, but will convert from "
147 " a cmake style path into the native path style \\ for windows and / "
151 cmTypeMacro(cmFileCommand
, cmCommand
);
154 bool HandleRemove(std::vector
<std::string
> const& args
, bool recurse
);
155 bool HandleWriteCommand(std::vector
<std::string
> const& args
, bool append
);
156 bool HandleReadCommand(std::vector
<std::string
> const& args
);
157 bool HandleStringsCommand(std::vector
<std::string
> const& args
);
158 bool HandleGlobCommand(std::vector
<std::string
> const& args
, bool recurse
);
159 bool HandleMakeDirectoryCommand(std::vector
<std::string
> const& args
);
161 bool HandleRelativePathCommand(std::vector
<std::string
> const& args
);
162 bool HandleCMakePathCommand(std::vector
<std::string
> const& args
,
165 // file(INSTALL ...) related functions
166 bool HandleInstallCommand(std::vector
<std::string
> const& args
);
167 bool ParseInstallArgs(std::vector
<std::string
> const& args
,
168 cmFileInstaller
& installer
,
169 std::map
<cmStdString
, const char*>& properties
,
171 std::string
& destination
,
173 std::vector
<std::string
>& files
,
176 bool DoInstall(cmFileInstaller
& installer
,
178 const std::string
& rename
,
179 const std::string
& destination
,
180 const std::vector
<std::string
>& files
,
183 void GetTargetTypeFromString(const std::string
& stype
, int& itype
) const;
184 bool HandleInstallDestination(cmFileInstaller
& installer
,
185 std::string
& destination
);
186 void HandleInstallPermissions(cmFileInstaller
& installer
,
187 mode_t
& permissions_file
,
188 mode_t
& permissions_dir
,
190 bool use_given_permissions_file
,
191 bool use_given_permissions_dir
,
192 bool use_source_permissions
) const;