[Cmake-commits] CMake branch, next, updated. v2.8.11.1-2610-g2d8245c
Stephen Kelly
steveire at gmail.com
Wed Jun 12 08:10:15 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 2d8245cbae9007976570b903d5cb185166e397f1 (commit)
via e5df6630d75ca6003897490426b2a6d2e61ed73c (commit)
via e6055284b347775ae1396725704778af0bfb56c7 (commit)
via 48bb48e114b7141b63e9c905f0258531c6b78cb1 (commit)
from dfc01051fc5733a48e5ddabecbb587d451f19864 (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=2d8245cbae9007976570b903d5cb185166e397f1
commit 2d8245cbae9007976570b903d5cb185166e397f1
Merge: dfc0105 e5df663
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Jun 12 08:10:12 2013 -0400
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Jun 12 08:10:12 2013 -0400
Merge topic 'version-compare-genex' into next
e5df663 Add generator expressions for compiler versions.
e605528 Add generator expressions for version comparision.
48bb48e De-duplicate version comparison code.
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e5df6630d75ca6003897490426b2a6d2e61ed73c
commit e5df6630d75ca6003897490426b2a6d2e61ed73c
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 12 14:09:36 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 84f4af5..a6c610b 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 1804691..1e79758 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -399,6 +399,105 @@ 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> ¶meters,
+ 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";
+ }
+
+ if (cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
+ parameters.begin()->c_str(),
+ compilerVersion) == 0)
+ {
+ return "1";
+ }
+ return "0";
+ }
+};
+
+//----------------------------------------------------------------------------
+static const struct CCompilerVersionNode : public CompilerVersionNode
+{
+ CCompilerVersionNode() {}
+
+ std::string Evaluate(const std::vector<std::string> ¶meters,
+ 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> ¶meters,
+ 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() {}
@@ -1229,6 +1328,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..aa45893 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)
+ && strcmp(EXPECTED_CXX_COMPILER_VERSION, TEST_CXX_COMPILER_VERSION)
+ && TEST_C_COMPILER_VERSION_EQUALITY
+ && TEST_CXX_COMPILER_VERSION_EQUALITY;
+#endif
return 0;
}
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=e6055284b347775ae1396725704778af0bfb56c7
commit e6055284b347775ae1396725704778af0bfb56c7
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Jun 11 09:53:10 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Jun 12 14:09:36 2013 +0200
Add generator expressions for version comparision.
diff --git a/Source/cmDocumentGeneratorExpressions.h b/Source/cmDocumentGeneratorExpressions.h
index a8b3847..84f4af5 100644
--- a/Source/cmDocumentGeneratorExpressions.h
+++ b/Source/cmDocumentGeneratorExpressions.h
@@ -48,6 +48,12 @@
"used.\n" \
" $<CXX_COMPILER_ID:comp> = '1' if the CMake-id of the CXX " \
"compiler matches comp, otherwise '0'.\n" \
+ " $<VERSION_GREATER:v1,v2> = '1' if v1 is a version greater than " \
+ "v2, else '0'.\n" \
+ " $<VERSION_LESS:v1,v2> = '1' if v1 is a version less than v2, " \
+ "else '0'.\n" \
+ " $<VERSION_EQUAL:v1,v2> = '1' if v1 is the same version as v2, " \
+ "else '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 28f749d..1804691 100644
--- a/Source/cmGeneratorExpressionEvaluator.cxx
+++ b/Source/cmGeneratorExpressionEvaluator.cxx
@@ -345,6 +345,60 @@ static const struct CXXCompilerIdNode : public CompilerIdNode
} cxxCompilerIdNode;
//----------------------------------------------------------------------------
+static const struct VersionGreaterNode : public cmGeneratorExpressionNode
+{
+ VersionGreaterNode() {}
+
+ virtual int NumExpectedParameters() const { return 2; }
+
+ std::string Evaluate(const std::vector<std::string> ¶meters,
+ 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> ¶meters,
+ 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> ¶meters,
+ cmGeneratorExpressionContext *,
+ const GeneratorExpressionContent *,
+ cmGeneratorExpressionDAGChecker *) const
+ {
+ return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
+ parameters.front().c_str(),
+ parameters[1].c_str()) ? "1" : "0";
+ }
+} versionEqualNode;
+
+//----------------------------------------------------------------------------
static const struct ConfigurationNode : public cmGeneratorExpressionNode
{
ConfigurationNode() {}
@@ -1169,6 +1223,12 @@ cmGeneratorExpressionNode* GetNode(const std::string &identifier)
return &cCompilerIdNode;
else if (identifier == "CXX_COMPILER_ID")
return &cxxCompilerIdNode;
+ else if (identifier == "VERSION_GREATER")
+ return &versionGreaterNode;
+ else if (identifier == "VERSION_LESS")
+ return &versionLessNode;
+ else if (identifier == "VERSION_EQUAL")
+ return &versionEqualNode;
else if (identifier == "CONFIGURATION")
return &configurationNode;
else if (identifier == "CONFIG")
diff --git a/Tests/GeneratorExpression/CMakeLists.txt b/Tests/GeneratorExpression/CMakeLists.txt
index 9cd8a7f..e2fc353 100644
--- a/Tests/GeneratorExpression/CMakeLists.txt
+++ b/Tests/GeneratorExpression/CMakeLists.txt
@@ -130,6 +130,12 @@ add_custom_target(check-part2 ALL
-Dtest_arbitrary_content_comma_8=$<1:a,,b>
-Dtest_arbitrary_content_comma_9=$<1:a,,b,,>
-Dtest_arbitrary_content_comma_10=$<1:,,a,,b,,>
+ -Dtest_version_greater_1=$<VERSION_GREATER:1.0,1.1.1>
+ -Dtest_version_greater_2=$<VERSION_GREATER:1.1.1,1.0>
+ -Dtest_version_less_1=$<VERSION_LESS:1.1.1,1.0>
+ -Dtest_version_less_2=$<VERSION_LESS:1.0,1.1.1>
+ -Dtest_version_equal_1=$<VERSION_EQUAL:1.0.1,1.1>
+ -Dtest_version_equal_2=$<VERSION_EQUAL:1.1,1.1>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check-part2.cmake
COMMAND ${CMAKE_COMMAND} -E echo "check done (part 2 of 2)"
VERBATIM
diff --git a/Tests/GeneratorExpression/check-part2.cmake b/Tests/GeneratorExpression/check-part2.cmake
index a1db5f6..f9b33b3 100644
--- a/Tests/GeneratorExpression/check-part2.cmake
+++ b/Tests/GeneratorExpression/check-part2.cmake
@@ -44,3 +44,9 @@ check(test_arbitrary_content_comma_7 ",,a")
check(test_arbitrary_content_comma_8 "a,,b")
check(test_arbitrary_content_comma_9 "a,,b,,")
check(test_arbitrary_content_comma_10 ",,a,,b,,")
+check(test_version_greater_1 "0")
+check(test_version_greater_2 "1")
+check(test_version_less_1 "0")
+check(test_version_less_2 "1")
+check(test_version_equal_1 "0")
+check(test_version_equal_2 "1")
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=48bb48e114b7141b63e9c905f0258531c6b78cb1
commit 48bb48e114b7141b63e9c905f0258531c6b78cb1
Author: Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Jun 11 09:56:02 2013 +0200
Commit: Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Jun 12 14:09:36 2013 +0200
De-duplicate version comparison code.
Extend the VersionCompare in cmSystemTools to handle 8 components,
and port the if command to use that.
diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx
index 56d7170..57cec5b 100644
--- a/Source/cmIfCommand.cxx
+++ b/Source/cmIfCommand.cxx
@@ -406,38 +406,6 @@ namespace
}
//=========================================================================
- enum Op { OpLess, OpEqual, OpGreater };
- bool HandleVersionCompare(Op op, const char* lhs_str, const char* rhs_str)
- {
- // Parse out up to 8 components.
- unsigned int lhs[8] = {0,0,0,0,0,0,0,0};
- unsigned int rhs[8] = {0,0,0,0,0,0,0,0};
- sscanf(lhs_str, "%u.%u.%u.%u.%u.%u.%u.%u",
- &lhs[0], &lhs[1], &lhs[2], &lhs[3],
- &lhs[4], &lhs[5], &lhs[6], &lhs[7]);
- sscanf(rhs_str, "%u.%u.%u.%u.%u.%u.%u.%u",
- &rhs[0], &rhs[1], &rhs[2], &rhs[3],
- &rhs[4], &rhs[5], &rhs[6], &rhs[7]);
-
- // Do component-wise comparison.
- for(unsigned int i=0; i < 8; ++i)
- {
- if(lhs[i] < rhs[i])
- {
- // lhs < rhs, so true if operation is LESS
- return op == OpLess;
- }
- else if(lhs[i] > rhs[i])
- {
- // lhs > rhs, so true if operation is GREATER
- return op == OpGreater;
- }
- }
- // lhs == rhs, so true if operation is EQUAL
- return op == OpEqual;
- }
-
- //=========================================================================
// level 0 processes parenthetical expressions
bool HandleLevel0(std::list<std::string> &newArgs,
cmMakefile *makefile,
@@ -723,16 +691,16 @@ namespace
{
def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
- Op op = OpEqual;
+ cmSystemTools::CompareOp op = cmSystemTools::OP_EQUAL;
if(*argP1 == "VERSION_LESS")
{
- op = OpLess;
+ op = cmSystemTools::OP_LESS;
}
else if(*argP1 == "VERSION_GREATER")
{
- op = OpGreater;
+ op = cmSystemTools::OP_GREATER;
}
- bool result = HandleVersionCompare(op, def, def2);
+ bool result = cmSystemTools::VersionCompare(op, def, def2);
HandleBinaryOp(result,
reducible, arg, newArgs, argP1, argP2);
}
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 803d0da..66b34ab 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -2680,13 +2680,18 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op,
const char* lhss, const char* rhss)
{
- unsigned int lhs[4] = {0,0,0,0};
- unsigned int rhs[4] = {0,0,0,0};
- sscanf(lhss, "%u.%u.%u.%u", &lhs[0], &lhs[1], &lhs[2], &lhs[3]);
- sscanf(rhss, "%u.%u.%u.%u", &rhs[0], &rhs[1], &rhs[2], &rhs[3]);
+ // Parse out up to 8 components.
+ unsigned int lhs[8] = {0,0,0,0,0,0,0,0};
+ unsigned int rhs[8] = {0,0,0,0,0,0,0,0};
+ sscanf(lhss, "%u.%u.%u.%u.%u.%u.%u.%u",
+ &lhs[0], &lhs[1], &lhs[2], &lhs[3],
+ &lhs[4], &lhs[5], &lhs[6], &lhs[7]);
+ sscanf(rhss, "%u.%u.%u.%u.%u.%u.%u.%u",
+ &rhs[0], &rhs[1], &rhs[2], &rhs[3],
+ &rhs[4], &rhs[5], &rhs[6], &rhs[7]);
// Do component-wise comparison.
- for(unsigned int i=0; i < 4; ++i)
+ for(unsigned int i=0; i < 8; ++i)
{
if(lhs[i] < rhs[i])
{
-----------------------------------------------------------------------
Summary of changes:
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list