2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-05-08 02:11:16 +04:00
|
|
|
#include "cmConfigureFileCommand.h"
|
2001-04-27 22:25:42 +04:00
|
|
|
|
2003-06-23 22:10:12 +04:00
|
|
|
#include <cmsys/RegularExpression.hxx>
|
|
|
|
|
2001-05-08 02:11:16 +04:00
|
|
|
// cmConfigureFileCommand
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2001-04-27 22:25:42 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < 2) {
|
2001-04-27 22:25:42 +04:00
|
|
|
this->SetError("called with incorrect number of arguments, expected 2");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-16 23:09:29 +04:00
|
|
|
|
|
|
|
const char* inFile = args[0].c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileIsFullPath(inFile)) {
|
2015-04-16 22:17:41 +03:00
|
|
|
this->InputFile = this->Makefile->GetCurrentSourceDirectory();
|
2009-09-16 23:09:29 +04:00
|
|
|
this->InputFile += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-16 23:09:29 +04:00
|
|
|
this->InputFile += inFile;
|
|
|
|
|
2009-09-16 23:09:42 +04:00
|
|
|
// If the input location is a directory, error out.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(this->InputFile)) {
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format off */
|
2009-09-16 23:09:42 +04:00
|
|
|
e << "input location\n"
|
|
|
|
<< " " << this->InputFile << "\n"
|
|
|
|
<< "is a directory but a file was expected.";
|
2016-05-06 21:19:04 +03:00
|
|
|
/* clang-format on */
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e.str());
|
2009-09-16 23:09:42 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-16 23:09:42 +04:00
|
|
|
|
2009-09-16 23:09:29 +04:00
|
|
|
const char* outFile = args[1].c_str();
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cmSystemTools::FileIsFullPath(outFile)) {
|
2015-04-16 22:33:09 +03:00
|
|
|
this->OutputFile = this->Makefile->GetCurrentBinaryDirectory();
|
2009-09-16 23:09:29 +04:00
|
|
|
this->OutputFile += "/";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-16 23:09:29 +04:00
|
|
|
this->OutputFile += outFile;
|
|
|
|
|
2009-09-16 23:09:42 +04:00
|
|
|
// If the output location is already a directory put the file in it.
|
2016-05-16 17:34:04 +03:00
|
|
|
if (cmSystemTools::FileIsDirectory(this->OutputFile)) {
|
2009-09-16 23:09:42 +04:00
|
|
|
this->OutputFile += "/";
|
|
|
|
this->OutputFile += cmSystemTools::GetFilenameName(inFile);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2009-09-16 23:09:42 +04:00
|
|
|
|
2016-05-16 17:34:04 +03: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-11 03:04:11 +04:00
|
|
|
this->SetError(e);
|
2006-03-22 22:40:36 +03:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2011-11-20 17:04:11 +04:00
|
|
|
std::string errorMessage;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->NewLineStyle.ReadFromArguments(args, errorMessage)) {
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(errorMessage);
|
2011-11-20 17:04:11 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2006-03-15 19:02:08 +03:00
|
|
|
this->CopyOnly = false;
|
|
|
|
this->EscapeQuotes = false;
|
2005-06-13 17:33:38 +04:00
|
|
|
|
2014-10-31 20:07:21 +03:00
|
|
|
std::string unknown_args;
|
2006-03-15 19:02:08 +03:00
|
|
|
this->AtOnly = false;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (unsigned int i = 2; i < args.size(); ++i) {
|
|
|
|
if (args[i] == "COPYONLY") {
|
2006-03-15 19:02:08 +03:00
|
|
|
this->CopyOnly = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->NewLineStyle.IsValid()) {
|
2011-11-20 17:04:11 +04:00
|
|
|
this->SetError("COPYONLY could not be used in combination "
|
|
|
|
"with NEWLINE_STYLE");
|
|
|
|
return false;
|
2001-05-09 17:52:21 +04:00
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "ESCAPE_QUOTES") {
|
2006-03-15 19:02:08 +03:00
|
|
|
this->EscapeQuotes = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "@ONLY") {
|
2006-03-15 19:02:08 +03:00
|
|
|
this->AtOnly = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (args[i] == "IMMEDIATE") {
|
2013-10-18 19:25:49 +04:00
|
|
|
/* Ignore legacy option. */
|
2016-05-16 17:34:04 +03: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 15:38:21 +03:00
|
|
|
/* Options handled by NewLineStyle member above. */
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2014-10-31 20:07:21 +03:00
|
|
|
unknown_args += " ";
|
|
|
|
unknown_args += args[i];
|
|
|
|
unknown_args += "\n";
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (!unknown_args.empty()) {
|
2014-10-31 20:07:21 +03: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 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->ConfigureFile()) {
|
2013-10-18 19:25:49 +04:00
|
|
|
this->SetError("Problem configuring file");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-08-13 21:42:58 +04:00
|
|
|
|
2001-04-27 22:25:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-03-29 01:00:57 +04:00
|
|
|
int cmConfigureFileCommand::ConfigureFile()
|
2001-04-27 22:25:42 +04:00
|
|
|
{
|
2009-09-16 23:09:29 +04:00
|
|
|
return this->Makefile->ConfigureFile(
|
2016-05-16 17:34:04 +03:00
|
|
|
this->InputFile.c_str(), this->OutputFile.c_str(), this->CopyOnly,
|
|
|
|
this->AtOnly, this->EscapeQuotes, this->NewLineStyle);
|
2001-04-27 22:25:42 +04:00
|
|
|
}
|