From 0e6c208755ceae5b0ca400882796572bc02ca9bd Mon Sep 17 00:00:00 2001
From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Date: Sun, 14 Nov 2010 20:50:12 -0800
Subject: [PATCH] COMP: replace VERSION_LESS by macro to enable compilation
 with cmake 2.6

---
 CMake/CompareVersionStrings.cmake  | 73 ++++++++++++++++++++++++++++++
 CMakeLists.txt                     |  3 ++
 Utilities/otbliblas/CMakeLists.txt |  4 +-
 3 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 CMake/CompareVersionStrings.cmake

diff --git a/CMake/CompareVersionStrings.cmake b/CMake/CompareVersionStrings.cmake
new file mode 100644
index 0000000000..45ea5138a7
--- /dev/null
+++ b/CMake/CompareVersionStrings.cmake
@@ -0,0 +1,73 @@
+# From  http://www.cmake.org/Wiki/CMakeCompareVersionStrings
+# to be able to support cmake 2.6.0 (VERSION_LESS not available yet)
+#
+# Computes the realtionship between two version strings.  A version
+# string is a number delineated by '.'s such as 1.3.2 and 0.99.9.1.
+# You can feed version strings with different number of dot versions,
+# and the shorter version number will be padded with zeros: 9.2 <
+# 9.2.1 will actually compare 9.2.0 < 9.2.1.
+#
+# Input: a_in - value, not variable
+#        b_in - value, not variable
+#        result_out - variable with value:
+#                         -1 : a_in <  b_in
+#                          0 : a_in == b_in
+#                          1 : a_in >  b_in
+#
+# Written by James Bigler.
+MACRO(COMPARE_VERSION_STRINGS a_in b_in result_out)
+  # Since SEPARATE_ARGUMENTS using ' ' as the separation token,
+  # replace '.' with ' ' to allow easy tokenization of the string.
+  STRING(REPLACE "." " " a ${a_in})
+  STRING(REPLACE "." " " b ${b_in})
+  SEPARATE_ARGUMENTS(a)
+  SEPARATE_ARGUMENTS(b)
+
+  # Check the size of each list to see if they are equal.
+  LIST(LENGTH a a_length)
+  LIST(LENGTH b b_length)
+
+  # Pad the shorter list with zeros.
+
+  # Note that range needs to be one less than the length as the for
+  # loop is inclusive (silly CMake).
+  IF(a_length LESS b_length)
+    # a is shorter
+    SET(shorter a)
+    MATH(EXPR range "${b_length} - 1")
+    MATH(EXPR pad_range "${b_length} - ${a_length} - 1")
+  ELSE(a_length LESS b_length)
+    # b is shorter
+    SET(shorter b)
+    MATH(EXPR range "${a_length} - 1")
+    MATH(EXPR pad_range "${a_length} - ${b_length} - 1")
+  ENDIF(a_length LESS b_length)
+
+  # PAD out if we need to
+  IF(NOT pad_range LESS 0)
+    FOREACH(pad RANGE ${pad_range})
+      # Since shorter is an alias for b, we need to get to it by by dereferencing shorter.
+      LIST(APPEND ${shorter} 0)
+    ENDFOREACH(pad RANGE ${pad_range})
+  ENDIF(NOT pad_range LESS 0)
+
+  SET(result 0)
+  FOREACH(index RANGE ${range})
+    IF(result EQUAL 0)
+      # Only continue to compare things as long as they are equal
+      LIST(GET a ${index} a_version)
+      LIST(GET b ${index} b_version)
+      # LESS
+      IF(a_version LESS b_version)
+        SET(result -1)
+      ENDIF(a_version LESS b_version)
+      # GREATER
+      IF(a_version GREATER b_version)
+        SET(result 1)
+      ENDIF(a_version GREATER b_version)
+    ENDIF(result EQUAL 0)
+  ENDFOREACH(index)
+
+  # Copy out the return result
+  SET(${result_out} ${result})
+ENDMACRO(COMPARE_VERSION_STRINGS)
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 71576f7339..ff70d7c90d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,9 @@ ENDIF(COMMAND CMAKE_POLICY)
 #
 INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/PreventInSourceBuilds.cmake)
 
+#For the support of cmake 2.6 which does not have VERSION_LESS
+INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/CMake/CompareVersionStrings.cmake)
+
 PROJECT(OTB)
 
 # Path to additional CMake modules
diff --git a/Utilities/otbliblas/CMakeLists.txt b/Utilities/otbliblas/CMakeLists.txt
index 3fa5f3cf91..31e22b43ef 100755
--- a/Utilities/otbliblas/CMakeLists.txt
+++ b/Utilities/otbliblas/CMakeLists.txt
@@ -45,7 +45,9 @@ SET(liblas_SRCS
   )
 
 #include Gdal and GeoTiff support only if version >= 1.6
-IF(GDAL_VERSION VERSION_LESS 1.6)
+COMPARE_VERSION_STRINGS(GDAL_VERSION VERSION_LESS 1.6 result)
+IF(result LESS 0)
+#IF(GDAL_VERSION VERSION_LESS 1.6)
   MESSAGE(STATUS "Disabling GDAL/GeoTIFF support for LibLAS (requires GDAL version >= 1.6)")
 ELSE()
   MESSAGE(STATUS "Enabling GDAL/GeoTIFF support for LibLAS")
-- 
GitLab