1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmConfigureFileCommand.h"
14 #include <cmsys/RegularExpression.hxx>
16 // cmConfigureFileCommand
17 bool cmConfigureFileCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
22 this->SetError("called with incorrect number of arguments, expected 2");
26 const char* inFile = args[0].c_str();
27 if(!cmSystemTools::FileIsFullPath(inFile))
29 this->InputFile = this->Makefile->GetCurrentDirectory();
30 this->InputFile += "/";
32 this->InputFile += inFile;
34 // If the input location is a directory, error out.
35 if(cmSystemTools::FileIsDirectory(this->InputFile.c_str()))
38 e << "input location\n"
39 << " " << this->InputFile << "\n"
40 << "is a directory but a file was expected.";
41 this->SetError(e.str().c_str());
45 const char* outFile = args[1].c_str();
46 if(!cmSystemTools::FileIsFullPath(outFile))
48 this->OutputFile = this->Makefile->GetCurrentOutputDirectory();
49 this->OutputFile += "/";
51 this->OutputFile += outFile;
53 // If the output location is already a directory put the file in it.
54 if(cmSystemTools::FileIsDirectory(this->OutputFile.c_str()))
56 this->OutputFile += "/";
57 this->OutputFile += cmSystemTools::GetFilenameName(inFile);
60 if ( !this->Makefile->CanIWriteThisFile(this->OutputFile.c_str()) )
62 std::string e = "attempted to configure a file: " + this->OutputFile
63 + " into a source directory.";
64 this->SetError(e.c_str());
65 cmSystemTools::SetFatalErrorOccured();
68 std::string errorMessage;
69 if (!this->NewLineStyle.ReadFromArguments(args, errorMessage))
71 this->SetError(errorMessage.c_str());
74 this->CopyOnly = false;
75 this->EscapeQuotes = false;
77 // for CMake 2.0 and earlier CONFIGURE_FILE defaults to the FinalPass,
78 // after 2.0 it only does InitialPass
79 this->Immediate = !this->Makefile->NeedBackwardsCompatibility(2,0);
82 for(unsigned int i=2;i < args.size();++i)
84 if(args[i] == "COPYONLY")
86 this->CopyOnly = true;
87 if (this->NewLineStyle.IsValid())
89 this->SetError("COPYONLY could not be used in combination "
90 "with NEWLINE_STYLE");
94 else if(args[i] == "ESCAPE_QUOTES")
96 this->EscapeQuotes = true;
98 else if(args[i] == "@ONLY")
102 else if(args[i] == "IMMEDIATE")
104 this->Immediate = true;
108 // If we were told to copy the file immediately, then do it on the
112 if ( !this->ConfigureFile() )
114 this->SetError("Problem configuring file");
122 void cmConfigureFileCommand::FinalPass()
126 this->ConfigureFile();
130 int cmConfigureFileCommand::ConfigureFile()
132 return this->Makefile->ConfigureFile(
133 this->InputFile.c_str(),
134 this->OutputFile.c_str(),