1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmWriteFileCommand.cxx,v $
6 <<<<<<< cmWriteFileCommand.cxx
7 Date: $Date: 2008/01/23 15:27:59 $
8 Version: $Revision: 1.16 $
10 Date: $Date: 2008-04-30 17:42:39 $
11 Version: $Revision: 1.17 $
14 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
15 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
17 This software is distributed WITHOUT ANY WARRANTY; without even
18 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 PURPOSE. See the above copyright notices for more information.
21 =========================================================================*/
22 #include "cmWriteFileCommand.h"
24 #include <sys/types.h>
28 bool cmWriteFileCommand
29 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
33 this->SetError("called with incorrect number of arguments");
37 std::vector
<std::string
>::const_iterator i
= args
.begin();
39 std::string fileName
= *i
;
40 bool overwrite
= true;
43 for(;i
!= args
.end(); ++i
)
55 if ( !this->Makefile
->CanIWriteThisFile(fileName
.c_str()) )
57 std::string e
= "attempted to write a file: " + fileName
58 + " into a source directory.";
59 this->SetError(e
.c_str());
60 cmSystemTools::SetFatalErrorOccured();
64 std::string dir
= cmSystemTools::GetFilenamePath(fileName
);
65 cmSystemTools::MakeDirectory(dir
.c_str());
68 #if defined( _MSC_VER ) || defined( __MINGW32__ )
70 #elif defined( __BORLANDC__ )
79 // Set permissions to writable
80 if ( cmSystemTools::GetPermissions(fileName
.c_str(), mode
) )
82 cmSystemTools::SetPermissions(fileName
.c_str(),
83 #if defined( _MSC_VER ) || defined( __MINGW32__ )
90 // If GetPermissions fails, pretend like it is ok. File open will fail if
91 // the file is not writable
92 std::ofstream
file(fileName
.c_str(),
93 overwrite
?std::ios::out
: std::ios::app
);
96 std::string error
= "Internal CMake error when trying to open file: ";
97 error
+= fileName
.c_str();
98 error
+= " for writing.";
99 this->SetError(error
.c_str());
102 file
<< message
<< std::endl
;
104 cmSystemTools::SetPermissions(fileName
.c_str(), mode
);