Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmConfigureFileCommand.cxx
blobb6837223fe3a57b1d7a8ebe8a69c412e64c2892c
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmConfigureFileCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.30 $
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 #include "cmConfigureFileCommand.h"
19 #include <cmsys/RegularExpression.hxx>
21 // cmConfigureFileCommand
22 bool cmConfigureFileCommand
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 if(args.size() < 2 )
27 this->SetError("called with incorrect number of arguments, expected 2");
28 return false;
30 this->InputFile = args[0];
31 this->OuputFile = args[1];
32 if ( !this->Makefile->CanIWriteThisFile(this->OuputFile.c_str()) )
34 std::string e = "attempted to configure a file: " + this->OuputFile
35 + " into a source directory.";
36 this->SetError(e.c_str());
37 cmSystemTools::SetFatalErrorOccured();
38 return false;
40 this->CopyOnly = false;
41 this->EscapeQuotes = false;
44 // for CMake 2.0 and earlier CONFIGURE_FILE defaults to the FinalPass,
45 // after 2.0 it only does InitialPass
46 this->Immediate = false;
47 const char* versionValue
48 = this->Makefile->GetDefinition("CMAKE_BACKWARDS_COMPATIBILITY");
49 if (versionValue && atof(versionValue) > 2.0)
51 this->Immediate = true;
55 this->AtOnly = false;
56 for(unsigned int i=2;i < args.size();++i)
58 if(args[i] == "COPYONLY")
60 this->CopyOnly = true;
62 else if(args[i] == "ESCAPE_QUOTES")
64 this->EscapeQuotes = true;
66 else if(args[i] == "@ONLY")
68 this->AtOnly = true;
70 else if(args[i] == "IMMEDIATE")
72 this->Immediate = true;
76 // If we were told to copy the file immediately, then do it on the
77 // first pass (now).
78 if(this->Immediate)
80 if ( !this->ConfigureFile() )
82 this->SetError("Problem configuring file");
83 return false;
87 return true;
90 void cmConfigureFileCommand::FinalPass()
92 if(!this->Immediate)
94 this->ConfigureFile();
98 int cmConfigureFileCommand::ConfigureFile()
100 std::string inFile = this->InputFile;
101 if (!cmSystemTools::FileIsFullPath(inFile.c_str()))
103 inFile = this->Makefile->GetStartDirectory();
104 inFile += "/";
105 inFile += this->InputFile;
107 return this->Makefile->ConfigureFile(inFile.c_str(),
108 this->OuputFile.c_str(),
109 this->CopyOnly,
110 this->AtOnly,
111 this->EscapeQuotes);