245
249
//----------------------------------------------------------------------------
250
struct CompilerIdNode : public cmGeneratorExpressionNode
254
virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; }
256
std::string EvaluateWithLanguage(const std::vector<std::string> ¶meters,
257
cmGeneratorExpressionContext *context,
258
const GeneratorExpressionContent *content,
259
cmGeneratorExpressionDAGChecker *,
260
const std::string &lang) const
262
const char *compilerId = context->Makefile ?
263
context->Makefile->GetSafeDefinition((
264
"CMAKE_" + lang + "_COMPILER_ID").c_str()) : "";
265
if (parameters.size() == 0)
267
return compilerId ? compilerId : "";
269
cmsys::RegularExpression compilerIdValidator;
270
compilerIdValidator.compile("^[A-Za-z0-9_]*$");
271
if (!compilerIdValidator.find(parameters.begin()->c_str()))
273
reportError(context, content->GetOriginalExpression(),
274
"Expression syntax not recognized.");
275
return std::string();
279
return parameters.front().empty() ? "1" : "0";
282
if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0)
290
//----------------------------------------------------------------------------
291
static const struct CCompilerIdNode : public CompilerIdNode
295
std::string Evaluate(const std::vector<std::string> ¶meters,
296
cmGeneratorExpressionContext *context,
297
const GeneratorExpressionContent *content,
298
cmGeneratorExpressionDAGChecker *dagChecker) const
300
if (parameters.size() != 0 && parameters.size() != 1)
302
reportError(context, content->GetOriginalExpression(),
303
"$<C_COMPILER_ID> expression requires one or two parameters");
304
return std::string();
306
if (!context->HeadTarget)
308
reportError(context, content->GetOriginalExpression(),
309
"$<C_COMPILER_ID> may only be used with targets. It may not "
310
"be used with add_custom_command.");
312
return this->EvaluateWithLanguage(parameters, context, content,
317
//----------------------------------------------------------------------------
318
static const struct CXXCompilerIdNode : public CompilerIdNode
320
CXXCompilerIdNode() {}
322
std::string Evaluate(const std::vector<std::string> ¶meters,
323
cmGeneratorExpressionContext *context,
324
const GeneratorExpressionContent *content,
325
cmGeneratorExpressionDAGChecker *dagChecker) const
327
if (parameters.size() != 0 && parameters.size() != 1)
329
reportError(context, content->GetOriginalExpression(),
330
"$<CXX_COMPILER_ID> expression requires one or two parameters");
331
return std::string();
333
if (!context->HeadTarget)
335
reportError(context, content->GetOriginalExpression(),
336
"$<CXX_COMPILER_ID> may only be used with targets. It may not "
337
"be used with add_custom_command.");
339
return this->EvaluateWithLanguage(parameters, context, content,
344
//----------------------------------------------------------------------------
345
struct CompilerVersionNode : public cmGeneratorExpressionNode
347
CompilerVersionNode() {}
349
virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; }
351
std::string EvaluateWithLanguage(const std::vector<std::string> ¶meters,
352
cmGeneratorExpressionContext *context,
353
const GeneratorExpressionContent *content,
354
cmGeneratorExpressionDAGChecker *,
355
const std::string &lang) const
357
const char *compilerVersion = context->Makefile ?
358
context->Makefile->GetSafeDefinition((
359
"CMAKE_" + lang + "_COMPILER_VERSION").c_str()) : "";
360
if (parameters.size() == 0)
362
return compilerVersion ? compilerVersion : "";
365
cmsys::RegularExpression compilerIdValidator;
366
compilerIdValidator.compile("^[0-9\\.]*$");
367
if (!compilerIdValidator.find(parameters.begin()->c_str()))
369
reportError(context, content->GetOriginalExpression(),
370
"Expression syntax not recognized.");
371
return std::string();
373
if (!compilerVersion)
375
return parameters.front().empty() ? "1" : "0";
378
return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
379
parameters.begin()->c_str(),
380
compilerVersion) ? "1" : "0";
384
//----------------------------------------------------------------------------
385
static const struct CCompilerVersionNode : public CompilerVersionNode
387
CCompilerVersionNode() {}
389
std::string Evaluate(const std::vector<std::string> ¶meters,
390
cmGeneratorExpressionContext *context,
391
const GeneratorExpressionContent *content,
392
cmGeneratorExpressionDAGChecker *dagChecker) const
394
if (parameters.size() != 0 && parameters.size() != 1)
396
reportError(context, content->GetOriginalExpression(),
397
"$<C_COMPILER_VERSION> expression requires one or two parameters");
398
return std::string();
400
if (!context->HeadTarget)
402
reportError(context, content->GetOriginalExpression(),
403
"$<C_COMPILER_VERSION> may only be used with targets. It may not "
404
"be used with add_custom_command.");
406
return this->EvaluateWithLanguage(parameters, context, content,
409
} cCompilerVersionNode;
411
//----------------------------------------------------------------------------
412
static const struct CxxCompilerVersionNode : public CompilerVersionNode
414
CxxCompilerVersionNode() {}
416
std::string Evaluate(const std::vector<std::string> ¶meters,
417
cmGeneratorExpressionContext *context,
418
const GeneratorExpressionContent *content,
419
cmGeneratorExpressionDAGChecker *dagChecker) const
421
if (parameters.size() != 0 && parameters.size() != 1)
423
reportError(context, content->GetOriginalExpression(),
424
"$<CXX_COMPILER_VERSION> expression requires one or two "
426
return std::string();
428
if (!context->HeadTarget)
430
reportError(context, content->GetOriginalExpression(),
431
"$<CXX_COMPILER_VERSION> may only be used with targets. It may "
432
"not be used with add_custom_command.");
434
return this->EvaluateWithLanguage(parameters, context, content,
437
} cxxCompilerVersionNode;
440
//----------------------------------------------------------------------------
441
static const struct VersionGreaterNode : public cmGeneratorExpressionNode
443
VersionGreaterNode() {}
445
virtual int NumExpectedParameters() const { return 2; }
447
std::string Evaluate(const std::vector<std::string> ¶meters,
448
cmGeneratorExpressionContext *,
449
const GeneratorExpressionContent *,
450
cmGeneratorExpressionDAGChecker *) const
452
return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER,
453
parameters.front().c_str(),
454
parameters[1].c_str()) ? "1" : "0";
456
} versionGreaterNode;
458
//----------------------------------------------------------------------------
459
static const struct VersionLessNode : public cmGeneratorExpressionNode
463
virtual int NumExpectedParameters() const { return 2; }
465
std::string Evaluate(const std::vector<std::string> ¶meters,
466
cmGeneratorExpressionContext *,
467
const GeneratorExpressionContent *,
468
cmGeneratorExpressionDAGChecker *) const
470
return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
471
parameters.front().c_str(),
472
parameters[1].c_str()) ? "1" : "0";
476
//----------------------------------------------------------------------------
477
static const struct VersionEqualNode : public cmGeneratorExpressionNode
479
VersionEqualNode() {}
481
virtual int NumExpectedParameters() const { return 2; }
483
std::string Evaluate(const std::vector<std::string> ¶meters,
484
cmGeneratorExpressionContext *,
485
const GeneratorExpressionContent *,
486
cmGeneratorExpressionDAGChecker *) const
488
return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
489
parameters.front().c_str(),
490
parameters[1].c_str()) ? "1" : "0";
494
//----------------------------------------------------------------------------
495
static const struct LinkOnlyNode : public cmGeneratorExpressionNode
499
std::string Evaluate(const std::vector<std::string> ¶meters,
500
cmGeneratorExpressionContext *,
501
const GeneratorExpressionContent *,
502
cmGeneratorExpressionDAGChecker *dagChecker) const
504
if(!dagChecker->GetTransitivePropertiesOnly())
506
return parameters.front();
512
//----------------------------------------------------------------------------
246
513
static const struct ConfigurationNode : public cmGeneratorExpressionNode
248
515
ConfigurationNode() {}
297
564
const char* loc = 0;
298
565
const char* imp = 0;
299
566
std::string suffix;
300
return context->CurrentTarget->GetMappedConfig(context->Config,
567
if (context->CurrentTarget->GetMappedConfig(context->Config,
572
// This imported target has an appropriate location
573
// for this (possibly mapped) config.
574
// Check if there is a proper config mapping for the tested config.
575
std::vector<std::string> mappedConfigs;
576
std::string mapProp = "MAP_IMPORTED_CONFIG_";
577
mapProp += cmSystemTools::UpperCase(context->Config);
578
if(const char* mapValue =
579
context->CurrentTarget->GetProperty(mapProp.c_str()))
581
cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
583
return std::find(mappedConfigs.begin(), mappedConfigs.end(),
584
cmSystemTools::UpperCase(parameters.front()))
585
!= mappedConfigs.end() ? "1" : "0";
307
591
} configurationTestNode;
593
static const struct JoinNode : public cmGeneratorExpressionNode
597
virtual int NumExpectedParameters() const { return 2; }
599
virtual bool AcceptsArbitraryContentParameter() const { return true; }
601
std::string Evaluate(const std::vector<std::string> ¶meters,
602
cmGeneratorExpressionContext *,
603
const GeneratorExpressionContent *,
604
cmGeneratorExpressionDAGChecker *) const
608
std::vector<std::string> list;
609
cmSystemTools::ExpandListArgument(parameters.front(), list);
611
for(std::vector<std::string>::const_iterator li = list.begin();
612
li != list.end(); ++li)
621
#define TRANSITIVE_PROPERTY_NAME(PROPERTY) \
310
624
//----------------------------------------------------------------------------
311
625
static const char* targetPropertyTransitiveWhitelist[] = {
312
"INTERFACE_INCLUDE_DIRECTORIES"
313
, "INTERFACE_COMPILE_DEFINITIONS"
627
CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
316
630
std::string getLinkedTargetsContent(const std::vector<std::string> &libraries,