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"
|
|
|
|
|
2015-03-08 15:51:20 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2012-09-18 15:42:23 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
|
|
|
|
const cmListFileBacktrace &backtrace,
|
|
|
|
const std::string &target,
|
|
|
|
const std::string &property,
|
|
|
|
const GeneratorExpressionContent *content,
|
|
|
|
cmGeneratorExpressionDAGChecker *parent)
|
|
|
|
: Parent(parent), Target(target), Property(property),
|
2013-06-05 15:43:54 +04:00
|
|
|
Content(content), Backtrace(backtrace), TransitivePropertiesOnly(false)
|
2014-05-23 22:59:11 +04:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
|
|
|
|
const std::string &target,
|
|
|
|
const std::string &property,
|
|
|
|
const GeneratorExpressionContent *content,
|
|
|
|
cmGeneratorExpressionDAGChecker *parent)
|
|
|
|
: Parent(parent), Target(target), Property(property),
|
2015-05-30 14:17:55 +03:00
|
|
|
Content(content), Backtrace(), TransitivePropertiesOnly(false)
|
2014-05-23 22:59:11 +04:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void
|
|
|
|
cmGeneratorExpressionDAGChecker::Initialize()
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
2013-02-01 12:38:40 +04:00
|
|
|
const cmGeneratorExpressionDAGChecker *top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker *p = this->Parent;
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
top = p;
|
|
|
|
p = p->Parent;
|
|
|
|
}
|
2014-01-05 08:25:09 +04:00
|
|
|
this->CheckResult = this->CheckGraph();
|
2013-02-01 12:38:40 +04:00
|
|
|
|
2013-06-10 18:01:59 +04:00
|
|
|
#define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) \
|
|
|
|
top->METHOD () ||
|
|
|
|
|
|
|
|
if (CheckResult == DAG && (
|
|
|
|
CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(TEST_TRANSITIVE_PROPERTY_METHOD)
|
|
|
|
false)
|
|
|
|
)
|
2013-12-31 17:34:16 +04:00
|
|
|
#undef TEST_TRANSITIVE_PROPERTY_METHOD
|
2013-02-01 12:38:40 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::map<std::string, std::set<std::string> >::const_iterator it
|
2014-05-23 22:59:11 +04:00
|
|
|
= top->Seen.find(this->Target);
|
2013-02-01 12:38:40 +04:00
|
|
|
if (it != top->Seen.end())
|
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
const std::set<std::string> &propSet = it->second;
|
2014-12-31 16:37:44 +03:00
|
|
|
if (propSet.find(this->Property) != propSet.end())
|
2013-02-01 12:38:40 +04:00
|
|
|
{
|
|
|
|
this->CheckResult = ALREADY_SEEN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const_cast<cmGeneratorExpressionDAGChecker *>(top)
|
2014-05-23 22:59:11 +04:00
|
|
|
->Seen[this->Target].insert(this->Property);
|
2013-02-01 12:38:40 +04:00
|
|
|
}
|
2012-09-18 15:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-12-21 18:49:19 +04:00
|
|
|
cmGeneratorExpressionDAGChecker::Result
|
2014-01-05 08:25:09 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2014-01-05 08:25:09 +04:00
|
|
|
void cmGeneratorExpressionDAGChecker::ReportError(
|
2012-09-18 15:42:23 +04:00
|
|
|
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)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2012-09-18 15:42:23 +04:00
|
|
|
e << "Error evaluating generator expression:\n"
|
|
|
|
<< " " << expr << "\n"
|
|
|
|
<< "Self reference on target \""
|
2012-11-06 19:06:31 +04:00
|
|
|
<< context->HeadTarget->GetName() << "\".\n";
|
2015-07-25 17:56:52 +03:00
|
|
|
context->LG->GetCMakeInstance()
|
2014-03-11 03:04:11 +04:00
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
2012-09-18 15:42:23 +04:00
|
|
|
parent->Backtrace);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2012-09-18 15:42:23 +04:00
|
|
|
e << "Error evaluating generator expression:\n"
|
|
|
|
<< " " << expr << "\n"
|
|
|
|
<< "Dependency loop found.";
|
2015-07-25 17:56:52 +03:00
|
|
|
context->LG->GetCMakeInstance()
|
2014-03-11 03:04:11 +04:00
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
2012-09-18 15:42:23 +04:00
|
|
|
context->Backtrace);
|
|
|
|
}
|
|
|
|
|
|
|
|
int loopStep = 1;
|
|
|
|
while (parent)
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2012-09-18 15:42:23 +04:00
|
|
|
e << "Loop step " << loopStep << "\n"
|
|
|
|
<< " "
|
|
|
|
<< (parent->Content ? parent->Content->GetOriginalExpression() : expr)
|
|
|
|
<< "\n";
|
2015-07-25 17:56:52 +03:00
|
|
|
context->LG->GetCMakeInstance()
|
2014-03-11 03:04:11 +04:00
|
|
|
->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
2012-09-18 15:42:23 +04:00
|
|
|
parent->Backtrace);
|
|
|
|
parent = parent->Parent;
|
|
|
|
++loopStep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2012-12-21 18:49:19 +04:00
|
|
|
cmGeneratorExpressionDAGChecker::Result
|
2014-01-05 08:25:09 +04:00
|
|
|
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
|
|
|
|
2013-06-05 15:43:54 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
bool cmGeneratorExpressionDAGChecker::GetTransitivePropertiesOnly()
|
|
|
|
{
|
|
|
|
const cmGeneratorExpressionDAGChecker *top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker *parent = this->Parent;
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
top = parent;
|
|
|
|
parent = parent->Parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return top->TransitivePropertiesOnly;
|
|
|
|
}
|
|
|
|
|
2013-01-19 14:21:14 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2013-06-14 17:58:04 +04:00
|
|
|
bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char *tgt)
|
2013-01-19 14:21:14 +04:00
|
|
|
{
|
|
|
|
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();
|
2013-06-14 17:58:04 +04:00
|
|
|
|
|
|
|
if (tgt)
|
|
|
|
{
|
|
|
|
return top->Target == tgt && strcmp(prop, "LINK_LIBRARIES") == 0;
|
|
|
|
}
|
|
|
|
|
2013-01-24 01:17:14 +04:00
|
|
|
return (strcmp(prop, "LINK_LIBRARIES") == 0
|
|
|
|
|| strcmp(prop, "LINK_INTERFACE_LIBRARIES") == 0
|
|
|
|
|| strcmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES") == 0
|
2013-11-20 05:12:00 +04:00
|
|
|
|| cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES_")
|
|
|
|
|| cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES_"))
|
2013-06-04 18:25:47 +04:00
|
|
|
|| strcmp(prop, "INTERFACE_LINK_LIBRARIES") == 0;
|
2013-01-19 14:21:14 +04:00
|
|
|
}
|
2013-01-31 02:35:22 +04:00
|
|
|
|
2014-02-13 23:52:21 +04:00
|
|
|
std::string cmGeneratorExpressionDAGChecker::TopTarget() const
|
|
|
|
{
|
|
|
|
const cmGeneratorExpressionDAGChecker *top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker *parent = this->Parent;
|
|
|
|
while (parent)
|
|
|
|
{
|
|
|
|
top = parent;
|
|
|
|
parent = parent->Parent;
|
|
|
|
}
|
|
|
|
return top->Target;
|
|
|
|
}
|
|
|
|
|
2014-01-05 15:40:38 +04:00
|
|
|
enum TransitiveProperty {
|
|
|
|
#define DEFINE_ENUM_ENTRY(NAME) NAME,
|
|
|
|
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(DEFINE_ENUM_ENTRY)
|
|
|
|
#undef DEFINE_ENUM_ENTRY
|
|
|
|
TransitivePropertyTerminal
|
|
|
|
};
|
|
|
|
|
|
|
|
template<TransitiveProperty>
|
|
|
|
bool additionalTest(const char* const)
|
2013-01-31 02:35:22 +04:00
|
|
|
{
|
2014-01-05 15:40:38 +04:00
|
|
|
return false;
|
2013-01-31 02:35:22 +04:00
|
|
|
}
|
|
|
|
|
2014-01-05 15:40:38 +04:00
|
|
|
template<>
|
|
|
|
bool additionalTest<COMPILE_DEFINITIONS>(const char* const prop)
|
2013-07-02 16:30:10 +04:00
|
|
|
{
|
2014-01-05 15:40:38 +04:00
|
|
|
return cmHasLiteralPrefix(prop, "COMPILE_DEFINITIONS_");
|
2013-07-02 16:30:10 +04:00
|
|
|
}
|
|
|
|
|
2014-01-05 15:40:38 +04:00
|
|
|
#define DEFINE_TRANSITIVE_PROPERTY_METHOD(METHOD, PROPERTY) \
|
|
|
|
bool cmGeneratorExpressionDAGChecker::METHOD() const \
|
|
|
|
{ \
|
|
|
|
const char* const prop = this->Property.c_str(); \
|
|
|
|
if (strcmp(prop, #PROPERTY) == 0 \
|
|
|
|
|| strcmp(prop, "INTERFACE_" #PROPERTY) == 0) \
|
|
|
|
{ \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
return additionalTest<PROPERTY>(prop); \
|
2013-01-31 02:35:22 +04:00
|
|
|
}
|
2013-05-16 17:15:28 +04:00
|
|
|
|
2014-01-05 15:40:38 +04:00
|
|
|
CM_FOR_EACH_TRANSITIVE_PROPERTY(DEFINE_TRANSITIVE_PROPERTY_METHOD)
|
2013-11-20 17:54:39 +04:00
|
|
|
|
2014-01-05 15:40:38 +04:00
|
|
|
#undef DEFINE_TRANSITIVE_PROPERTY_METHOD
|