2012-09-18 15:42:23 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2012 Stephen Kelly <steveire@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
|
|
|
|
#include "cmGeneratorExpressionDAGChecker.h"
|
|
|
|
|
|
|
|
#include "cmMakefile.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
|
|
|
|
const cmListFileBacktrace &backtrace,
|
|
|
|
const std::string &target,
|
|
|
|
const std::string &property,
|
|
|
|
const GeneratorExpressionContent *content,
|
|
|
|
cmGeneratorExpressionDAGChecker *parent)
|
|
|
|
: Parent(parent), Target(target), Property(property),
|
|
|
|
Content(content), Backtrace(backtrace)
|
|
|
|
{
|
2013-02-01 12:38:40 +04:00
|
|
|
const cmGeneratorExpressionDAGChecker *top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker *p = this->Parent;
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
top = p;
|
|
|
|
p = p->Parent;
|
|
|
|
}
|
2012-12-21 18:49:19 +04:00
|
|
|
this->CheckResult = this->checkGraph();
|
2013-02-01 12:38:40 +04:00
|
|
|
|
|
|
|
if (CheckResult == DAG && (top->Property == "INCLUDE_DIRECTORIES"
|
|
|
|
|| top->Property == "COMPILE_DEFINITIONS") )
|
|
|
|
{
|
|
|
|
std::map<cmStdString, std::set<cmStdString> >::const_iterator it
|
|
|
|
= top->Seen.find(target);
|
|
|
|
if (it != top->Seen.end())
|
|
|
|
{
|
|
|
|
const std::set<cmStdString> &propSet = it->second;
|
|
|
|
const std::set<cmStdString>::const_iterator i = propSet.find(property);
|
|
|
|
if (i != propSet.end())
|
|
|
|
{
|
|
|
|
this->CheckResult = ALREADY_SEEN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const_cast<cmGeneratorExpressionDAGChecker *>(top)
|
|
|
|
->Seen[target].insert(property);
|
|
|
|
}
|
2012-09-18 15:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-12-21 18:49:19 +04:00
|
|
|
cmGeneratorExpressionDAGChecker::Result
|
|
|
|
cmGeneratorExpressionDAGChecker::check() const
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
2012-12-21 18:49:19 +04:00
|
|
|
return this->CheckResult;
|
2012-09-18 15:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmGeneratorExpressionDAGChecker::reportError(
|
|
|
|
cmGeneratorExpressionContext *context,
|
|
|
|
const std::string &expr)
|
|
|
|
{
|
2012-12-21 18:49:19 +04:00
|
|
|
if (this->CheckResult == DAG)
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context->HadError = true;
|
|
|
|
if (context->Quiet)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const cmGeneratorExpressionDAGChecker *parent = this->Parent;
|
|
|
|
|
|
|
|
if (parent && !parent->Parent)
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Error evaluating generator expression:\n"
|
|
|
|
<< " " << expr << "\n"
|
|
|
|
<< "Self reference on target \""
|
2012-11-06 19:06:31 +04:00
|
|
|
<< context->HeadTarget->GetName() << "\".\n";
|
2012-09-18 15:42:23 +04:00
|
|
|
context->Makefile->GetCMakeInstance()
|
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(),
|
|
|
|
parent->Backtrace);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Error evaluating generator expression:\n"
|
|
|
|
<< " " << expr << "\n"
|
|
|
|
<< "Dependency loop found.";
|
|
|
|
context->Makefile->GetCMakeInstance()
|
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(),
|
|
|
|
context->Backtrace);
|
|
|
|
}
|
|
|
|
|
|
|
|
int loopStep = 1;
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
cmOStringStream e;
|
|
|
|
e << "Loop step " << loopStep << "\n"
|
|
|
|
<< " "
|
|
|
|
<< (parent->Content ? parent->Content->GetOriginalExpression() : expr)
|
|
|
|
<< "\n";
|
|
|
|
context->Makefile->GetCMakeInstance()
|
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(),
|
|
|
|
parent->Backtrace);
|
|
|
|
parent = parent->Parent;
|
|
|
|
++loopStep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-12-21 18:49:19 +04:00
|
|
|
cmGeneratorExpressionDAGChecker::Result
|
|
|
|
cmGeneratorExpressionDAGChecker::checkGraph() const
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
|
|
|
const cmGeneratorExpressionDAGChecker *parent = this->Parent;
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
if (this->Target == parent->Target && this->Property == parent->Property)
|
|
|
|
{
|
2013-02-18 14:08:24 +04:00
|
|
|
return (parent == this->Parent) ? SELF_REFERENCE : CYCLIC_REFERENCE;
|
2012-09-18 15:42:23 +04:00
|
|
|
}
|
|
|
|
parent = parent->Parent;
|
|
|
|
}
|
2012-12-21 18:49:19 +04:00
|
|
|
return DAG;
|
2012-09-18 15:42:23 +04:00
|
|
|
}
|
2013-01-19 14:21:14 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries()
|
|
|
|
{
|
|
|
|
const cmGeneratorExpressionDAGChecker *top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker *parent = this->Parent;
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
top = parent;
|
2013-01-24 01:17:14 +04:00
|
|
|
parent = parent->Parent;
|
2013-01-19 14:21:14 +04:00
|
|
|
}
|
2013-01-24 01:17:14 +04:00
|
|
|
|
|
|
|
const char *prop = top->Property.c_str();
|
|
|
|
return (strcmp(prop, "LINK_LIBRARIES") == 0
|
|
|
|
|| strcmp(prop, "LINK_INTERFACE_LIBRARIES") == 0
|
|
|
|
|| strcmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
|
2013-02-07 15:31:18 +04:00
|
|
|
|| strncmp(prop, "LINK_INTERFACE_LIBRARIES_", 25) == 0
|
|
|
|
|| strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES_", 34) == 0);
|
2013-01-19 14:21:14 +04:00
|
|
|
}
|
2013-01-31 02:35:22 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmGeneratorExpressionDAGChecker::EvaluatingIncludeDirectories()
|
|
|
|
{
|
|
|
|
const char *prop = this->Property.c_str();
|
|
|
|
return (strcmp(prop, "INCLUDE_DIRECTORIES") == 0
|
|
|
|
|| strcmp(prop, "INTERFACE_INCLUDE_DIRECTORIES") == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmGeneratorExpressionDAGChecker::EvaluatingCompileDefinitions()
|
|
|
|
{
|
|
|
|
const char *prop = this->Property.c_str();
|
|
|
|
return (strcmp(prop, "COMPILE_DEFINITIONS") == 0
|
2013-02-12 13:38:45 +04:00
|
|
|
|| strcmp(prop, "INTERFACE_COMPILE_DEFINITIONS") == 0
|
|
|
|
|| strncmp(prop, "COMPILE_DEFINITIONS_", 20) == 0);
|
2013-01-31 02:35:22 +04:00
|
|
|
}
|