summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorExpressionEvaluator.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-05-16 13:52:25 (GMT)
committerBrad King <brad.king@kitware.com>2013-05-24 13:06:53 (GMT)
commit32410140a7c592090249db772fd5f18c7808a3aa (patch)
tree055e13759b3d6a1a7d67311c3f0fcb609c5adcdb /Source/cmGeneratorExpressionEvaluator.cxx
parenta7ba4520c7b15dc9f56d2c4718748b79b12c0c89 (diff)
downloadCMake-32410140a7c592090249db772fd5f18c7808a3aa.zip
CMake-32410140a7c592090249db772fd5f18c7808a3aa.tar.gz
CMake-32410140a7c592090249db772fd5f18c7808a3aa.tar.bz2
Add $<LINK_LANGUAGE> generator expression
They can't be used when evaluating link libraries, but they can be used for include directories and compile definitions. Later they can be used for compile options.
Diffstat (limited to 'Source/cmGeneratorExpressionEvaluator.cxx')
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx72
1 files changed, 67 insertions, 5 deletions
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index 6092aa2..7870d37 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -45,6 +45,11 @@ void reportError(cmGeneratorExpressionContext *context,
//----------------------------------------------------------------------------
struct cmGeneratorExpressionNode
{
+ enum {
+ DynamicParameters = 0,
+ OneOrMoreParameters = -1,
+ ZeroOrMoreParameters = -2
+ };
virtual ~cmGeneratorExpressionNode() {}
virtual bool GeneratesContent() const { return true; }
@@ -110,8 +115,7 @@ static const struct ZeroNode installInterfaceNode;
static const struct OP ## Node : public cmGeneratorExpressionNode \
{ \
OP ## Node () {} \
-/* We let -1 carry the meaning 'at least one' */ \
- virtual int NumExpectedParameters() const { return -1; } \
+ virtual int NumExpectedParameters() const { return OneOrMoreParameters; } \
\
std::string Evaluate(const std::vector<std::string> &parameters, \
cmGeneratorExpressionContext *context, \
@@ -306,6 +310,60 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
}
} configurationTestNode;
+//----------------------------------------------------------------------------
+static const struct LinkLanguageNode : public cmGeneratorExpressionNode
+{
+ LinkLanguageNode() {}
+
+ virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; }
+
+ std::string Evaluate(const std::vector<std::string> &parameters,
+ cmGeneratorExpressionContext *context,
+ const GeneratorExpressionContent *content,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ if (parameters.size() != 0 && parameters.size() != 1)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<LINK_LANGUAGE> expression requires one or two parameters");
+ return std::string();
+ }
+ cmTarget* target = context->HeadTarget;
+ if (!target)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<LINK_LANGUAGE> may only be used with targets. It may not "
+ "be used with add_custom_command.");
+ }
+
+ const char *lang = target->GetLinkerLanguage(context->Config);
+ if (parameters.size() == 0)
+ {
+ return lang ? lang : "";
+ }
+ else
+ {
+ cmsys::RegularExpression langValidator;
+ langValidator.compile("^[A-Za-z0-9_]*$");
+ if (!langValidator.find(parameters.begin()->c_str()))
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "Expression syntax not recognized.");
+ return std::string();
+ }
+ if (!lang)
+ {
+ return parameters.front().empty() ? "1" : "0";
+ }
+
+ if (strcmp(parameters.begin()->c_str(), lang) == 0)
+ {
+ return "1";
+ }
+ return "0";
+ }
+ }
+} linkLanguageNode;
static const struct JoinNode : public cmGeneratorExpressionNode
{
@@ -347,7 +405,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode
TargetPropertyNode() {}
// This node handles errors on parameter count itself.
- virtual int NumExpectedParameters() const { return -1; }
+ virtual int NumExpectedParameters() const { return OneOrMoreParameters; }
std::string Evaluate(const std::vector<std::string> &parameters,
cmGeneratorExpressionContext *context,
@@ -961,6 +1019,8 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
return &configurationNode;
else if (identifier == "CONFIG")
return &configurationTestNode;
+ else if (identifier == "LINK_LANGUAGE")
+ return &linkLanguageNode;
else if (identifier == "TARGET_FILE")
return &targetFileNode;
else if (identifier == "TARGET_LINKER_FILE")
@@ -1188,7 +1248,8 @@ std::string GeneratorExpressionContent::EvaluateParameters(
}
}
- if ((numExpected != -1 && (unsigned int)numExpected != parameters.size()))
+ if ((numExpected > cmGeneratorExpressionNode::DynamicParameters
+ && (unsigned int)numExpected != parameters.size()))
{
if (numExpected == 0)
{
@@ -1213,7 +1274,8 @@ std::string GeneratorExpressionContent::EvaluateParameters(
return std::string();
}
- if (numExpected == -1 && parameters.empty())
+ if (numExpected == cmGeneratorExpressionNode::OneOrMoreParameters
+ && parameters.empty())
{
reportError(context, this->GetOriginalExpression(), "$<" + identifier
+ "> expression requires at least one parameter.");