check-host-cmake.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # prevent shift error
  3. [ $# -lt 2 ] && exit 1
  4. major_min="${1%.*}"
  5. minor_min="${1#*.}"
  6. shift
  7. for candidate; do
  8. # Try to locate the candidate. Discard it if not located.
  9. cmake=`which "${candidate}" 2>/dev/null`
  10. [ -n "${cmake}" ] || continue
  11. # Extract version X.Y from versions in the form X.Y or X.Y.Z
  12. # with X, Y and Z numbers with one or more digits each, e.g.
  13. # 3.2 -> 3.2
  14. # 3.2.3 -> 3.2
  15. # 3.2.42 -> 3.2
  16. # 3.10 -> 3.10
  17. # 3.10.4 -> 3.10
  18. # 3.10.42 -> 3.10
  19. # Discard the candidate if no version can be obtained
  20. version="$(${cmake} --version \
  21. |sed -r -e '/.* ([[:digit:]]+\.[[:digit:]]+).*$/!d;' \
  22. -e 's//\1/'
  23. )"
  24. [ -n "${version}" ] || continue
  25. major="${version%.*}"
  26. minor="${version#*.}"
  27. if [ ${major} -gt ${major_min} ]; then
  28. echo "${cmake}"
  29. exit
  30. elif [ ${major} -eq ${major_min} -a ${minor} -ge ${minor_min} ]; then
  31. echo "${cmake}"
  32. exit
  33. fi
  34. done
  35. # echo nothing: no suitable cmake found
  36. exit 1