ENH: add submit via cp mode
[cmake.git] / Source / cmConfigureFileCommand.cxx
blob3c93af9d062a117aaea6915c45df3b5aef79386f
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmConfigureFileCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-03-07 20:30:33 $
7 Version: $Revision: 1.34 $
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;
43 // for CMake 2.0 and earlier CONFIGURE_FILE defaults to the FinalPass,
44 // after 2.0 it only does InitialPass
45 this->Immediate = !this->Makefile->NeedBackwardsCompatibility(2,0);
47 this->AtOnly = false;
48 for(unsigned int i=2;i < args.size();++i)
50 if(args[i] == "COPYONLY")
52 this->CopyOnly = true;
54 else if(args[i] == "ESCAPE_QUOTES")
56 this->EscapeQuotes = true;
58 else if(args[i] == "@ONLY")
60 this->AtOnly = true;
62 else if(args[i] == "IMMEDIATE")
64 this->Immediate = true;
68 // If we were told to copy the file immediately, then do it on the
69 // first pass (now).
70 if(this->Immediate)
72 if ( !this->ConfigureFile() )
74 this->SetError("Problem configuring file");
75 return false;
79 return true;
82 void cmConfigureFileCommand::FinalPass()
84 if(!this->Immediate)
86 this->ConfigureFile();
90 int cmConfigureFileCommand::ConfigureFile()
92 std::string inFile = this->InputFile;
93 if (!cmSystemTools::FileIsFullPath(inFile.c_str()))
95 inFile = this->Makefile->GetStartDirectory();
96 inFile += "/";
97 inFile += this->InputFile;
99 return this->Makefile->ConfigureFile(inFile.c_str(),
100 this->OuputFile.c_str(),
101 this->CopyOnly,
102 this->AtOnly,
103 this->EscapeQuotes);