boost: Update boost check to support older CMake versions

Prior to this commit, we only tested boost version using
`Boost_VERSION_MACRO` which is supported in CMake 3.15 or later
(https://cmake.org/cmake/help/git-stage/policy/CMP0093.html). When
building madlib on versions<3.15, since `Boost_VERSION_MACRO` variable
does not exist, the check for validating boost versions wouldn't work.
This commit fixes this issue by checking for `Boost_VERSION` (for
CMake<3.15) as well as `Boost_VERSION_MACRO` (for CMake 3.15 or later).

Also added an if condition to check for the case when CXX11 is already
enabled and boost > 1.65
Also removed a redundant message about discovering boost version.

Co-authored-by: Nikhil Kak <nkak@vmware.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a4231fb..df3b1f3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,21 +65,34 @@
 # for older versions of Boost.  Therefore, we detect it here intstead of
 # in src/CMakeLists.txt where the other 3rd party libraries are detected.
 #
+# https://cmake.org/cmake/help/git-stage/policy/CMP0093.html
+# cmake < 3.15 does not define Boost_VERSION_MACRO but stores the version in
+# Boost_VERSION in the format 104700. But cmake > 3.15 stores the version in Boost_VERSION
+# in 1.47.0(x.y.z) format which is unsuitable for our comparison. So for cmake > 3.15
+# we need to use Boost_VERSION_MACRO instead.
 find_package(Boost)
 if(Boost_FOUND)
+    if(Boost_VERSION_MACRO)
+        set(LOCAL_Boost_VERSION ${Boost_VERSION_MACRO})
+    else(Boost_VERSION_MACRO)
+        set(LOCAL_Boost_VERSION ${Boost_VERSION})
+    endif(Boost_VERSION_MACRO)
+
     # We use BOOST_ASSERT_MSG, which only exists in Boost 1.47 and later.
-    if(Boost_VERSION_MACRO LESS 104700)
-        message(STATUS "Found Boost ${Boost_VERSION_STRING}, but too old for MADlib")
+    if(LOCAL_Boost_VERSION LESS 104700)
+        message(STATUS "Found Boost ${Boost_VERSION_STRING}, but too old for MADlib. Will download a compatible version")
         set(Boost_FOUND FALSE)
-    elseif(CXX11 AND (Boost_VERSION_MACRO LESS 106500))
-        message(STATUS "Found Boost ${Boost_VERSION_STRING}, but too old for C++11")
+    elseif(CXX11 AND (LOCAL_Boost_VERSION LESS 106500))
+        message(STATUS "Found Boost ${Boost_VERSION_STRING}, but too old for C++11. Will download a compatible version")
         set(Boost_FOUND FALSE)
     else()
         message(STATUS "Found Boost ${Boost_VERSION_STRING}")
-        if(106500 LESS Boost_VERSION_MACRO)
-            message(STATUS "Auto-enabling -DCXX11, because Boost >= v1.65 requires C++11")
-            set(CXX11 TRUE)
-        endif(106500 LESS Boost_VERSION_MACRO)
+        if(106500 LESS LOCAL_Boost_VERSION)
+            if(NOT CXX11)
+                message(STATUS "Auto-enabling -DCXX11, because Boost >= v1.65 requires C++11")
+                set(CXX11 TRUE)
+            endif(NOT CXX11)
+        endif(106500 LESS LOCAL_Boost_VERSION)
     endif()
 endif(Boost_FOUND)
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7825028..0cf5661 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -113,7 +113,6 @@
     message(STATUS "Boost include directory ${Boost_INCLUDE_DIRS}")
     include_directories(${Boost_INCLUDE_DIRS})
 else(Boost_FOUND)
-    message(STATUS "No sufficiently recent version (>= 1.47) of Boost was found. Will download.")
     ExternalProject_Add(EP_boost
         PREFIX ${MAD_THIRD_PARTY}
         DOWNLOAD_DIR ${MAD_THIRD_PARTY}/downloads