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-09-01 21:59:28 +03:00
|
|
|
#include "cmGeneratorExpressionContext.h"
|
|
|
|
#include "cmGeneratorExpressionEvaluator.h"
|
|
|
|
#include "cmGeneratorTarget.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
2016-09-01 21:59:28 +03:00
|
|
|
#include "cmake.h"
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include <string.h>
|
|
|
|
#include <utility>
|
2012-09-18 15:42:23 +04:00
|
|
|
|
|
|
|
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
|
2016-05-16 17:34:04 +03:00
|
|
|
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)
|
|
|
|
, TransitivePropertiesOnly(false)
|
2014-05-23 22:59:11 +04:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
cmGeneratorExpressionDAGChecker::cmGeneratorExpressionDAGChecker(
|
2016-05-16 17:34:04 +03:00
|
|
|
const std::string& target, const std::string& property,
|
|
|
|
const GeneratorExpressionContent* content,
|
|
|
|
cmGeneratorExpressionDAGChecker* parent)
|
|
|
|
: Parent(parent)
|
|
|
|
, Target(target)
|
|
|
|
, Property(property)
|
|
|
|
, Content(content)
|
|
|
|
, Backtrace()
|
|
|
|
, TransitivePropertiesOnly(false)
|
2014-05-23 22:59:11 +04:00
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmGeneratorExpressionDAGChecker::Initialize()
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorExpressionDAGChecker* top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker* p = this->Parent;
|
|
|
|
while (p) {
|
2013-02-01 12:38:40 +04:00
|
|
|
top = p;
|
|
|
|
p = p->Parent;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-01-05 08:25:09 +04:00
|
|
|
this->CheckResult = this->CheckGraph();
|
2013-02-01 12:38:40 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
#define TEST_TRANSITIVE_PROPERTY_METHOD(METHOD) top->METHOD() ||
|
2013-06-10 18:01:59 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
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
|
2016-05-16 17:34:04 +03:00
|
|
|
{
|
|
|
|
std::map<std::string, std::set<std::string> >::const_iterator it =
|
|
|
|
top->Seen.find(this->Target);
|
|
|
|
if (it != top->Seen.end()) {
|
|
|
|
const std::set<std::string>& propSet = it->second;
|
|
|
|
if (propSet.find(this->Property) != propSet.end()) {
|
2013-02-01 12:38:40 +04:00
|
|
|
this->CheckResult = ALREADY_SEEN;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
const_cast<cmGeneratorExpressionDAGChecker*>(top)
|
|
|
|
->Seen[this->Target]
|
|
|
|
.insert(this->Property);
|
|
|
|
}
|
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(
|
2016-05-16 17:34:04 +03:00
|
|
|
cmGeneratorExpressionContext* context, const std::string& expr)
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->CheckResult == DAG) {
|
2012-09-18 15:42:23 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-18 15:42:23 +04:00
|
|
|
|
|
|
|
context->HadError = true;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (context->Quiet) {
|
2012-09-18 15:42:23 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-18 15:42:23 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorExpressionDAGChecker* parent = this->Parent;
|
2012-09-18 15:42:23 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
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"
|
2016-05-16 17:34:04 +03:00
|
|
|
<< "Self reference on target \"" << context->HeadTarget->GetName()
|
|
|
|
<< "\".\n";
|
|
|
|
context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
|
|
|
parent->Backtrace);
|
2012-09-18 15:42:23 +04:00
|
|
|
return;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2012-09-18 15:42:23 +04:00
|
|
|
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::ostringstream e;
|
|
|
|
/* clang-format off */
|
2012-09-18 15:42:23 +04:00
|
|
|
e << "Error evaluating generator expression:\n"
|
|
|
|
<< " " << expr << "\n"
|
|
|
|
<< "Dependency loop found.";
|
2016-05-16 17:34:04 +03:00
|
|
|
/* clang-format on */
|
|
|
|
context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
|
|
|
context->Backtrace);
|
2012-09-18 15:42:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int loopStep = 1;
|
2016-05-16 17:34:04 +03:00
|
|
|
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";
|
2016-05-16 17:34:04 +03:00
|
|
|
context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
|
|
|
|
parent->Backtrace);
|
2012-09-18 15:42:23 +04:00
|
|
|
parent = parent->Parent;
|
|
|
|
++loopStep;
|
2016-05-16 17:34:04 +03: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::CheckGraph() const
|
2012-09-18 15:42:23 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03: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
|
|
|
}
|
2016-05-16 17:34:04 +03: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()
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorExpressionDAGChecker* top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker* parent = this->Parent;
|
|
|
|
while (parent) {
|
2013-06-05 15:43:54 +04:00
|
|
|
top = parent;
|
|
|
|
parent = parent->Parent;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-05 15:43:54 +04:00
|
|
|
|
|
|
|
return top->TransitivePropertiesOnly;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmGeneratorExpressionDAGChecker::EvaluatingLinkLibraries(const char* tgt)
|
2013-01-19 14:21:14 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorExpressionDAGChecker* top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker* parent = this->Parent;
|
|
|
|
while (parent) {
|
2013-01-19 14:21:14 +04:00
|
|
|
top = parent;
|
2013-01-24 01:17:14 +04:00
|
|
|
parent = parent->Parent;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-01-24 01:17:14 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
const char* prop = top->Property.c_str();
|
2013-06-14 17:58:04 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (tgt) {
|
2013-06-14 17:58:04 +04:00
|
|
|
return top->Target == tgt && strcmp(prop, "LINK_LIBRARIES") == 0;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-14 17:58:04 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
return (strcmp(prop, "LINK_LIBRARIES") == 0 ||
|
|
|
|
strcmp(prop, "LINK_INTERFACE_LIBRARIES") == 0 ||
|
|
|
|
strcmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES") == 0 ||
|
|
|
|
cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES_") ||
|
|
|
|
cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES_")) ||
|
|
|
|
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
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
const cmGeneratorExpressionDAGChecker* top = this;
|
|
|
|
const cmGeneratorExpressionDAGChecker* parent = this->Parent;
|
|
|
|
while (parent) {
|
2014-02-13 23:52:21 +04:00
|
|
|
top = parent;
|
|
|
|
parent = parent->Parent;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-13 23:52:21 +04:00
|
|
|
return top->Target;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
enum TransitiveProperty
|
|
|
|
{
|
2014-01-05 15:40:38 +04:00
|
|
|
#define DEFINE_ENUM_ENTRY(NAME) NAME,
|
|
|
|
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(DEFINE_ENUM_ENTRY)
|
|
|
|
#undef DEFINE_ENUM_ENTRY
|
2016-05-16 17:34:04 +03:00
|
|
|
TransitivePropertyTerminal
|
2014-01-05 15:40:38 +04:00
|
|
|
};
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
template <TransitiveProperty>
|
2016-08-17 02:49:57 +03:00
|
|
|
bool additionalTest(const char* const /*unused*/)
|
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
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
template <>
|
2014-01-05 15:40:38 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03: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-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
|