cmGeneratorExpressionEvaluator.cxx 69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*============================================================================
  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 "cmMakefile.h"

#include "cmGeneratorExpressionEvaluator.h"
#include "cmGeneratorExpressionParser.h"
16
#include "cmGeneratorExpressionDAGChecker.h"
17
#include "cmGeneratorExpression.h"
18
19
#include "cmLocalGenerator.h"
#include "cmSourceFile.h"
20

21
22
#include <cmsys/String.h>

23
#include <assert.h>
Stephen Kelly's avatar
Stephen Kelly committed
24
#include <errno.h>
25

26
//----------------------------------------------------------------------------
27
28
29
30
#if !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x510
static
#endif
void reportError(cmGeneratorExpressionContext *context,
31
32
33
34
35
36
37
38
39
40
41
42
43
                        const std::string &expr, const std::string &result)
{
  context->HadError = true;
  if (context->Quiet)
    {
    return;
    }

  cmOStringStream e;
  e << "Error evaluating generator expression:\n"
    << "  " << expr << "\n"
    << result;
  context->Makefile->GetCMakeInstance()
Stephen Kelly's avatar
Stephen Kelly committed
44
    ->IssueMessage(cmake::FATAL_ERROR, e.str(),
45
46
47
48
49
50
                    context->Backtrace);
}

//----------------------------------------------------------------------------
struct cmGeneratorExpressionNode
{
51
52
53
  enum {
    DynamicParameters = 0,
    OneOrMoreParameters = -1,
54
    OneOrZeroParameters = -2
55
  };
56
57
58
59
  virtual ~cmGeneratorExpressionNode() {}

  virtual bool GeneratesContent() const { return true; }

60
61
  virtual bool RequiresLiteralInput() const { return false; }

62
  virtual bool AcceptsArbitraryContentParameter() const
63
64
65
66
67
68
    { return false; }

  virtual int NumExpectedParameters() const { return 1; }

  virtual std::string Evaluate(const std::vector<std::string> &parameters,
                               cmGeneratorExpressionContext *context,
69
70
                               const GeneratorExpressionContent *content,
                               cmGeneratorExpressionDAGChecker *dagChecker
71
72
73
74
75
76
77
78
79
80
                              ) const = 0;
};

//----------------------------------------------------------------------------
static const struct ZeroNode : public cmGeneratorExpressionNode
{
  ZeroNode() {}

  virtual bool GeneratesContent() const { return false; }

81
  virtual bool AcceptsArbitraryContentParameter() const { return true; }
82

83
84
  std::string Evaluate(const std::vector<std::string> &,
                       cmGeneratorExpressionContext *,
85
86
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
87
88
89
90
91
92
93
94
95
96
  {
    return std::string();
  }
} zeroNode;

//----------------------------------------------------------------------------
static const struct OneNode : public cmGeneratorExpressionNode
{
  OneNode() {}

97
  virtual bool AcceptsArbitraryContentParameter() const { return true; }
98

99
  std::string Evaluate(const std::vector<std::string> &parameters,
100
                       cmGeneratorExpressionContext *,
101
102
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
103
  {
104
    return parameters.front();
105
106
107
  }
} oneNode;

108
109
110
111
112
113
//----------------------------------------------------------------------------
static const struct OneNode buildInterfaceNode;

//----------------------------------------------------------------------------
static const struct ZeroNode installInterfaceNode;

114
115
116
117
118
//----------------------------------------------------------------------------
#define BOOLEAN_OP_NODE(OPNAME, OP, SUCCESS_VALUE, FAILURE_VALUE) \
static const struct OP ## Node : public cmGeneratorExpressionNode \
{ \
  OP ## Node () {} \
119
  virtual int NumExpectedParameters() const { return OneOrMoreParameters; } \
120
121
122
 \
  std::string Evaluate(const std::vector<std::string> &parameters, \
                       cmGeneratorExpressionContext *context, \
123
124
                       const GeneratorExpressionContent *content, \
                       cmGeneratorExpressionDAGChecker *) const \
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  { \
    std::vector<std::string>::const_iterator it = parameters.begin(); \
    const std::vector<std::string>::const_iterator end = parameters.end(); \
    for ( ; it != end; ++it) \
      { \
      if (*it == #FAILURE_VALUE) \
        { \
        return #FAILURE_VALUE; \
        } \
      else if (*it != #SUCCESS_VALUE) \
        { \
        reportError(context, content->GetOriginalExpression(), \
        "Parameters to $<" #OP "> must resolve to either '0' or '1'."); \
        return std::string(); \
        } \
      } \
    return #SUCCESS_VALUE; \
  } \
} OPNAME;

BOOLEAN_OP_NODE(andNode, AND, 1, 0)
BOOLEAN_OP_NODE(orNode, OR, 0, 1)

#undef BOOLEAN_OP_NODE

//----------------------------------------------------------------------------
static const struct NotNode : public cmGeneratorExpressionNode
{
  NotNode() {}
154

155
156
  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
157
158
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *) const
159
160
161
162
163
164
165
166
167
168
169
  {
    if (*parameters.begin() != "0" && *parameters.begin() != "1")
      {
      reportError(context, content->GetOriginalExpression(),
            "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
      return std::string();
      }
    return *parameters.begin() == "0" ? "1" : "0";
  }
} notNode;

170
171
172
173
174
175
176
177
178
//----------------------------------------------------------------------------
static const struct BoolNode : public cmGeneratorExpressionNode
{
  BoolNode() {}

  virtual int NumExpectedParameters() const { return 1; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
179
180
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  {
    return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
  }
} boolNode;

//----------------------------------------------------------------------------
static const struct StrEqualNode : public cmGeneratorExpressionNode
{
  StrEqualNode() {}

  virtual int NumExpectedParameters() const { return 2; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
195
196
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
197
  {
198
    return *parameters.begin() == parameters[1] ? "1" : "0";
199
200
201
  }
} strEqualNode;

Stephen Kelly's avatar
Stephen Kelly committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//----------------------------------------------------------------------------
static const struct EqualNode : public cmGeneratorExpressionNode
{
  EqualNode() {}

  virtual int NumExpectedParameters() const { return 2; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *) const
  {
    char *pEnd;

    int base = 0;
    bool flipSign = false;

    const char *lhs = parameters[0].c_str();
220
    if (cmHasLiteralPrefix(lhs, "0b") || cmHasLiteralPrefix(lhs, "0B"))
Stephen Kelly's avatar
Stephen Kelly committed
221
222
223
224
      {
      base = 2;
      lhs += 2;
      }
225
    if (cmHasLiteralPrefix(lhs, "-0b") || cmHasLiteralPrefix(lhs, "-0B"))
Stephen Kelly's avatar
Stephen Kelly committed
226
227
228
229
230
      {
      base = 2;
      lhs += 3;
      flipSign = true;
      }
231
    if (cmHasLiteralPrefix(lhs, "+0b") || cmHasLiteralPrefix(lhs, "+0B"))
Stephen Kelly's avatar
Stephen Kelly committed
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
      {
      base = 2;
      lhs += 3;
      }

    long lnum = strtol(lhs, &pEnd, base);
    if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
      {
      reportError(context, content->GetOriginalExpression(),
          "$<EQUAL> parameter " + parameters[0] + " is not a valid integer.");
      return std::string();
      }

    if (flipSign)
      {
      lnum = -lnum;
      }

    base = 0;
    flipSign = false;

    const char *rhs = parameters[1].c_str();
254
    if (cmHasLiteralPrefix(rhs, "0b") || cmHasLiteralPrefix(rhs, "0B"))
Stephen Kelly's avatar
Stephen Kelly committed
255
256
257
258
      {
      base = 2;
      rhs += 2;
      }
259
    if (cmHasLiteralPrefix(rhs, "-0b") || cmHasLiteralPrefix(rhs, "-0B"))
Stephen Kelly's avatar
Stephen Kelly committed
260
261
262
263
264
      {
      base = 2;
      rhs += 3;
      flipSign = true;
      }
265
    if (cmHasLiteralPrefix(rhs, "+0b") || cmHasLiteralPrefix(rhs, "+0B"))
Stephen Kelly's avatar
Stephen Kelly committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
      {
      base = 2;
      rhs += 3;
      }

    long rnum = strtol(rhs, &pEnd, base);
    if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
      {
      reportError(context, content->GetOriginalExpression(),
          "$<EQUAL> parameter " + parameters[1] + " is not a valid integer.");
      return std::string();
      }

    if (flipSign)
      {
      rnum = -rnum;
      }

    return lnum == rnum ? "1" : "0";
  }
} equalNode;

288
289
290
291
292
//----------------------------------------------------------------------------
static const struct LowerCaseNode : public cmGeneratorExpressionNode
{
  LowerCaseNode() {}

293
294
  bool AcceptsArbitraryContentParameter() const { return true; }

295
296
297
298
299
300
301
302
303
304
305
306
307
308
  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return cmSystemTools::LowerCase(parameters.front());
  }
} lowerCaseNode;

//----------------------------------------------------------------------------
static const struct UpperCaseNode : public cmGeneratorExpressionNode
{
  UpperCaseNode() {}

309
310
  bool AcceptsArbitraryContentParameter() const { return true; }

311
312
313
314
315
316
317
318
319
320
321
322
323
324
  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return cmSystemTools::UpperCase(parameters.front());
  }
} upperCaseNode;

//----------------------------------------------------------------------------
static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode
{
  MakeCIdentifierNode() {}

325
326
  bool AcceptsArbitraryContentParameter() const { return true; }

327
328
329
330
331
332
333
334
335
  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return cmSystemTools::MakeCidentifier(parameters.front().c_str());
  }
} makeCIdentifierNode;

336
337
338
339
340
341
342
343
344
//----------------------------------------------------------------------------
static const struct Angle_RNode : public cmGeneratorExpressionNode
{
  Angle_RNode() {}

  virtual int NumExpectedParameters() const { return 0; }

  std::string Evaluate(const std::vector<std::string> &,
                       cmGeneratorExpressionContext *,
345
346
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  {
    return ">";
  }
} angle_rNode;

//----------------------------------------------------------------------------
static const struct CommaNode : public cmGeneratorExpressionNode
{
  CommaNode() {}

  virtual int NumExpectedParameters() const { return 0; }

  std::string Evaluate(const std::vector<std::string> &,
                       cmGeneratorExpressionContext *,
361
362
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
363
364
365
366
367
  {
    return ",";
  }
} commaNode;

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
//----------------------------------------------------------------------------
static const struct SemicolonNode : public cmGeneratorExpressionNode
{
  SemicolonNode() {}

  virtual int NumExpectedParameters() const { return 0; }

  std::string Evaluate(const std::vector<std::string> &,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return ";";
  }
} semicolonNode;

384
385
386
387
388
//----------------------------------------------------------------------------
struct CompilerIdNode : public cmGeneratorExpressionNode
{
  CompilerIdNode() {}

389
  virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
390
391
392
393
394
395
396
397

  std::string EvaluateWithLanguage(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *,
                       const std::string &lang) const
  {
    const char *compilerId = context->Makefile ?
Stephen Kelly's avatar
Stephen Kelly committed
398
399
                              context->Makefile->GetSafeDefinition(
                                      "CMAKE_" + lang + "_COMPILER_ID") : "";
400
401
402
403
    if (parameters.size() == 0)
      {
      return compilerId ? compilerId : "";
      }
404
    static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
405
    if (!compilerIdValidator.find(*parameters.begin()))
406
407
408
409
410
411
412
413
414
415
      {
      reportError(context, content->GetOriginalExpression(),
                  "Expression syntax not recognized.");
      return std::string();
      }
    if (!compilerId)
      {
      return parameters.front().empty() ? "1" : "0";
      }

416
    if (strcmp(parameters.begin()->c_str(), compilerId) == 0)
417
418
419
      {
      return "1";
      }
420
421
422
423
424
425
426
427
428
429
430
431

    if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0)
      {
      switch(context->Makefile->GetPolicyStatus(cmPolicies::CMP0044))
        {
        case cmPolicies::WARN:
          {
          cmOStringStream e;
          e << context->Makefile->GetPolicies()
                      ->GetPolicyWarning(cmPolicies::CMP0044);
          context->Makefile->GetCMakeInstance()
                 ->IssueMessage(cmake::AUTHOR_WARNING,
Stephen Kelly's avatar
Stephen Kelly committed
432
                                e.str(), context->Backtrace);
433
434
435
436
437
438
439
440
441
          }
        case cmPolicies::OLD:
          return "1";
        case cmPolicies::NEW:
        case cmPolicies::REQUIRED_ALWAYS:
        case cmPolicies::REQUIRED_IF_USED:
          break;
        }
      }
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
    return "0";
  }
};

//----------------------------------------------------------------------------
static const struct CCompilerIdNode : public CompilerIdNode
{
  CCompilerIdNode() {}

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *dagChecker) const
  {
    if (!context->HeadTarget)
      {
      reportError(context, content->GetOriginalExpression(),
459
460
          "$<C_COMPILER_ID> may only be used with binary targets.  It may "
          "not be used with add_custom_command or add_custom_target.");
461
      return std::string();
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
      }
    return this->EvaluateWithLanguage(parameters, context, content,
                                      dagChecker, "C");
  }
} cCompilerIdNode;

//----------------------------------------------------------------------------
static const struct CXXCompilerIdNode : public CompilerIdNode
{
  CXXCompilerIdNode() {}

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *dagChecker) const
  {
    if (!context->HeadTarget)
      {
      reportError(context, content->GetOriginalExpression(),
481
482
          "$<CXX_COMPILER_ID> may only be used with binary targets.  It may "
          "not be used with add_custom_command or add_custom_target.");
483
      return std::string();
484
485
486
487
488
489
      }
    return this->EvaluateWithLanguage(parameters, context, content,
                                      dagChecker, "CXX");
  }
} cxxCompilerIdNode;

490
491
492
493
494
//----------------------------------------------------------------------------
struct CompilerVersionNode : public cmGeneratorExpressionNode
{
  CompilerVersionNode() {}

495
  virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
496
497
498
499
500
501
502
503

  std::string EvaluateWithLanguage(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *,
                       const std::string &lang) const
  {
    const char *compilerVersion = context->Makefile ?
Stephen Kelly's avatar
Stephen Kelly committed
504
505
                              context->Makefile->GetSafeDefinition(
                                  "CMAKE_" + lang + "_COMPILER_VERSION") : "";
506
507
508
509
510
    if (parameters.size() == 0)
      {
      return compilerVersion ? compilerVersion : "";
      }

511
    static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
512
    if (!compilerIdValidator.find(*parameters.begin()))
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
      {
      reportError(context, content->GetOriginalExpression(),
                  "Expression syntax not recognized.");
      return std::string();
      }
    if (!compilerVersion)
      {
      return parameters.front().empty() ? "1" : "0";
      }

    return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
                                      parameters.begin()->c_str(),
                                      compilerVersion) ? "1" : "0";
  }
};

//----------------------------------------------------------------------------
static const struct CCompilerVersionNode : public CompilerVersionNode
{
  CCompilerVersionNode() {}

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *dagChecker) const
  {
    if (!context->HeadTarget)
      {
      reportError(context, content->GetOriginalExpression(),
542
543
          "$<C_COMPILER_VERSION> may only be used with binary targets.  It "
          "may not be used with add_custom_command or add_custom_target.");
544
      return std::string();
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
      }
    return this->EvaluateWithLanguage(parameters, context, content,
                                      dagChecker, "C");
  }
} cCompilerVersionNode;

//----------------------------------------------------------------------------
static const struct CxxCompilerVersionNode : public CompilerVersionNode
{
  CxxCompilerVersionNode() {}

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *dagChecker) const
  {
    if (!context->HeadTarget)
      {
      reportError(context, content->GetOriginalExpression(),
564
565
          "$<CXX_COMPILER_VERSION> may only be used with binary targets.  It "
          "may not be used with add_custom_command or add_custom_target.");
566
      return std::string();
567
568
569
570
571
572
573
      }
    return this->EvaluateWithLanguage(parameters, context, content,
                                      dagChecker, "CXX");
  }
} cxxCompilerVersionNode;


574
575
576
577
578
//----------------------------------------------------------------------------
struct PlatformIdNode : public cmGeneratorExpressionNode
{
  PlatformIdNode() {}

579
  virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    const char *platformId = context->Makefile ?
                              context->Makefile->GetSafeDefinition(
                        "CMAKE_SYSTEM_NAME") : "";
    if (parameters.size() == 0)
      {
      return platformId ? platformId : "";
      }

    if (!platformId)
      {
      return parameters.front().empty() ? "1" : "0";
      }

599
    if (strcmp(parameters.begin()->c_str(), platformId) == 0)
600
601
602
603
604
605
606
      {
      return "1";
      }
    return "0";
  }
} platformIdNode;

607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
//----------------------------------------------------------------------------
static const struct VersionGreaterNode : public cmGeneratorExpressionNode
{
  VersionGreaterNode() {}

  virtual int NumExpectedParameters() const { return 2; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER,
                                         parameters.front().c_str(),
                                         parameters[1].c_str()) ? "1" : "0";
  }
} versionGreaterNode;

//----------------------------------------------------------------------------
static const struct VersionLessNode : public cmGeneratorExpressionNode
{
  VersionLessNode() {}

  virtual int NumExpectedParameters() const { return 2; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
                                         parameters.front().c_str(),
                                         parameters[1].c_str()) ? "1" : "0";
  }
} versionLessNode;

//----------------------------------------------------------------------------
static const struct VersionEqualNode : public cmGeneratorExpressionNode
{
  VersionEqualNode() {}

  virtual int NumExpectedParameters() const { return 2; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
                                         parameters.front().c_str(),
                                         parameters[1].c_str()) ? "1" : "0";
  }
} versionEqualNode;

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
//----------------------------------------------------------------------------
static const struct LinkOnlyNode : public cmGeneratorExpressionNode
{
  LinkOnlyNode() {}

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *dagChecker) const
  {
    if(!dagChecker->GetTransitivePropertiesOnly())
      {
      return parameters.front();
      }
    return "";
  }
} linkOnlyNode;

679
680
681
682
//----------------------------------------------------------------------------
static const struct ConfigurationNode : public cmGeneratorExpressionNode
{
  ConfigurationNode() {}
683

684
685
686
687
  virtual int NumExpectedParameters() const { return 0; }

  std::string Evaluate(const std::vector<std::string> &,
                       cmGeneratorExpressionContext *context,
688
689
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
690
  {
691
    context->HadContextSensitiveCondition = true;
692
    return context->Config;
693
694
695
696
697
698
699
700
  }
} configurationNode;

//----------------------------------------------------------------------------
static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
{
  ConfigurationTestNode() {}

701
  virtual int NumExpectedParameters() const { return OneOrZeroParameters; }
702
703
704

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
705
706
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *) const
707
  {
708
709
710
711
    if (parameters.empty())
      {
      return configurationNode.Evaluate(parameters, context, content, 0);
      }
712
    static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
713
    if (!configValidator.find(*parameters.begin()))
714
715
716
717
718
      {
      reportError(context, content->GetOriginalExpression(),
                  "Expression syntax not recognized.");
      return std::string();
      }
719
    context->HadContextSensitiveCondition = true;
720
    if (context->Config.empty())
721
722
723
724
      {
      return parameters.front().empty() ? "1" : "0";
      }

725
    if (cmsysString_strcasecmp(parameters.begin()->c_str(),
726
                               context->Config.c_str()) == 0)
727
728
729
730
731
732
733
734
735
736
      {
      return "1";
      }

    if (context->CurrentTarget
        && context->CurrentTarget->IsImported())
      {
      const char* loc = 0;
      const char* imp = 0;
      std::string suffix;
737
      if (context->CurrentTarget->GetMappedConfig(context->Config,
738
739
                                                  &loc,
                                                  &imp,
740
741
742
743
744
745
746
                                                  suffix))
        {
        // This imported target has an appropriate location
        // for this (possibly mapped) config.
        // Check if there is a proper config mapping for the tested config.
        std::vector<std::string> mappedConfigs;
        std::string mapProp = "MAP_IMPORTED_CONFIG_";
747
        mapProp += cmSystemTools::UpperCase(context->Config);
748
        if(const char* mapValue =
Stephen Kelly's avatar
Stephen Kelly committed
749
                        context->CurrentTarget->GetProperty(mapProp))
750
751
752
753
          {
          cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
                                            mappedConfigs);
          return std::find(mappedConfigs.begin(), mappedConfigs.end(),
754
755
                           cmSystemTools::UpperCase(parameters.front()))
              != mappedConfigs.end() ? "1" : "0";
756
757
          }
        }
758
759
      }
    return "0";
760
761
762
  }
} configurationTestNode;

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
static const struct JoinNode : public cmGeneratorExpressionNode
{
  JoinNode() {}

  virtual int NumExpectedParameters() const { return 2; }

  virtual bool AcceptsArbitraryContentParameter() const { return true; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    std::string result;

    std::vector<std::string> list;
    cmSystemTools::ExpandListArgument(parameters.front(), list);
    std::string sep;
    for(std::vector<std::string>::const_iterator li = list.begin();
      li != list.end(); ++li)
      {
      result += sep + *li;
      sep = parameters[1];
      }
    return result;
  }
} joinNode;

791
#define TRANSITIVE_PROPERTY_NAME(PROPERTY) \
792
  , "INTERFACE_" #PROPERTY
793

794
795
//----------------------------------------------------------------------------
static const char* targetPropertyTransitiveWhitelist[] = {
796
797
  0
  CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
798
799
};

800
801
#undef TRANSITIVE_PROPERTY_NAME

802
std::string getLinkedTargetsContent(const std::vector<cmTarget*> &targets,
803
804
                                  cmTarget const* target,
                                  cmTarget const* headTarget,
805
806
807
808
                                  cmGeneratorExpressionContext *context,
                                  cmGeneratorExpressionDAGChecker *dagChecker,
                                  const std::string &interfacePropertyName)
{
809
  cmGeneratorExpression ge(&context->Backtrace);
810
811
812

  std::string sep;
  std::string depString;
813
814
815
  for (std::vector<cmTarget*>::const_iterator
      it = targets.begin();
      it != targets.end(); ++it)
816
    {
817
    if (*it == target)
818
819
820
821
822
823
      {
      // Broken code can have a target in its own link interface.
      // Don't follow such link interface entries so as not to create a
      // self-referencing loop.
      continue;
      }
824
825
826
827
    depString +=
      sep + "$<TARGET_PROPERTY:" +
        (*it)->GetName() + "," + interfacePropertyName + ">";
    sep = ";";
828
829
830
831
832
    }
  cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(depString);
  std::string linkedTargetsContent = cge->Evaluate(context->Makefile,
                      context->Config,
                      context->Quiet,
833
                      headTarget,
834
835
836
837
838
839
840
841
842
                      target,
                      dagChecker);
  if (cge->GetHadContextSensitiveCondition())
    {
    context->HadContextSensitiveCondition = true;
    }
  return linkedTargetsContent;
}

843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
std::string getLinkedTargetsContent(const std::vector<std::string> &libraries,
                                  cmTarget const* target,
                                  cmTarget const* headTarget,
                                  cmGeneratorExpressionContext *context,
                                  cmGeneratorExpressionDAGChecker *dagChecker,
                                  const std::string &interfacePropertyName)
{
  std::vector<cmTarget*> tgts;
  for (std::vector<std::string>::const_iterator
      it = libraries.begin();
      it != libraries.end(); ++it)
    {
    if (cmTarget *tgt = context->Makefile->FindTargetToUse(*it))
      {
      tgts.push_back(tgt);
      }
    }
  return getLinkedTargetsContent(tgts, target, headTarget, context,
                                 dagChecker, interfacePropertyName);
}

864
//----------------------------------------------------------------------------
865
static const struct TargetPropertyNode : public cmGeneratorExpressionNode
866
867
868
869
{
  TargetPropertyNode() {}

  // This node handles errors on parameter count itself.
870
  virtual int NumExpectedParameters() const { return OneOrMoreParameters; }
871
872
873

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
874
                       const GeneratorExpressionContent *content,
875
876
                       cmGeneratorExpressionDAGChecker *dagCheckerParent
                      ) const
877
878
879
880
881
882
883
  {
    if (parameters.size() != 1 && parameters.size() != 2)
      {
      reportError(context, content->GetOriginalExpression(),
          "$<TARGET_PROPERTY:...> expression requires one or two parameters");
      return std::string();
      }
884
    static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
885

886
    cmTarget const* target = context->HeadTarget;
887
    std::string propertyName = *parameters.begin();
888
889
890
891

    if (!target && parameters.size() == 1)
      {
      reportError(context, content->GetOriginalExpression(),
892
893
894
895
          "$<TARGET_PROPERTY:prop>  may only be used with binary targets.  "
          "It may not be used with add_custom_command or add_custom_target.  "
          "Specify the target to read a property from using the "
          "$<TARGET_PROPERTY:tgt,prop> signature instead.");
896
897
898
      return std::string();
      }

899
900
    if (parameters.size() == 2)
      {
901
      if (parameters.begin()->empty() && parameters[1].empty())
902
903
904
905
906
907
908
909
910
911
912
913
914
915
        {
        reportError(context, content->GetOriginalExpression(),
            "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
            "target name and property name.");
        return std::string();
        }
      if (parameters.begin()->empty())
        {
        reportError(context, content->GetOriginalExpression(),
            "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
            "target name.");
        return std::string();
        }

916
      std::string targetName = parameters.front();
917
      propertyName = parameters[1];
918
      if (!cmGeneratorExpression::IsValidTargetName(targetName))
919
        {
920
        if (!propertyNameValidator.find(propertyName.c_str()))
921
922
923
924
925
926
927
928
929
          {
          ::reportError(context, content->GetOriginalExpression(),
                        "Target name and property name not supported.");
          return std::string();
          }
        ::reportError(context, content->GetOriginalExpression(),
                      "Target name not supported.");
        return std::string();
        }
930
931
      if(propertyName == "ALIASED_TARGET")
        {
932
        if(context->Makefile->IsAlias(targetName))
933
          {
934
          if(cmTarget* tgt = context->Makefile->FindTargetToUse(targetName))
935
936
937
938
939
940
            {
            return tgt->GetName();
            }
          }
        return "";
        }
941
      target = context->Makefile->FindTargetToUse(targetName);
942
943
944
945
946

      if (!target)
        {
        cmOStringStream e;
        e << "Target \""
947
          << targetName
948
949
          << "\" not found.";
        reportError(context, content->GetOriginalExpression(), e.str());
950
        return std::string();
951
        }
952
        context->AllTargets.insert(target);
953
954
      }

955
956
957
958
    if (target == context->HeadTarget)
      {
      // Keep track of the properties seen while processing.
      // The evaluation of the LINK_LIBRARIES generator expressions
959
960
      // will check this to ensure that properties have one consistent
      // value for all evaluations.
961
962
963
      context->SeenTargetProperties.insert(propertyName);
      }

964
965
966
967
968
969
970
971
    if (propertyName.empty())
      {
      reportError(context, content->GetOriginalExpression(),
          "$<TARGET_PROPERTY:...> expression requires a non-empty property "
          "name.");
      return std::string();
      }

972
    if (!propertyNameValidator.find(propertyName))
973
974
975
976
      {
      ::reportError(context, content->GetOriginalExpression(),
                    "Property name not supported.");
      return std::string();
977
      }
978

979
980
    assert(target);

981
982
    if (propertyName == "LINKER_LANGUAGE")
      {
983
      if (target->LinkLanguagePropagatesToDependents() &&
984
985
          dagCheckerParent && (dagCheckerParent->EvaluatingLinkLibraries()
            || dagCheckerParent->EvaluatingSources()))
986
987
988
        {
        reportError(context, content->GetOriginalExpression(),
            "LINKER_LANGUAGE target property can not be used while evaluating "
989
            "link libraries for a static library");
990
991
        return std::string();
        }
992
      return target->GetLinkerLanguage(context->Config);
993
994
      }

995
996
997
998
999
1000
    cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
                                               target->GetName(),
                                               propertyName,
                                               content,
                                               dagCheckerParent);

1001
    switch (dagChecker.Check())
1002
      {
1003
    case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
1004
      dagChecker.ReportError(context, content->GetOriginalExpression());
1005
      return std::string();
1006
1007
1008
    case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
      // No error. We just skip cyclic references.
      return std::string();
1009
    case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
1010
      for (size_t i = 1;
1011
          i < cmArraySize(targetPropertyTransitiveWhitelist);
1012
1013
1014
1015
1016
1017
1018
1019
          ++i)
        {
        if (targetPropertyTransitiveWhitelist[i] == propertyName)
          {
          // No error. We're not going to find anything new here.
          return std::string();
          }
        }
1020
1021
    case cmGeneratorExpressionDAGChecker::DAG:
      break;
1022
1023
      }

Stephen Kelly's avatar
Stephen Kelly committed
1024
    const char *prop = target->GetProperty(propertyName);
1025
1026

    if (dagCheckerParent)
1027
      {
1028
      if (dagCheckerParent->EvaluatingLinkLibraries())
1029
        {
1030
1031
1032
1033
        if(!prop)
          {
          return std::string();
          }
1034
        }
1035
      else
1036
        {
1037
1038
1039
1040
1041
1042
1043
#define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) \
  dagCheckerParent->METHOD () ||

        assert(
          CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
                                            ASSERT_TRANSITIVE_PROPERTY_METHOD)
          false);
1044
        }
1045
#undef ASSERT_TRANSITIVE_PROPERTY_METHOD
1046
1047
1048
1049
1050
      }

    std::string linkedTargetsContent;

    std::string interfacePropertyName;
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
#define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
    if (propertyName == #prop || propertyName == "INTERFACE_" #prop) \
      { \
      interfacePropertyName = "INTERFACE_" #prop; \
      } \
    else

    CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
      // Note that the above macro terminates with an else
1061
1062
    /* else */ if (cmHasLiteralPrefix(propertyName.c_str(),
                           "COMPILE_DEFINITIONS_"))
1063
      {
1064
1065
1066
1067
1068
1069
      cmPolicies::PolicyStatus polSt =
                      context->Makefile->GetPolicyStatus(cmPolicies::CMP0043);
      if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
        {
        interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
        }
1070
      }
1071
#undef POPULATE_INTERFACE_PROPERTY_NAME
1072

1073
1074
    cmTarget const* headTarget = context->HeadTarget
                               ? context->HeadTarget : target;
1075

1076
1077
1078
1079
1080
    const char * const *transBegin =
                        cmArrayBegin(targetPropertyTransitiveWhitelist) + 1;
    const char * const *transEnd =
                        cmArrayEnd(targetPropertyTransitiveWhitelist);

1081
    if (std::find_if(transBegin, transEnd,
1082
                     cmStrCmp(propertyName)) != transEnd)
1083
      {
1084

1085
1086
1087
1088
      std::vector<cmTarget*> tgts;
      target->GetTransitivePropertyTargets(context->Config,
                                                 headTarget, tgts);
      if (!tgts.empty())
1089
        {
1090
        linkedTargetsContent =
1091
                  getLinkedTargetsContent(tgts, target,
1092
                                          headTarget,
1093
1094
                                          context, &dagChecker,
                                          interfacePropertyName);
1095
1096
        }
      }
1097
    else if (std::find_if(transBegin, transEnd,
1098
                          cmStrCmp(interfacePropertyName)) != transEnd)
1099
      {
1100
1101
1102
      const cmTarget::LinkImplementation *impl
          = target->GetLinkImplementationLibraries(context->Config,
                                                   headTarget);
1103
1104
1105
1106
      if(impl)
        {
        linkedTargetsContent =
                  getLinkedTargetsContent(impl->Libraries, target,
1107
                                          headTarget,
1108
1109
                                          context, &dagChecker,
                                          interfacePropertyName);
1110
1111
1112
        }
      }

1113
1114
1115
    linkedTargetsContent =
          cmGeneratorExpression::StripEmptyListElements(linkedTargetsContent);

1116
1117
    if (!prop)
      {
1118
1119
      if (target->IsImported()
          || target->GetType() == cmTarget::INTERFACE_LIBRARY)
1120
1121
        {
        return linkedTargetsContent;
1122
1123
1124
1125
        }
      if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
                                                       context->Config))
        {
1126
        context->HadContextSensitiveCondition = true;
1127
1128
1129
1130
        return target->GetLinkInterfaceDependentBoolProperty(
                                                propertyName,
                                                context->Config) ? "1" : "0";
        }
1131
1132
1133
      if (target->IsLinkInterfaceDependentStringProperty(propertyName,
                                                         context->Config))
        {
1134
        context->HadContextSensitiveCondition = true;
1135
1136
        const char *propContent =
                              target->GetLinkInterfaceDependentStringProperty(
1137
1138
                                                propertyName,
                                                context->Config);
1139
        return propContent ? propContent : "";
1140
        }
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
      if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
                                                         context->Config))
        {
        context->HadContextSensitiveCondition = true;
        const char *propContent =
                          target->GetLinkInterfaceDependentNumberMinProperty(
                                                propertyName,
                                                context->Config);
        return propContent ? propContent : "";
        }
      if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
                                                         context->Config))
        {
        context->HadContextSensitiveCondition = true;
        const char *propContent =
                          target->GetLinkInterfaceDependentNumberMaxProperty(
                                                propertyName,
                                                context->Config);
        return propContent ? propContent : "";
        }
1161

1162
      return linkedTargetsContent;
1163
1164
      }

1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
    if (!target->IsImported()
        && dagCheckerParent && !dagCheckerParent->EvaluatingLinkLibraries())
      {
      if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
                                                        context->Config))
        {
        context->HadContextSensitiveCondition = true;
        const char *propContent =
                            target->GetLinkInterfaceDependentNumberMinProperty(
                                                propertyName,
                                                context->Config);
        return propContent ? propContent : "";
        }
      if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
                                                        context->Config))
        {
        context->HadContextSensitiveCondition = true;
        const char *propContent =
                            target->GetLinkInterfaceDependentNumberMaxProperty(
                                                propertyName,
                                                context->Config);
        return propContent ? propContent : "";
        }
      }
1189
    for (size_t i = 1;
1190
         i < cmArraySize(targetPropertyTransitiveWhitelist);
1191
1192
         ++i)
      {
1193
      if (targetPropertyTransitiveWhitelist[i] == interfacePropertyName)
1194
        {
1195
        cmGeneratorExpression ge(&context->Backtrace);
1196
1197
        cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
        std::string result = cge->Evaluate(context->Makefile,
1198
1199
                            context->Config,
                            context->Quiet,
1200
                            headTarget,
1201
1202
                            target,
                            &dagChecker);
1203
1204
1205
1206
1207

        if (cge->GetHadContextSensitiveCondition())
          {
          context->HadContextSensitiveCondition = true;
          }
1208
1209
1210
1211
        if (!linkedTargetsContent.empty())
          {
          result += (result.empty() ? "" : ";") + linkedTargetsContent;
          }
1212
        return result;
1213
1214
1215
        }
      }
    return prop;
1216
1217
1218
  }
} targetPropertyNode;

1219
1220
1221
1222
1223
1224
1225
//----------------------------------------------------------------------------
static const struct TargetNameNode : public cmGeneratorExpressionNode
{
  TargetNameNode() {}

  virtual bool GeneratesContent() const { return true; }

1226
  virtual bool AcceptsArbitraryContentParameter() const { return true; }
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
  virtual bool RequiresLiteralInput() const { return true; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *,
                       const GeneratorExpressionContent *,
                       cmGeneratorExpressionDAGChecker *) const
  {
    return parameters.front();
  }

  virtual int NumExpectedParameters() const { return 1; }

} targetNameNode;

1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
//----------------------------------------------------------------------------
static const struct TargetObjectsNode : public cmGeneratorExpressionNode
{
  TargetObjectsNode() {}

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *) const
  {
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
    if (!context->EvaluateForBuildsystem)
      {
      cmOStringStream e;
      e << "The evaluation of the TARGET_OBJECTS generator expression "
        "is only suitable for consumption by CMake.  It is not suitable "
        "for writing out elsewhere.";
      reportError(context, content->GetOriginalExpression(), e.str());
      return std::string();
      }

1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
    std::string tgtName = parameters.front();
    cmGeneratorTarget* gt =
                context->Makefile->FindGeneratorTargetToUse(tgtName.c_str());
    if (!gt)
      {
      cmOStringStream e;
      e << "Objects of target \"" << tgtName
        << "\" referenced but no such target exists.";
      reportError(context, content->GetOriginalExpression(), e.str());
      return std::string();
      }
    if (gt->GetType() != cmTarget::OBJECT_LIBRARY)
      {
      cmOStringStream e;
      e << "Objects of target \"" << tgtName
        << "\" referenced but is not an OBJECT library.";
      reportError(context, content->GetOriginalExpression(), e.str());
      return std::string();
      }

    std::vector<cmSourceFile const*> objectSources;
1282
    gt->GetObjectSources(objectSources, context->Config);
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
    std::map<cmSourceFile const*, std::string> mapping;

    for(std::vector<cmSourceFile const*>::const_iterator it
        = objectSources.begin(); it != objectSources.end(); ++it)
      {
      mapping[*it];
      }

    gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);

    std::string obj_dir = gt->ObjectDirectory;
    std::string result;
    const char* sep = "";
    for(std::map<cmSourceFile const*, std::string>::const_iterator it
        = mapping.begin(); it != mapping.end(); ++it)
      {
      assert(!it->second.empty());
      result += sep;
      std::string objFile = obj_dir + it->second;
      cmSourceFile* sf = context->Makefile->GetOrCreateSource(objFile, true);
      sf->SetObjectLibrary(tgtName);
      sf->SetProperty("EXTERNAL_OBJECT", "1");
      result += objFile;
      sep = ";";
      }
    return result;
  }
} targetObjectsNode;

1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
//----------------------------------------------------------------------------
static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
{
  CompileFeaturesNode() {}

  virtual int NumExpectedParameters() const { return OneOrMoreParameters; }

  std::string Evaluate(const std::vector<std::string> &parameters,
                       cmGeneratorExpressionContext *context,
                       const GeneratorExpressionContent *content,
                       cmGeneratorExpressionDAGChecker *dagChecker) const
  {
    cmTarget const* target = context->HeadTarget;
    if (!target)
      {
      reportError(context, content->GetOriginalExpression(),
          "$<COMPILE_FEATURE> may only be used with binary targets.  It may "
          "not be used with add_custom_command or add_custom_target.");
      return std::string();
      }

    typedef std::map<std::string, std::vector<std::string> > LangMap;
    static LangMap availableFeatures;

    LangMap testedFeatures;

    for (std::vector<std::string>::const_iterator it = parameters.begin();
        it != parameters.end(); ++it)
      {
      std::string error;
      std::string lang;
      if (!context->Makefile->CompileFeatureKnown(context->HeadTarget,
                                                  *it, lang, &error))
        {
        reportError(context, content->GetOriginalExpression(), error);
        return std::string();
        }
      testedFeatures[lang].push_back(*it);

      if (availableFeatures.find(lang) == availableFeatures.end())
        {
        const char* featuresKnown
                  = context->Makefile->CompileFeaturesAvailable(lang, &error);
        if (!featuresKnown)
          {
          reportError(context, content->GetOriginalExpression(), error);
          return std::string();
          }
        cmSystemTools::ExpandListArgument(featuresKnown,
                                          availableFeatures[lang]);
        }
      }

    bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();

    std::string result;

    for (LangMap::const_iterator lit = testedFeatures.begin();
          lit != testedFeatures.end(); ++lit)
      {
      for (std::vector<std::string>::const_iterator it = lit->second.begin();
          it != lit->second.end(); ++it)
        {
        if (!context->Makefile->HaveFeatureAvailable(target,
                                                      lit->first, *it))
          {
          if (evalLL)
            {
            const char* l = target->GetProperty(lit->first + "_STANDARD");
            if (!l)
              {
              l = context->Makefile
                  ->GetDefinition("CMAKE_" + lit->first + "_STANDARD_DEFAULT");
              }
            assert(l);
            context->MaxLanguageStandard[target][lit->first] = l;
            }
          else
            {
            return "0";
            }
          }
        }
      }
    return "1";
  }
} compileFeaturesNode;

1400
1401
//----------------------------------------------------------------------------
static const char* targetPolicyWhitelist[] = {
1402
1403
1404
1405
1406
1407
1408
  0
#define TARGET_POLICY_STRING(POLICY) \
  , #POLICY

  CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)

#undef TARGET_POLICY_STRING
1409
1410
};

1411
1412
cmPolicies::PolicyStatus statusForTarget(cmTarget const* tgt,
                                         const char *policy)
1413
1414
1415
1416
1417
1418
1419
{
#define RETURN_POLICY(POLICY) \
  if (strcmp(policy, #POLICY) == 0) \
  { \
    return tgt->GetPolicyStatus ## POLICY (); \
  } \

1420
  CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435

#undef RETURN_POLICY

  assert("!Unreachable code. Not a valid policy");
  return cmPolicies::WARN;
}

cmPolicies::PolicyID policyForString(const char *policy_id)
{
#define RETURN_POLICY_ID(POLICY_ID) \
  if (strcmp(policy_id, #POLICY_ID) == 0) \
  { \
    return cmPolicies:: POLICY_ID; \
  } \

1436
  CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458

#undef RETURN_POLICY_ID

  assert("!Unreachable code. Not a valid policy");
  return cmPolicies::CMP0002;
}

//----------------------------------------------------------------------------
static const struct TargetPolicyNode : public cmGeneratorExpressionNode
{
  TargetPolicyNode() {}

  virtual int Num