2002-01-21 23:30:43 +03:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-01-21 23:30:43 +03:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-24 02:03:27 +04:00
|
|
|
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
|
|
|
|
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
|
2002-01-21 23:30:43 +03:00
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
PURPOSE. See the above copyright notices for more information.
|
|
|
|
|
|
|
|
=========================================================================*/
|
2001-08-29 02:28:31 +04:00
|
|
|
#include "cmListFileCache.h"
|
2003-12-08 21:36:59 +03:00
|
|
|
|
|
|
|
#include "cmListFileLexer.h"
|
2001-08-29 02:28:31 +04:00
|
|
|
#include "cmSystemTools.h"
|
2008-03-06 18:57:59 +03:00
|
|
|
#include "cmMakefile.h"
|
2003-06-23 22:10:12 +04:00
|
|
|
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2001-08-29 02:28:31 +04:00
|
|
|
|
2006-08-01 19:38:42 +04:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
# pragma warn -8060 /* possibly incorrect assignment */
|
|
|
|
#endif
|
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
|
|
|
|
cmListFileFunction& function,
|
|
|
|
const char* filename);
|
|
|
|
|
2008-03-06 18:57:59 +03:00
|
|
|
bool cmListFile::ParseFile(const char* filename,
|
|
|
|
bool topLevel,
|
|
|
|
cmMakefile *mf)
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2006-03-08 18:52:29 +03:00
|
|
|
if(!cmSystemTools::FileExists(filename))
|
2002-04-12 01:02:10 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-04 18:45:11 +04:00
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
// Create the scanner.
|
|
|
|
cmListFileLexer* lexer = cmListFileLexer_New();
|
|
|
|
if(!lexer)
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error("cmListFileCache: error allocating lexer ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the file.
|
2004-08-04 18:45:11 +04:00
|
|
|
if(!cmListFileLexer_SetFileName(lexer, filename))
|
2003-12-08 21:36:59 +03:00
|
|
|
{
|
|
|
|
cmListFileLexer_Delete(lexer);
|
2006-05-12 19:56:09 +04:00
|
|
|
cmSystemTools::Error("cmListFileCache: error can not open file ",
|
|
|
|
filename);
|
2001-08-29 02:28:31 +04:00
|
|
|
return false;
|
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
|
|
|
// Use a simple recursive-descent parser to process the token
|
|
|
|
// stream.
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ModifiedTime = cmSystemTools::ModifiedTime(filename);
|
2003-12-08 21:36:59 +03:00
|
|
|
bool parseError = false;
|
|
|
|
bool haveNewline = true;
|
|
|
|
cmListFileLexer_Token* token;
|
|
|
|
while(!parseError && (token = cmListFileLexer_Scan(lexer)))
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
if(token->type == cmListFileLexer_Token_Newline)
|
2001-08-29 02:28:31 +04:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
haveNewline = true;
|
2001-08-29 02:28:31 +04:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type == cmListFileLexer_Token_Identifier)
|
2001-11-30 00:44:22 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
if(haveNewline)
|
|
|
|
{
|
|
|
|
haveNewline = false;
|
|
|
|
cmListFileFunction inFunction;
|
2006-03-15 19:02:08 +03:00
|
|
|
inFunction.Name = token->text;
|
|
|
|
inFunction.FilePath = filename;
|
|
|
|
inFunction.Line = token->line;
|
2004-08-04 18:45:11 +04:00
|
|
|
if(cmListFileCacheParseFunction(lexer, inFunction, filename))
|
2003-12-08 21:36:59 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->Functions.push_back(inFunction);
|
2003-12-08 21:36:59 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parseError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2004-08-04 18:45:11 +04:00
|
|
|
<< filename << ":" << token->line << ":\n"
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Parse error. Expected a newline, got "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
parseError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2004-08-04 18:45:11 +04:00
|
|
|
<< filename << ":" << token->line << ":\n"
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Parse error. Expected a command name, got "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \""
|
2003-12-08 21:36:59 +03:00
|
|
|
<< token->text << "\".";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
parseError = true;
|
2001-11-30 00:44:22 +03:00
|
|
|
}
|
2001-08-29 02:28:31 +04:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
if (parseError)
|
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
this->ModifiedTime = 0;
|
2003-12-08 21:36:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileLexer_Delete(lexer);
|
|
|
|
|
2008-03-06 18:57:59 +03:00
|
|
|
// do we need a cmake_policy(VERSION call?
|
|
|
|
if(topLevel)
|
|
|
|
{
|
|
|
|
bool hasPolicy = 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_policy" &&
|
|
|
|
i->Arguments.size() &&
|
|
|
|
cmSystemTools::LowerCase(i->Arguments[0].Value) == "version")
|
|
|
|
{
|
|
|
|
hasPolicy = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-07 19:43:47 +03:00
|
|
|
if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required")
|
|
|
|
{
|
|
|
|
hasPolicy = true;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-06 18:57:59 +03:00
|
|
|
}
|
|
|
|
// if no policy command is found this is an error
|
|
|
|
if(!hasPolicy)
|
|
|
|
{
|
|
|
|
switch (mf->GetPolicyStatus(cmPolicies::CMP_0000))
|
|
|
|
{
|
|
|
|
case cmPolicies::WARN:
|
2008-03-07 16:40:36 +03:00
|
|
|
mf->IssueWarning(
|
|
|
|
mf->GetPolicies()->GetPolicyWarning(cmPolicies::CMP_0000)
|
|
|
|
);
|
2008-03-07 23:30:35 +03:00
|
|
|
|
|
|
|
// Implicitly set the version for the user.
|
|
|
|
mf->SetPolicyVersion("2.4");
|
2008-03-06 18:57:59 +03:00
|
|
|
case cmPolicies::OLD:
|
|
|
|
break;
|
|
|
|
default:
|
2008-03-07 16:40:36 +03:00
|
|
|
mf->IssueError(
|
|
|
|
mf->GetPolicies()->GetRequiredPolicyError(cmPolicies::CMP_0000)
|
|
|
|
);
|
2008-03-06 18:57:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(topLevel)
|
2002-12-02 23:30:59 +03:00
|
|
|
{
|
|
|
|
bool hasProject = false;
|
|
|
|
// search for a project command
|
|
|
|
for(std::vector<cmListFileFunction>::iterator i
|
2006-03-15 19:02:08 +03:00
|
|
|
= this->Functions.begin();
|
|
|
|
i != this->Functions.end(); ++i)
|
2002-12-02 23:30:59 +03:00
|
|
|
{
|
2006-03-15 19:02:08 +03:00
|
|
|
if(cmSystemTools::LowerCase(i->Name) == "project")
|
2002-12-02 23:30:59 +03:00
|
|
|
{
|
|
|
|
hasProject = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if no project command is found, add one
|
|
|
|
if(!hasProject)
|
|
|
|
{
|
|
|
|
cmListFileFunction project;
|
2006-03-15 19:02:08 +03:00
|
|
|
project.Name = "PROJECT";
|
2004-08-04 18:45:11 +04:00
|
|
|
cmListFileArgument prj("Project", false, filename, 0);
|
2006-03-15 19:02:08 +03:00
|
|
|
project.Arguments.push_back(prj);
|
|
|
|
this->Functions.insert(this->Functions.begin(),project);
|
2002-12-02 23:30:59 +03:00
|
|
|
}
|
|
|
|
}
|
2007-11-19 21:42:05 +03:00
|
|
|
if(parseError)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2001-08-29 02:28:31 +04:00
|
|
|
return true;
|
|
|
|
}
|
2002-09-19 22:34:15 +04:00
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
|
|
|
|
cmListFileFunction& function,
|
|
|
|
const char* filename)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
// Command name has already been parsed. Read the left paren.
|
|
|
|
cmListFileLexer_Token* token;
|
|
|
|
if(!(token = cmListFileLexer_Scan(lexer)))
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
|
|
|
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n"
|
|
|
|
<< "Parse error. Function missing opening \"(\".";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
return false;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
if(token->type != cmListFileLexer_Token_ParenLeft)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
|
|
|
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n"
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Parse error. Expected \"(\", got "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 21:36:59 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-12 02:13:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
|
|
|
|
// Arguments.
|
2004-09-01 02:51:35 +04:00
|
|
|
unsigned long lastLine = cmListFileLexer_GetCurrentLine(lexer);
|
2003-12-08 21:36:59 +03:00
|
|
|
while((token = cmListFileLexer_Scan(lexer)))
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
if(token->type == cmListFileLexer_Token_ParenRight)
|
2003-07-10 01:17:34 +04:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
return true;
|
2003-07-10 01:17:34 +04:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type == cmListFileLexer_Token_Identifier ||
|
|
|
|
token->type == cmListFileLexer_Token_ArgumentUnquoted)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2005-06-17 23:50:08 +04:00
|
|
|
cmListFileArgument a(token->text,
|
2004-08-04 18:45:11 +04:00
|
|
|
false, filename, token->line);
|
2006-03-15 19:02:08 +03:00
|
|
|
function.Arguments.push_back(a);
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type == cmListFileLexer_Token_ArgumentQuoted)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2005-06-17 23:50:08 +04:00
|
|
|
cmListFileArgument a(token->text,
|
2004-08-04 18:45:11 +04:00
|
|
|
true, filename, token->line);
|
2006-03-15 19:02:08 +03:00
|
|
|
function.Arguments.push_back(a);
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
2003-12-08 21:36:59 +03:00
|
|
|
else if(token->type != cmListFileLexer_Token_Newline)
|
2002-12-12 02:13:33 +03:00
|
|
|
{
|
2003-12-08 21:36:59 +03:00
|
|
|
// Error.
|
2002-12-12 19:36:28 +03:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2006-05-12 19:56:09 +04:00
|
|
|
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer)
|
|
|
|
<< ":\n"
|
2003-12-08 21:36:59 +03:00
|
|
|
<< "Parse error. Function missing ending \")\". "
|
2004-09-01 02:39:42 +04:00
|
|
|
<< "Instead found "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \"" << token->text << "\".";
|
2002-12-12 19:36:28 +03:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-12 02:13:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
2004-09-01 02:51:35 +04:00
|
|
|
lastLine = cmListFileLexer_GetCurrentLine(lexer);
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2004-09-01 02:51:35 +04:00
|
|
|
<< filename << ":" << lastLine << ":\n"
|
2003-12-08 21:36:59 +03:00
|
|
|
<< "Parse error. Function missing ending \")\". "
|
|
|
|
<< "End of file reached.";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-12 02:13:33 +03:00
|
|
|
|
2003-12-08 21:36:59 +03:00
|
|
|
return false;
|
2002-12-12 02:13:33 +03:00
|
|
|
}
|