summaryrefslogtreecommitdiffstats
path: root/Source/cmListFileCache.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmListFileCache.cxx')
-rw-r--r--Source/cmListFileCache.cxx101
1 files changed, 14 insertions, 87 deletions
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index f47e9b6..28b3781 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -23,6 +23,7 @@ struct cmListFileParser
{
cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename);
~cmListFileParser();
+ void IssueFileOpenError(std::string const& text) const;
bool ParseFile();
bool ParseFunction(const char* name, long line);
bool AddArgument(cmListFileLexer_Token* token,
@@ -54,23 +55,25 @@ cmListFileParser::~cmListFileParser()
cmListFileLexer_Delete(this->Lexer);
}
+void cmListFileParser::IssueFileOpenError(const std::string& text) const
+{
+ this->Makefile->IssueMessage(cmake::FATAL_ERROR, text);
+}
+
bool cmListFileParser::ParseFile()
{
// Open the file.
cmListFileLexer_BOM bom;
if (!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) {
- cmSystemTools::Error("cmListFileCache: error can not open file ",
- this->FileName);
+ this->IssueFileOpenError("cmListFileCache: error can not open file.");
return false;
}
// Verify the Byte-Order-Mark, if any.
if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) {
- cmListFileLexer_SetFileName(this->Lexer, 0, 0);
- std::ostringstream m;
- m << "File\n " << this->FileName << "\n"
- << "starts with a Byte-Order-Mark that is not UTF-8.";
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str());
+ cmListFileLexer_SetFileName(this->Lexer, CM_NULLPTR, CM_NULLPTR);
+ this->IssueFileOpenError(
+ "File starts with a Byte-Order-Mark that is not UTF-8.");
return false;
}
@@ -115,7 +118,7 @@ bool cmListFileParser::ParseFile()
return true;
}
-bool cmListFile::ParseFile(const char* filename, bool topLevel, cmMakefile* mf)
+bool cmListFile::ParseFile(const char* filename, cmMakefile* mf)
{
if (!cmSystemTools::FileExists(filename) ||
cmSystemTools::FileIsDirectory(filename)) {
@@ -129,83 +132,7 @@ bool cmListFile::ParseFile(const char* filename, bool topLevel, cmMakefile* mf)
parseError = !parser.ParseFile();
}
- // do we need a cmake_policy(VERSION call?
- if (topLevel) {
- bool hasVersion = false;
- // search for the right policy command
- for (std::vector<cmListFileFunction>::iterator i = this->Functions.begin();
- i != this->Functions.end(); ++i) {
- if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required") {
- hasVersion = true;
- break;
- }
- }
- // if no policy command is found this is an error if they use any
- // non advanced functions or a lot of functions
- if (!hasVersion) {
- bool isProblem = true;
- if (this->Functions.size() < 30) {
- // the list of simple commands DO NOT ADD TO THIS LIST!!!!!
- // these commands must have backwards compatibility forever and
- // and that is a lot longer than your tiny mind can comprehend mortal
- std::set<std::string> allowedCommands;
- allowedCommands.insert("project");
- allowedCommands.insert("set");
- allowedCommands.insert("if");
- allowedCommands.insert("endif");
- allowedCommands.insert("else");
- allowedCommands.insert("elseif");
- allowedCommands.insert("add_executable");
- allowedCommands.insert("add_library");
- allowedCommands.insert("target_link_libraries");
- allowedCommands.insert("option");
- allowedCommands.insert("message");
- isProblem = false;
- for (std::vector<cmListFileFunction>::iterator i =
- this->Functions.begin();
- i != this->Functions.end(); ++i) {
- std::string name = cmSystemTools::LowerCase(i->Name);
- if (allowedCommands.find(name) == allowedCommands.end()) {
- isProblem = true;
- break;
- }
- }
- }
-
- if (isProblem) {
- // Tell the top level cmMakefile to diagnose
- // this violation of CMP0000.
- mf->SetCheckCMP0000(true);
-
- // Implicitly set the version for the user.
- mf->SetPolicyVersion("2.4");
- }
- }
- }
-
- if (topLevel) {
- bool hasProject = false;
- // search for a project command
- for (std::vector<cmListFileFunction>::iterator i = this->Functions.begin();
- i != this->Functions.end(); ++i) {
- if (cmSystemTools::LowerCase(i->Name) == "project") {
- hasProject = true;
- break;
- }
- }
- // if no project command is found, add one
- if (!hasProject) {
- cmListFileFunction project;
- project.Name = "PROJECT";
- cmListFileArgument prj("Project", cmListFileArgument::Unquoted, 0);
- project.Arguments.push_back(prj);
- this->Functions.insert(this->Functions.begin(), project);
- }
- }
- if (parseError) {
- return false;
- }
- return true;
+ return !parseError;
}
bool cmListFileParser::ParseFunction(const char* name, long line)
@@ -387,13 +314,13 @@ cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot bottom, Entry* cur)
cmListFileBacktrace::cmListFileBacktrace()
: Bottom()
- , Cur(0)
+ , Cur(CM_NULLPTR)
{
}
cmListFileBacktrace::cmListFileBacktrace(cmState::Snapshot snapshot)
: Bottom(snapshot.GetCallStackBottom())
- , Cur(0)
+ , Cur(CM_NULLPTR)
{
}