Delegate cmake version check to cmake when possible (#37447)
authorAdeel Mujahid <adeelbm@outlook.com>
Thu, 18 Jun 2020 16:47:34 +0000 (19:47 +0300)
committerGitHub <noreply@github.com>
Thu, 18 Jun 2020 16:47:34 +0000 (18:47 +0200)
* Delegate cmake version check to cmake when possible
There are two kinds of old cmake versions:
* <ins>v3.13.0 onwards that support `-B` command-line option:</ins>
  cmake will print the error message based on `cmake_minimum_required`
  specified.
* <ins>< v3.13.0, which do not have `-B` option:</ins> cmake will fail
  before the version check with an obscure message, quite implicitly
  indicating that it doesn't understand `-B`. For that we have an
  up-front check just for `-B` option, covering the existence of cmake
  as well.

* Update eng/native/build-commons.sh

Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
Co-authored-by: Jan Vorlicek <janvorli@microsoft.com>
eng/native/build-commons.sh

index 31d8d8b..b976f5f 100755 (executable)
@@ -48,17 +48,9 @@ check_prereqs()
 {
     echo "Checking prerequisites..."
 
-    # Check presence of CMake on the path
-    command -v cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
-
-    function version { echo "$@" | awk -F. '{ printf("%d%02d%02d\n", $1,$2,$3); }'; }
-
-    local cmakeRequiredMinimumVersion="3.14.5"
-    local cmakeInstalledVersion="$(cmake --version | awk '/^cmake.* version [0-9]+\.[0-9]+\.[0-9]+$/ {print $3}')"
-
-    if [[ "$(version "$cmakeInstalledVersion")" -lt "$(version "$cmakeRequiredMinimumVersion")" ]]; then
-        echo "Found cmake v$cmakeInstalledVersion in PATH. Please install v$cmakeRequiredMinimumVersion or newer from https://www.cmake.org/download/."
-        exit 1;
+    if ! cmake --help 2>&1 | grep -q \\-B; then
+        echo "Please install cmake v3.14.5 or newer from https://www.cmake.org/download/."
+        exit 1
     fi
 
     if [[ "$__HostOS" == "OSX" ]]; then