[Cmake-commits] CMake branch, next, updated. v2.8.11.1-2761-g9dc0fe3

Stephen Kelly steveire at gmail.com
Wed Jun 26 09:27:32 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  9dc0fe3b145404a2b4bebb9cbf4d181d6c4cc48d (commit)
       via  5d033a4c7362eb55819123111060d7b97ea67e9c (commit)
      from  8398d4ff959fb9d90d1a33a3c0ea13df6b3b4d65 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9dc0fe3b145404a2b4bebb9cbf4d181d6c4cc48d
commit 9dc0fe3b145404a2b4bebb9cbf4d181d6c4cc48d
Merge: 8398d4f 5d033a4
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Jun 26 09:27:31 2013 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Jun 26 09:27:31 2013 -0400

    Merge topic 'compiler-version-genex' into next
    
    5d033a4 Add generator expressions for compiler versions.


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=5d033a4c7362eb55819123111060d7b97ea67e9c
commit 5d033a4c7362eb55819123111060d7b97ea67e9c
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Jun 11 10:48:47 2013 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Jun 26 15:26:00 2013 +0200

    Add generator expressions for compiler versions.
    
    New generator expressions allow retrieval of the version per language,
    as well as equality comparison.

diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h
index 7358a36..4caaabf 100644
--- a/Source/cmDocumentGeneratorExpressions.h
+++ b/Source/cmDocumentGeneratorExpressions.h
@@ -54,6 +54,14 @@
   "else '0'.\n"                                                         \
   "  $<VERSION_EQUAL:v1,v2>    = '1' if v1 is the same version as v2, " \
   "else '0'.\n"                                                         \
+  "  $<C_COMPILER_VERSION>     = The CMake-id of the C compiler "       \
+  "used.\n"                                                             \
+  "  $<C_COMPILER_VERSION:ver> = '1' if the CMake-id of the C "         \
+  "compiler matches ver, otherwise '0'.\n"                              \
+  "  $<CXX_COMPILER_VERSION>   = The CMake-id of the CXX compiler "     \
+  "used.\n"                                                             \
+  "  $<CXX_COMPILER_VERSION:ver> = '1' if the CMake-id 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..72927db 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -396,6 +396,101 @@ static const struct VersionEqualNode : public cmGeneratorExpressionNode
 } versionEqualNode;
 
 //----------------------------------------------------------------------------
+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 ConfigurationNode : public cmGeneratorExpressionNode
 {
   ConfigurationNode() {}
@@ -1247,6 +1342,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")
diff --git a/Tests/CompileOptions/CMakeLists.txt b/Tests/CompileOptions/CMakeLists.txt
index 6d8a96a..4de2883 100644
--- a/Tests/CompileOptions/CMakeLists.txt
+++ b/Tests/CompileOptions/CMakeLists.txt
@@ -5,12 +5,27 @@ project(CompileOptions)
 add_library(testlib other.cpp)
 
 add_executable(CompileOptions main.cpp)
-set_property(TARGET CompileOptions PROPERTY COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE>")
+
+macro(get_compiler_test_genex string lang)
+  set(${string} "-DTEST_${lang}_COMPILER_VERSION=\\\"$<${lang}_COMPILER_VERSION>\\\"")
+  set(${string} "${${string}};-DTEST_${lang}_COMPILER_VERSION_EQUALITY=$<${lang}_COMPILER_VERSION:${CMAKE_${lang}_COMPILER_VERSION}>")
+endmacro()
+
+get_compiler_test_genex(c_tests C)
+get_compiler_test_genex(cxx_tests CXX)
+
+set_property(TARGET CompileOptions PROPERTY
+  COMPILE_OPTIONS
+    "$<$<C_COMPILER_ID:GNU>:${c_tests}>"
+    "$<$<CXX_COMPILER_ID:GNU>:-DTEST_DEFINE;${cxx_tests}>"
+)
 target_link_libraries(CompileOptions testlib)
 
 if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
   target_compile_definitions(CompileOptions
     PRIVATE
       "DO_GNU_TESTS"
+      "EXPECTED_C_COMPILER_VERSION=\"${CMAKE_C_COMPILER_VERSION}\""
+      "EXPECTED_CXX_COMPILER_VERSION=\"${CMAKE_CXX_COMPILER_VERSION}\""
   )
 endif()
diff --git a/Tests/CompileOptions/main.cpp b/Tests/CompileOptions/main.cpp
index 0d39050..046f5a1 100644
--- a/Tests/CompileOptions/main.cpp
+++ b/Tests/CompileOptions/main.cpp
@@ -5,7 +5,15 @@
 #  endif
 #endif
 
+#include <cstring>
+
 int main(int argc, char **argv)
 {
+#ifdef DO_GNU_TESTS
+  return (strcmp(EXPECTED_C_COMPILER_VERSION, TEST_C_COMPILER_VERSION) == 0
+      && strcmp(EXPECTED_CXX_COMPILER_VERSION, TEST_CXX_COMPILER_VERSION) == 0
+      && TEST_C_COMPILER_VERSION_EQUALITY == 1
+      && TEST_CXX_COMPILER_VERSION_EQUALITY == 1) ? 0 : 1;
+#endif
   return 0;
 }

-----------------------------------------------------------------------

Summary of changes:
 Source/cmDocumentGeneratorExpressions.h   |    8 +++
 Source/cmGeneratorExpressionEvaluator.cxx |   99 +++++++++++++++++++++++++++++
 Tests/CompileOptions/CMakeLists.txt       |   17 +++++-
 Tests/CompileOptions/main.cpp             |    8 +++
 4 files changed, 131 insertions(+), 1 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list