summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-06-11 08:48:47 (GMT)
committerStephen Kelly <steveire@gmail.com>2013-06-28 12:32:58 (GMT)
commit47a8db5bcd1907c45552ad267ee8f11427a1c8f2 (patch)
tree9ecf8ed4b0ab060f8805f00d35fa537784078e31 /Source
parentd221eac81261679d3580849218220290fcd122df (diff)
downloadCMake-47a8db5bcd1907c45552ad267ee8f11427a1c8f2.zip
CMake-47a8db5bcd1907c45552ad267ee8f11427a1c8f2.tar.gz
CMake-47a8db5bcd1907c45552ad267ee8f11427a1c8f2.tar.bz2
Add generator expressions for compiler versions.
New generator expressions allow retrieval of the version per language, as well as equality comparison.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmDocumentGeneratorExpressions.h7
-rw-r--r--Source/cmGeneratorExpressionEvaluator.cxx100
2 files changed, 107 insertions, 0 deletions
diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h
index 7358a36..841061c 100644
--- a/Source/cmDocumentGeneratorExpressions.h
+++ b/Source/cmDocumentGeneratorExpressions.h
@@ -54,6 +54,13 @@
"else '0'.\n" \
" $<VERSION_EQUAL:v1,v2> = '1' if v1 is the same version as v2, " \
"else '0'.\n" \
+ " $<C_COMPILER_VERSION> = The version of the C compiler used.\n" \
+ " $<C_COMPILER_VERSION:ver> = '1' if the version of the C " \
+ "compiler matches ver, otherwise '0'.\n" \
+ " $<CXX_COMPILER_VERSION> = The version of the CXX compiler " \
+ "used.\n" \
+ " $<CXX_COMPILER_VERSION:ver> = '1' if the version of the CXX " \
+ "compiler matches ver, otherwise '0'.\n" \
" $<TARGET_FILE:tgt> = main file (.exe, .so.1.2, .a)\n" \
" $<TARGET_LINKER_FILE:tgt> = file used to link (.a, .lib, .so)\n" \
" $<TARGET_SONAME_FILE:tgt> = file with soname (.so.3)\n" \
diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx
index 037ef31..05bbc1c 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -342,6 +342,102 @@ static const struct CXXCompilerIdNode : public CompilerIdNode
} cxxCompilerIdNode;
//----------------------------------------------------------------------------
+struct CompilerVersionNode : public cmGeneratorExpressionNode
+{
+ CompilerVersionNode() {}
+
+ virtual int NumExpectedParameters() const { return ZeroOrMoreParameters; }
+
+ 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 ?
+ context->Makefile->GetSafeDefinition((
+ "CMAKE_" + lang + "_COMPILER_VERSION").c_str()) : "";
+ if (parameters.size() == 0)
+ {
+ return compilerVersion ? compilerVersion : "";
+ }
+
+ cmsys::RegularExpression compilerIdValidator;
+ compilerIdValidator.compile("^[0-9\\.]*$");
+ if (!compilerIdValidator.find(parameters.begin()->c_str()))
+ {
+ 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 (parameters.size() != 0 && parameters.size() != 1)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<C_COMPILER_VERSION> expression requires one or two parameters");
+ return std::string();
+ }
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<C_COMPILER_VERSION> may only be used with targets. It may not "
+ "be used with add_custom_command.");
+ }
+ 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 (parameters.size() != 0 && parameters.size() != 1)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<CXX_COMPILER_VERSION> expression requires one or two "
+ "parameters");
+ return std::string();
+ }
+ if (!context->HeadTarget)
+ {
+ reportError(context, content->GetOriginalExpression(),
+ "$<CXX_COMPILER_VERSION> may only be used with targets. It may "
+ "not be used with add_custom_command.");
+ }
+ return this->EvaluateWithLanguage(parameters, context, content,
+ dagChecker, "CXX");
+ }
+} cxxCompilerVersionNode;
+
+
+//----------------------------------------------------------------------------
static const struct VersionGreaterNode : public cmGeneratorExpressionNode
{
VersionGreaterNode() {}
@@ -1247,6 +1343,10 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
return &versionLessNode;
else if (identifier == "VERSION_EQUAL")
return &versionEqualNode;
+ else if (identifier == "C_COMPILER_VERSION")
+ return &cCompilerVersionNode;
+ else if (identifier == "CXX_COMPILER_VERSION")
+ return &cxxCompilerVersionNode;
else if (identifier == "CONFIGURATION")
return &configurationNode;
else if (identifier == "CONFIG")