summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2016-01-28 21:10:26 (GMT)
committerStephen Kelly <steveire@gmail.com>2016-06-13 18:19:16 (GMT)
commit905e738ffeb1ec1b5d1a376b99e300a8787f7255 (patch)
treef67f157fd02b911636f4cb35fdac07fbce967768 /Source
parent0a9094cd1017057d3c5141fdacdc6a89fb14acfc (diff)
downloadCMake-905e738ffeb1ec1b5d1a376b99e300a8787f7255.zip
CMake-905e738ffeb1ec1b5d1a376b99e300a8787f7255.tar.gz
CMake-905e738ffeb1ec1b5d1a376b99e300a8787f7255.tar.bz2
Parser: Out-of-line conditional code to cmMakefile
Simplify parser API.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmListFileCache.cxx72
-rw-r--r--Source/cmListFileCache.h2
-rw-r--r--Source/cmMakefile.cxx79
3 files changed, 77 insertions, 76 deletions
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 4df542f..4460418 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -118,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)) {
@@ -132,76 +132,6 @@ 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");
- }
- }
- 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);
- }
- }
return !parseError;
}
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h
index d72c360..f3e6f70 100644
--- a/Source/cmListFileCache.h
+++ b/Source/cmListFileCache.h
@@ -158,7 +158,7 @@ private:
struct cmListFile
{
- bool ParseFile(const char* path, bool topLevel, cmMakefile* mf);
+ bool ParseFile(const char* path, cmMakefile* mf);
std::vector<cmListFileFunction> Functions;
};
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index c9192fd..95ca0e2 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -426,7 +426,7 @@ bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope)
IncludeScope incScope(this, filenametoread, noPolicyScope);
cmListFile listFile;
- if (!listFile.ParseFile(filenametoread.c_str(), false, this)) {
+ if (!listFile.ParseFile(filenametoread.c_str(), this)) {
return false;
}
@@ -475,7 +475,7 @@ bool cmMakefile::ReadListFile(const char* filename)
ListFileScope scope(this, filenametoread);
cmListFile listFile;
- if (!listFile.ParseFile(filenametoread.c_str(), false, this)) {
+ if (!listFile.ParseFile(filenametoread.c_str(), this)) {
return false;
}
@@ -1423,10 +1423,81 @@ void cmMakefile::Configure()
this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str());
cmListFile listFile;
- if (!listFile.ParseFile(currentStart.c_str(), this->IsRootMakefile(),
- this)) {
+ if (!listFile.ParseFile(currentStart.c_str(), this)) {
return;
}
+ if (this->IsRootMakefile()) {
+ bool hasVersion = false;
+ // search for the right policy command
+ for (std::vector<cmListFileFunction>::iterator i =
+ listFile.Functions.begin();
+ i != listFile.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 (listFile.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 =
+ listFile.Functions.begin();
+ i != listFile.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.
+ this->SetCheckCMP0000(true);
+
+ // Implicitly set the version for the user.
+ this->SetPolicyVersion("2.4");
+ }
+ }
+ bool hasProject = false;
+ // search for a project command
+ for (std::vector<cmListFileFunction>::iterator i =
+ listFile.Functions.begin();
+ i != listFile.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);
+ listFile.Functions.insert(listFile.Functions.begin(), project);
+ }
+ }
+
this->ReadListFile(listFile, currentStart);
if (cmSystemTools::GetFatalErrorOccured()) {
scope.Quiet();