From 52197bcd32ac8ca33097cf4bebae30f930d1da12 Mon Sep 17 00:00:00 2001
From: Artyom Dymchenko <Artem.Dymchenko@noveogroup.com>
Date: Wed, 13 Jan 2016 00:18:49 +0600
Subject: [PATCH] CMake minimal version 2.8.7 test

---
 .travis.yml                                   |  8 +--
 contrib/cmake/CMakeLists.txt                  | 14 ++--
 .../cmake/CMakeModules/CompareVersion.cmake   | 70 -------------------
 contrib/cmake/lib/CMakeLists.txt              | 18 ++---
 contrib/cmake/programs/CMakeLists.txt         |  8 +--
 5 files changed, 16 insertions(+), 102 deletions(-)
 delete mode 100644 contrib/cmake/CMakeModules/CompareVersion.cmake

diff --git a/.travis.yml b/.travis.yml
index 993695b8615..065e6f143b4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,9 +1,6 @@
 language: c
 
 before_install:
-  - "wget https://launchpad.net/ubuntu/+source/cmake/2.8.8-2ubuntu1/+build/3441442/+files/cmake_2.8.8-2ubuntu1_amd64.deb"
-  - "wget https://launchpad.net/ubuntu/+archive/primary/+files/cmake-data_2.8.8-2ubuntu1_all.deb"
-  - "sudo apt-get remove cmake-data cmake"
   - sudo apt-get update  -qq
   - sudo apt-get install -qq gcc-arm-linux-gnueabi
   - sudo apt-get install -qq clang
@@ -11,9 +8,6 @@ before_install:
   - sudo apt-get install -qq gcc-multilib
   - sudo apt-get install -qq valgrind
 
-install:
-    - "sudo dpkg --install cmake-data_2.8.8-2ubuntu1_all.deb cmake_2.8.8-2ubuntu1_amd64.deb" 
-
 env:
   - ZSTD_TRAVIS_CI_ENV=travis-install
   - ZSTD_TRAVIS_CI_ENV=cmaketest
@@ -34,4 +28,4 @@ script:
   - make $ZSTD_TRAVIS_CI_ENV
 
 matrix:
-  fast_finish: true
\ No newline at end of file
+  fast_finish: true
diff --git a/contrib/cmake/CMakeLists.txt b/contrib/cmake/CMakeLists.txt
index baa36c6abb4..3687c9ec2da 100644
--- a/contrib/cmake/CMakeLists.txt
+++ b/contrib/cmake/CMakeLists.txt
@@ -32,7 +32,7 @@
 # ################################################################
 
 PROJECT(zstd)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7)
 
 OPTION(ZSTD_LEGACY_SUPPORT "LEGACY SUPPORT" OFF)
 
@@ -44,14 +44,12 @@ ELSE (ZSTD_LEGACY_SUPPORT)
     ADD_DEFINITIONS(-DZSTD_LEGACY_SUPPORT=0)
 ENDIF (ZSTD_LEGACY_SUPPORT)
 
-INCLUDE(CMakeModules/CompareVersion.cmake)
-COMPARE_VERSION_STRINGS("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" "2.8.8" CMP_RESULT)
-
-IF ((CMP_RESULT LESS 0) OR (CMP_RESULT EQUAL 0))
-    SET(USE_DEPRECATED_CODE_STYLE TRUE)
+# TARGET_INCLUDE_DIRECTORIES can use in version 2.8.11 and greate
+IF ((${CMAKE_MAJOR_VERSION} EQUAL 2) AND (${CMAKE_MINOR_VERSION} EQUAL 8) AND (${CMAKE_PATCH_VERSION} LESS 11))
+    SET(WORKAROUND_OUTDATED_CODE_STYLE TRUE)
 ELSE ()
-    SET(USE_DEPRECATED_CODE_STYLE FALSE)
-ENDIF ((CMP_RESULT LESS 0) OR (CMP_RESULT EQUAL 0))
+    SET(WORKAROUND_OUTDATED_CODE_STYLE FALSE)
+ENDIF ((${CMAKE_MAJOR_VERSION} EQUAL 2) AND (${CMAKE_MINOR_VERSION} EQUAL 8) AND (${CMAKE_PATCH_VERSION} LESS 11))
 
 ADD_SUBDIRECTORY(lib)
 ADD_SUBDIRECTORY(programs)
diff --git a/contrib/cmake/CMakeModules/CompareVersion.cmake b/contrib/cmake/CMakeModules/CompareVersion.cmake
deleted file mode 100644
index a90157591d7..00000000000
--- a/contrib/cmake/CMakeModules/CompareVersion.cmake
+++ /dev/null
@@ -1,70 +0,0 @@
-# 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) 
diff --git a/contrib/cmake/lib/CMakeLists.txt b/contrib/cmake/lib/CMakeLists.txt
index f533a5b8efa..f15244275b3 100644
--- a/contrib/cmake/lib/CMakeLists.txt
+++ b/contrib/cmake/lib/CMakeLists.txt
@@ -31,12 +31,6 @@
 #  - Public forum : https://groups.google.com/forum/#!forum/lz4c
 # ################################################################
 
-IF (USE_DEPRECATED_CODE_STYLE)
-    IF (POLICY CMP0021)
-        cmake_policy(SET CMP0021 OLD)
-    ENDIF ()
-ENDIF (USE_DEPRECATED_CODE_STYLE)
-
 # Get library version based on information from input content (use regular exp)
 function(GetLibraryVersion _content _outputVar1 _outputVar2 _outputVar3)
     string(REGEX MATCHALL ".*define ZSTD_VERSION_MAJOR+.* ([0-9]+).*define ZSTD_VERSION_MINOR+.* ([0-9]+).*define ZSTD_VERSION_RELEASE+.* ([0-9]+)" VERSION_REGEX "${_content}")
@@ -115,17 +109,15 @@ IF (MSVC)
     SET_TARGET_PROPERTIES(libzstd_shared PROPERTIES COMPILE_DEFINITIONS "ZSTD_DLL_EXPORT=1;ZSTD_HEAPMODE=0;_CONSOLE;_CRT_SECURE_NO_WARNINGS")
 ENDIF (MSVC)
 
-IF (NOT USE_DEPRECATED_CODE_STYLE)
+# Define include directories
+IF (NOT WORKAROUND_OUTDATED_CODE_STYLE)
     TARGET_INCLUDE_DIRECTORIES(libzstd_static PUBLIC ${LIBRARY_DIR})
     TARGET_INCLUDE_DIRECTORIES(libzstd_shared PUBLIC ${LIBRARY_DIR})
-ENDIF (NOT USE_DEPRECATED_CODE_STYLE)
-
-IF (ZSTD_LEGACY_SUPPORT)
-    IF (NOT USE_DEPRECATED_CODE_STYLE)
+    IF (ZSTD_LEGACY_SUPPORT)
         TARGET_INCLUDE_DIRECTORIES(libzstd_static PUBLIC ${LIBRARY_LEGACY_DIR})
         TARGET_INCLUDE_DIRECTORIES(libzstd_shared PUBLIC ${LIBRARY_LEGACY_DIR})
-    ENDIF (NOT USE_DEPRECATED_CODE_STYLE)
-ENDIF (ZSTD_LEGACY_SUPPORT)
+    ENDIF (ZSTD_LEGACY_SUPPORT)
+ENDIF (NOT WORKAROUND_OUTDATED_CODE_STYLE)
 
 # Define library base name
 IF (UNIX)
diff --git a/contrib/cmake/programs/CMakeLists.txt b/contrib/cmake/programs/CMakeLists.txt
index 7904b682c30..af9a0572510 100644
--- a/contrib/cmake/programs/CMakeLists.txt
+++ b/contrib/cmake/programs/CMakeLists.txt
@@ -42,19 +42,19 @@ SET(ROOT_DIR ../../..)
 SET(PROGRAMS_DIR ${ROOT_DIR}/programs)
 INCLUDE_DIRECTORIES(${PROGRAMS_DIR})
 
-IF (USE_DEPRECATED_CODE_STYLE)
+IF (WORKAROUND_OUTDATED_CODE_STYLE)
     # Define library directory, where sources and header files are located
     SET(LIBRARY_DIR ${ROOT_DIR}/lib)
     INCLUDE_DIRECTORIES(${LIBRARY_DIR})
-ENDIF (USE_DEPRECATED_CODE_STYLE)
+ENDIF (WORKAROUND_OUTDATED_CODE_STYLE)
 
 IF (ZSTD_LEGACY_SUPPORT)
     SET(PROGRAMS_LEGACY_DIR ${PROGRAMS_DIR}/legacy)
     INCLUDE_DIRECTORIES(${PROGRAMS_LEGACY_DIR})
 
-    IF (USE_DEPRECATED_CODE_STYLE)
+    IF (WORKAROUND_OUTDATED_CODE_STYLE)
         INCLUDE_DIRECTORIES(${LIBRARY_DIR}/legacy)
-    ENDIF (USE_DEPRECATED_CODE_STYLE)
+    ENDIF (WORKAROUND_OUTDATED_CODE_STYLE)
 
     SET(ZSTD_FILEIO_LEGACY ${PROGRAMS_LEGACY_DIR}/fileio_legacy.c)
 ENDIF (ZSTD_LEGACY_SUPPORT)