2002-01-21 20:30:43 +00:00
|
|
|
/*=========================================================================
|
|
|
|
|
2002-10-23 22:03:27 +00:00
|
|
|
Program: CMake - Cross-Platform Makefile Generator
|
2002-01-21 20:30:43 +00:00
|
|
|
Module: $RCSfile$
|
|
|
|
Language: C++
|
|
|
|
Date: $Date$
|
|
|
|
Version: $Revision$
|
|
|
|
|
2002-10-23 22:03:27 +00: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 20:30:43 +00: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-28 22:28:31 +00:00
|
|
|
#include "cmListFileCache.h"
|
2003-12-08 18:36:59 +00:00
|
|
|
|
|
|
|
#include "cmListFileLexer.h"
|
2001-08-28 22:28:31 +00:00
|
|
|
#include "cmSystemTools.h"
|
2008-03-06 15:57:59 +00:00
|
|
|
#include "cmMakefile.h"
|
2008-03-19 19:18:21 +00:00
|
|
|
#include "cmVersion.h"
|
2003-06-23 18:10:12 +00:00
|
|
|
|
|
|
|
#include <cmsys/RegularExpression.hxx>
|
2001-08-28 22:28:31 +00:00
|
|
|
|
2006-08-01 15:38:42 +00:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
# pragma warn -8060 /* possibly incorrect assignment */
|
|
|
|
#endif
|
|
|
|
|
2003-12-08 18:36:59 +00:00
|
|
|
bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
|
|
|
|
cmListFileFunction& function,
|
|
|
|
const char* filename);
|
|
|
|
|
2008-03-06 15:57:59 +00:00
|
|
|
bool cmListFile::ParseFile(const char* filename,
|
|
|
|
bool topLevel,
|
|
|
|
cmMakefile *mf)
|
2001-08-28 22:28:31 +00:00
|
|
|
{
|
2006-03-08 15:52:29 +00:00
|
|
|
if(!cmSystemTools::FileExists(filename))
|
2002-04-11 21:02:10 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-04 14:45:11 +00:00
|
|
|
|
2003-12-08 18:36:59 +00:00
|
|
|
// Create the scanner.
|
|
|
|
cmListFileLexer* lexer = cmListFileLexer_New();
|
|
|
|
if(!lexer)
|
2001-08-28 22:28:31 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
cmSystemTools::Error("cmListFileCache: error allocating lexer ");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open the file.
|
2004-08-04 14:45:11 +00:00
|
|
|
if(!cmListFileLexer_SetFileName(lexer, filename))
|
2003-12-08 18:36:59 +00:00
|
|
|
{
|
|
|
|
cmListFileLexer_Delete(lexer);
|
2006-05-12 15:56:09 +00:00
|
|
|
cmSystemTools::Error("cmListFileCache: error can not open file ",
|
|
|
|
filename);
|
2001-08-28 22:28:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
|
|
|
|
// Use a simple recursive-descent parser to process the token
|
|
|
|
// stream.
|
2006-03-15 16:02:08 +00:00
|
|
|
this->ModifiedTime = cmSystemTools::ModifiedTime(filename);
|
2003-12-08 18:36:59 +00:00
|
|
|
bool parseError = false;
|
|
|
|
bool haveNewline = true;
|
|
|
|
cmListFileLexer_Token* token;
|
|
|
|
while(!parseError && (token = cmListFileLexer_Scan(lexer)))
|
2001-08-28 22:28:31 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
if(token->type == cmListFileLexer_Token_Newline)
|
2001-08-28 22:28:31 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
haveNewline = true;
|
2001-08-28 22:28:31 +00:00
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
else if(token->type == cmListFileLexer_Token_Identifier)
|
2001-11-29 21:44:22 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
if(haveNewline)
|
|
|
|
{
|
|
|
|
haveNewline = false;
|
|
|
|
cmListFileFunction inFunction;
|
2006-03-15 16:02:08 +00:00
|
|
|
inFunction.Name = token->text;
|
|
|
|
inFunction.FilePath = filename;
|
|
|
|
inFunction.Line = token->line;
|
2004-08-04 14:45:11 +00:00
|
|
|
if(cmListFileCacheParseFunction(lexer, inFunction, filename))
|
2003-12-08 18:36:59 +00:00
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->Functions.push_back(inFunction);
|
2003-12-08 18:36:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parseError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2004-08-04 14:45:11 +00:00
|
|
|
<< filename << ":" << token->line << ":\n"
|
2004-08-31 22:39:42 +00:00
|
|
|
<< "Parse error. Expected a newline, got "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 18:36:59 +00:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
parseError = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2004-08-04 14:45:11 +00:00
|
|
|
<< filename << ":" << token->line << ":\n"
|
2004-08-31 22:39:42 +00:00
|
|
|
<< "Parse error. Expected a command name, got "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \""
|
2003-12-08 18:36:59 +00:00
|
|
|
<< token->text << "\".";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
|
|
|
parseError = true;
|
2001-11-29 21:44:22 +00:00
|
|
|
}
|
2001-08-28 22:28:31 +00:00
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
if (parseError)
|
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
this->ModifiedTime = 0;
|
2003-12-08 18:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmListFileLexer_Delete(lexer);
|
|
|
|
|
2008-03-06 15:57:59 +00:00
|
|
|
// do we need a cmake_policy(VERSION call?
|
|
|
|
if(topLevel)
|
|
|
|
{
|
2008-03-19 19:18:21 +00:00
|
|
|
bool hasVersion = false;
|
2008-03-06 15:57:59 +00:00
|
|
|
// search for the right policy command
|
|
|
|
for(std::vector<cmListFileFunction>::iterator i
|
|
|
|
= this->Functions.begin();
|
|
|
|
i != this->Functions.end(); ++i)
|
|
|
|
{
|
2008-03-07 16:43:47 +00:00
|
|
|
if (cmSystemTools::LowerCase(i->Name) == "cmake_minimum_required")
|
|
|
|
{
|
2008-03-19 19:18:21 +00:00
|
|
|
hasVersion = true;
|
2008-03-07 16:43:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-03-06 15:57:59 +00:00
|
|
|
}
|
2008-03-19 19:18:21 +00:00
|
|
|
// if no version command is found this is a warning or error
|
|
|
|
if(!hasVersion)
|
2008-03-06 15:57:59 +00:00
|
|
|
{
|
2008-03-19 19:18:21 +00:00
|
|
|
cmOStringStream msg;
|
|
|
|
msg << "No cmake_minimum_required command is present. "
|
|
|
|
<< "A line of code such as\n"
|
|
|
|
<< " cmake_minimum_required(VERSION "
|
|
|
|
<< cmVersion::GetMajorVersion() << "."
|
|
|
|
<< cmVersion::GetMinorVersion()
|
|
|
|
<< ")\n"
|
|
|
|
<< "should be added at the top of the file. "
|
|
|
|
<< "The version specified may be lower if you wish to "
|
|
|
|
<< "support older CMake versions for this project. "
|
|
|
|
<< "For more information run "
|
|
|
|
<< "\"cmake --help-policy CMP0000\".";
|
|
|
|
switch (mf->GetPolicyStatus(cmPolicies::CMP0000))
|
|
|
|
{
|
2008-03-06 15:57:59 +00:00
|
|
|
case cmPolicies::WARN:
|
2008-03-19 19:18:21 +00:00
|
|
|
mf->IssueMessage(cmake::AUTHOR_WARNING, msg.str().c_str());
|
|
|
|
case cmPolicies::OLD:
|
2008-03-07 20:30:35 +00:00
|
|
|
// Implicitly set the version for the user.
|
|
|
|
mf->SetPolicyVersion("2.4");
|
2008-03-19 19:18:21 +00:00
|
|
|
break;
|
2008-03-06 15:57:59 +00:00
|
|
|
default:
|
2008-03-19 19:18:21 +00:00
|
|
|
mf->IssueMessage(cmake::FATAL_ERROR, msg.str().c_str());
|
2008-03-06 15:57:59 +00:00
|
|
|
return false;
|
2008-03-19 19:18:21 +00:00
|
|
|
}
|
2008-03-06 15:57:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(topLevel)
|
2002-12-02 20:30:59 +00:00
|
|
|
{
|
|
|
|
bool hasProject = false;
|
|
|
|
// search for a project command
|
|
|
|
for(std::vector<cmListFileFunction>::iterator i
|
2006-03-15 16:02:08 +00:00
|
|
|
= this->Functions.begin();
|
|
|
|
i != this->Functions.end(); ++i)
|
2002-12-02 20:30:59 +00:00
|
|
|
{
|
2006-03-15 16:02:08 +00:00
|
|
|
if(cmSystemTools::LowerCase(i->Name) == "project")
|
2002-12-02 20:30:59 +00:00
|
|
|
{
|
|
|
|
hasProject = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if no project command is found, add one
|
|
|
|
if(!hasProject)
|
|
|
|
{
|
|
|
|
cmListFileFunction project;
|
2006-03-15 16:02:08 +00:00
|
|
|
project.Name = "PROJECT";
|
2004-08-04 14:45:11 +00:00
|
|
|
cmListFileArgument prj("Project", false, filename, 0);
|
2006-03-15 16:02:08 +00:00
|
|
|
project.Arguments.push_back(prj);
|
|
|
|
this->Functions.insert(this->Functions.begin(),project);
|
2002-12-02 20:30:59 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-19 18:42:05 +00:00
|
|
|
if(parseError)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2001-08-28 22:28:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2002-09-19 18:34:15 +00:00
|
|
|
|
2003-12-08 18:36:59 +00:00
|
|
|
bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
|
|
|
|
cmListFileFunction& function,
|
|
|
|
const char* filename)
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
// Command name has already been parsed. Read the left paren.
|
|
|
|
cmListFileLexer_Token* token;
|
|
|
|
if(!(token = cmListFileLexer_Scan(lexer)))
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00: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-11 23:13:33 +00:00
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
if(token->type != cmListFileLexer_Token_ParenLeft)
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
|
|
|
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n"
|
2004-08-31 22:39:42 +00:00
|
|
|
<< "Parse error. Expected \"(\", got "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \"" << token->text << "\".";
|
2003-12-08 18:36:59 +00:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-11 23:13:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
|
|
|
|
// Arguments.
|
2004-08-31 22:51:35 +00:00
|
|
|
unsigned long lastLine = cmListFileLexer_GetCurrentLine(lexer);
|
2003-12-08 18:36:59 +00:00
|
|
|
while((token = cmListFileLexer_Scan(lexer)))
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
if(token->type == cmListFileLexer_Token_ParenRight)
|
2003-07-09 21:17:34 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
return true;
|
2003-07-09 21:17:34 +00:00
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
else if(token->type == cmListFileLexer_Token_Identifier ||
|
|
|
|
token->type == cmListFileLexer_Token_ArgumentUnquoted)
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2005-06-17 19:50:08 +00:00
|
|
|
cmListFileArgument a(token->text,
|
2004-08-04 14:45:11 +00:00
|
|
|
false, filename, token->line);
|
2006-03-15 16:02:08 +00:00
|
|
|
function.Arguments.push_back(a);
|
2002-12-11 23:13:33 +00:00
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
else if(token->type == cmListFileLexer_Token_ArgumentQuoted)
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2005-06-17 19:50:08 +00:00
|
|
|
cmListFileArgument a(token->text,
|
2004-08-04 14:45:11 +00:00
|
|
|
true, filename, token->line);
|
2006-03-15 16:02:08 +00:00
|
|
|
function.Arguments.push_back(a);
|
2002-12-11 23:13:33 +00:00
|
|
|
}
|
2003-12-08 18:36:59 +00:00
|
|
|
else if(token->type != cmListFileLexer_Token_Newline)
|
2002-12-11 23:13:33 +00:00
|
|
|
{
|
2003-12-08 18:36:59 +00:00
|
|
|
// Error.
|
2002-12-12 16:36:28 +00:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2006-05-12 15:56:09 +00:00
|
|
|
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer)
|
|
|
|
<< ":\n"
|
2003-12-08 18:36:59 +00:00
|
|
|
<< "Parse error. Function missing ending \")\". "
|
2004-08-31 22:39:42 +00:00
|
|
|
<< "Instead found "
|
|
|
|
<< cmListFileLexer_GetTypeAsString(lexer, token->type)
|
|
|
|
<< " with text \"" << token->text << "\".";
|
2002-12-12 16:36:28 +00:00
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-11 23:13:33 +00:00
|
|
|
return false;
|
|
|
|
}
|
2004-08-31 22:51:35 +00:00
|
|
|
lastLine = cmListFileLexer_GetCurrentLine(lexer);
|
2002-12-11 23:13:33 +00:00
|
|
|
}
|
|
|
|
|
2003-12-08 18:36:59 +00:00
|
|
|
cmOStringStream error;
|
|
|
|
error << "Error in cmake code at\n"
|
2004-08-31 22:51:35 +00:00
|
|
|
<< filename << ":" << lastLine << ":\n"
|
2003-12-08 18:36:59 +00:00
|
|
|
<< "Parse error. Function missing ending \")\". "
|
|
|
|
<< "End of file reached.";
|
|
|
|
cmSystemTools::Error(error.str().c_str());
|
2002-12-11 23:13:33 +00:00
|
|
|
|
2003-12-08 18:36:59 +00:00
|
|
|
return false;
|
2002-12-11 23:13:33 +00:00
|
|
|
}
|
2008-03-13 17:48:57 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
|
|
|
|
{
|
|
|
|
os << lfc.FilePath;
|
|
|
|
if(lfc.Line)
|
|
|
|
{
|
|
|
|
os << ":" << lfc.Line;
|
|
|
|
if(!lfc.Name.empty())
|
|
|
|
{
|
|
|
|
os << " (" << lfc.Name << ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|