2
0

setup-cmake.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # Copyright The OpenTelemetry Authors
  3. # SPDX-License-Identifier: Apache-2.0
  4. #
  5. # This script installs latest CMake on Linux machine
  6. #
  7. set -e
  8. export PATH=/usr/local/bin:$PATH
  9. # Min required CMake version
  10. export CMAKE_MIN_VERSION=${1:-3.1.0}
  11. # Target version to install if min required is not found
  12. export CMAKE_VERSION=${2:-3.18.4}
  13. UPGRADE_NEEDED=no
  14. function splitVersion {
  15. pattern='([^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]'
  16. v1=$(cut -d '.' -f 1 <<< $ver )
  17. v2=$(cut -d '.' -f 2 <<< $ver )
  18. v3=$(cut -d '.' -f 3 <<< $ver )
  19. }
  20. function checkVersion {
  21. # Current CMake version
  22. currVer=`cmake --version | grep version | cut -d' ' -f 3`
  23. ver=$currVer splitVersion
  24. cv1=$v1
  25. cv2=$v2
  26. cv3=$v3
  27. cv=`echo "65536*$v1+256*$v2+$v3" | bc`
  28. # New CMake version
  29. ver=$CMAKE_MIN_VERSION splitVersion
  30. nv=`echo "65536*$v1+256*$v2+$v3" | bc`
  31. if [ "$cv" -ge "$nv" ]; then
  32. echo "CMake is already installed: $currVer"
  33. else
  34. UPGRADE_NEEDED=yes
  35. fi
  36. }
  37. checkVersion
  38. if [[ "$UPGRADE_NEEDED" == "no" ]]; then
  39. echo "Skipping CMake installation"
  40. exit 0
  41. fi
  42. # Download cmake to /tmp
  43. pushd /tmp
  44. if [[ ! -f "/tmp/cmake.tar.gz" ]]; then
  45. wget -O /tmp/cmake.tar.gz https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}.tar.gz
  46. tar -zxvf /tmp/cmake.tar.gz
  47. fi
  48. # Bootstrap CMake
  49. cd cmake-${CMAKE_VERSION}
  50. ./bootstrap --prefix=/usr/local
  51. # Build CMake without CMake and without Ninja (slow)
  52. make
  53. make install
  54. popd