Skip to content

Commit

Permalink
Delegate cmake version check to cmake when possible (#37447)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Jan Vorlicek <[email protected]>
  • Loading branch information
am11 and janvorli authored Jun 18, 2020
1 parent 643f5e1 commit 16b451d
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 16b451d

Please sign in to comment.