2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-04-27 18:25:42 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-04-27 18:25:42 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-05-07 22:11:16 +00:00
|
|
|
#include "cmConfigureFileCommand.h"
|
2001-04-27 18:25:42 +00:00
|
|
|
|
2003-06-23 18:10:12 +00:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2001-05-07 22:11:16 +00:00
|
|
|
// cmConfigureFileCommand
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-04-27 18:25:42 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
if (args.size() < 2) {
|
2001-04-27 18:25:42 +00:00
|
|
|
this->SetError("called with incorrect number of arguments, expected 2");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-16 19:09:29 +00:00
|
|
|
|
|
|
|
const char* inFile = args[0].c_str();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::FileIsFullPath(inFile)) {
|
2015-04-16 19:17:41 +00:00
|
|
|
this->InputFile = this->Makefile->GetCurrentSourceDirectory();
|
2009-09-16 19:09:29 +00:00
|
|
|
this->InputFile += "/";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-16 19:09:29 +00:00
|
|
|
this->InputFile += inFile;
|
|
|
|
|
2009-09-16 19:09:42 +00:00
|
|
|
// If the input location is a directory, error out.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileIsDirectory(this->InputFile)) {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2016-05-06 18:19:04 +00:00
|
|
|
/* clang-format off */
|
2009-09-16 19:09:42 +00:00
|
|
|
e << "input location\n"
|
|
|
|
<< " " << this->InputFile << "\n"
|
|
|
|
<< "is a directory but a file was expected.";
|
2016-05-06 18:19:04 +00:00
|
|
|
/* clang-format on */
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e.str());
|
2009-09-16 19:09:42 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-16 19:09:42 +00:00
|
|
|
|
2009-09-16 19:09:29 +00:00
|
|
|
const char* outFile = args[1].c_str();
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!cmSystemTools::FileIsFullPath(outFile)) {
|
2015-04-16 19:33:09 +00:00
|
|
|
this->OutputFile = this->Makefile->GetCurrentBinaryDirectory();
|
2009-09-16 19:09:29 +00:00
|
|
|
this->OutputFile += "/";
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-16 19:09:29 +00:00
|
|
|
this->OutputFile += outFile;
|
|
|
|
|
2009-09-16 19:09:42 +00:00
|
|
|
// If the output location is already a directory put the file in it.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmSystemTools::FileIsDirectory(this->OutputFile)) {
|
2009-09-16 19:09:42 +00:00
|
|
|
this->OutputFile += "/";
|
|
|
|
this->OutputFile += cmSystemTools::GetFilenameName(inFile);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2009-09-16 19:09:42 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->Makefile->CanIWriteThisFile(this->OutputFile.c_str())) {
|
|
|
|
std::string e = "attempted to configure a file: " + this->OutputFile +
|
|
|
|
" into a source directory.";
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e);
|
2006-03-22 19:40:36 +00:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2011-11-20 13:04:11 +00:00
|
|
|
std::string errorMessage;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->NewLineStyle.ReadFromArguments(args, errorMessage)) {
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(errorMessage);
|
2011-11-20 13:04:11 +00:00
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-15 16:02:08 +00:00
|
|
|
this->CopyOnly = false;
|
|
|
|
this->EscapeQuotes = false;
|
2005-06-13 13:33:38 +00:00
|
|
|
|
2014-10-31 17:07:21 +00:00
|
|
|
std::string unknown_args;
|
2006-03-15 16:02:08 +00:00
|
|
|
this->AtOnly = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (unsigned int i = 2; i < args.size(); ++i) {
|
|
|
|
if (args[i] == "COPYONLY") {
|
2006-03-15 16:02:08 +00:00
|
|
|
this->CopyOnly = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (this->NewLineStyle.IsValid()) {
|
2011-11-20 13:04:11 +00:00
|
|
|
this->SetError("COPYONLY could not be used in combination "
|
|
|
|
"with NEWLINE_STYLE");
|
|
|
|
return false;
|
2001-05-09 13:52:21 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "ESCAPE_QUOTES") {
|
2006-03-15 16:02:08 +00:00
|
|
|
this->EscapeQuotes = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "@ONLY") {
|
2006-03-15 16:02:08 +00:00
|
|
|
this->AtOnly = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "IMMEDIATE") {
|
2013-10-18 15:25:49 +00:00
|
|
|
/* Ignore legacy option. */
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "NEWLINE_STYLE" || args[i] == "LF" ||
|
|
|
|
args[i] == "UNIX" || args[i] == "CRLF" || args[i] == "WIN32" ||
|
|
|
|
args[i] == "DOS") {
|
2015-03-09 12:38:21 +00:00
|
|
|
/* Options handled by NewLineStyle member above. */
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2014-10-31 17:07:21 +00:00
|
|
|
unknown_args += " ";
|
|
|
|
unknown_args += args[i];
|
|
|
|
unknown_args += "\n";
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!unknown_args.empty()) {
|
2014-10-31 17:07:21 +00:00
|
|
|
std::string msg = "configure_file called with unknown argument(s):\n";
|
|
|
|
msg += unknown_args;
|
|
|
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->ConfigureFile()) {
|
2013-10-18 15:25:49 +00:00
|
|
|
this->SetError("Problem configuring file");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2012-08-13 17:42:58 +00:00
|
|
|
|
2001-04-27 18:25:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-03-28 21:00:57 +00:00
|
|
|
int cmConfigureFileCommand::ConfigureFile()
|
2001-04-27 18:25:42 +00:00
|
|
|
{
|
2009-09-16 19:09:29 +00:00
|
|
|
return this->Makefile->ConfigureFile(
|
2016-05-16 14:34:04 +00:00
|
|
|
this->InputFile.c_str(), this->OutputFile.c_str(), this->CopyOnly,
|
|
|
|
this->AtOnly, this->EscapeQuotes, this->NewLineStyle);
|
2001-04-27 18:25:42 +00:00
|
|
|
}
|