cmake/Source/cmConfigureFileCommand.cxx

115 lines
3.5 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmConfigureFileCommand.h"
2017-04-14 19:02:05 +02:00
#include <sstream>
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include "cmake.h"
class cmExecutionStatus;
// cmConfigureFileCommand
2016-07-09 11:21:54 +02:00
bool cmConfigureFileCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
this->SetError("called with incorrect number of arguments, expected 2");
return false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2017-07-20 19:35:53 +02:00
std::string const& inFile = args[0];
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileIsFullPath(inFile)) {
2015-08-17 11:37:30 +02:00
this->InputFile = this->Makefile->GetCurrentSourceDirectory();
2009-10-04 10:30:41 +03:00
this->InputFile += "/";
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
this->InputFile += inFile;
// If the input location is a directory, error out.
2016-07-09 11:21:54 +02:00
if (cmSystemTools::FileIsDirectory(this->InputFile)) {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
/* clang-format off */
2009-10-04 10:30:41 +03:00
e << "input location\n"
<< " " << this->InputFile << "\n"
<< "is a directory but a file was expected.";
2016-07-09 11:21:54 +02:00
/* clang-format on */
2015-04-27 22:25:09 +02:00
this->SetError(e.str());
2009-10-04 10:30:41 +03:00
return false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2017-07-20 19:35:53 +02:00
std::string const& outFile = args[1];
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileIsFullPath(outFile)) {
2015-08-17 11:37:30 +02:00
this->OutputFile = this->Makefile->GetCurrentBinaryDirectory();
2009-10-04 10:30:41 +03:00
this->OutputFile += "/";
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
this->OutputFile += outFile;
// If the output location is already a directory put the file in it.
2016-07-09 11:21:54 +02:00
if (cmSystemTools::FileIsDirectory(this->OutputFile)) {
2009-10-04 10:30:41 +03:00
this->OutputFile += "/";
this->OutputFile += cmSystemTools::GetFilenameName(inFile);
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
if (!this->Makefile->CanIWriteThisFile(this->OutputFile.c_str())) {
std::string e = "attempted to configure a file: " + this->OutputFile +
" into a source directory.";
2015-04-27 22:25:09 +02:00
this->SetError(e);
cmSystemTools::SetFatalErrorOccured();
return false;
2016-07-09 11:21:54 +02:00
}
2012-02-18 12:40:36 +02:00
std::string errorMessage;
2016-07-09 11:21:54 +02:00
if (!this->NewLineStyle.ReadFromArguments(args, errorMessage)) {
2015-04-27 22:25:09 +02:00
this->SetError(errorMessage);
2012-02-18 12:40:36 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
this->CopyOnly = false;
this->EscapeQuotes = false;
2015-04-27 22:25:09 +02:00
std::string unknown_args;
this->AtOnly = false;
2016-07-09 11:21:54 +02:00
for (unsigned int i = 2; i < args.size(); ++i) {
if (args[i] == "COPYONLY") {
this->CopyOnly = true;
2016-07-09 11:21:54 +02:00
if (this->NewLineStyle.IsValid()) {
2012-02-18 12:40:36 +02:00
this->SetError("COPYONLY could not be used in combination "
"with NEWLINE_STYLE");
return false;
}
2016-07-09 11:21:54 +02:00
} else if (args[i] == "ESCAPE_QUOTES") {
this->EscapeQuotes = true;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "@ONLY") {
this->AtOnly = true;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "IMMEDIATE") {
2014-08-03 19:52:23 +02:00
/* Ignore legacy option. */
2016-07-09 11:21:54 +02:00
} else if (args[i] == "NEWLINE_STYLE" || args[i] == "LF" ||
args[i] == "UNIX" || args[i] == "CRLF" || args[i] == "WIN32" ||
args[i] == "DOS") {
2015-04-27 22:25:09 +02:00
/* Options handled by NewLineStyle member above. */
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
unknown_args += " ";
unknown_args += args[i];
unknown_args += "\n";
}
2016-07-09 11:21:54 +02:00
}
if (!unknown_args.empty()) {
2015-04-27 22:25:09 +02:00
std::string msg = "configure_file called with unknown argument(s):\n";
msg += unknown_args;
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg);
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2016-07-09 11:21:54 +02:00
if (!this->ConfigureFile()) {
2014-08-03 19:52:23 +02:00
this->SetError("Problem configuring file");
return false;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
return true;
}
int cmConfigureFileCommand::ConfigureFile()
{
2009-10-04 10:30:41 +03:00
return this->Makefile->ConfigureFile(
2016-07-09 11:21:54 +02:00
this->InputFile.c_str(), this->OutputFile.c_str(), this->CopyOnly,
this->AtOnly, this->EscapeQuotes, this->NewLineStyle);
}