2
0

install_abseil.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # Copyright The OpenTelemetry Authors
  3. # SPDX-License-Identifier: Apache-2.0
  4. set -ex
  5. export DEBIAN_FRONTEND=noninteractive
  6. [ -z "${ABSEIL_CPP_VERSION}" ] && export ABSEIL_CPP_VERSION="20240116.1"
  7. TOPDIR=`pwd`
  8. BUILD_DIR=/tmp/
  9. INSTALL_DIR=/usr/local/
  10. pushd $BUILD_DIR
  11. git clone --depth=1 -b ${ABSEIL_CPP_VERSION} https://github.com/abseil/abseil-cpp.git
  12. cd abseil-cpp
  13. ABSEIL_CPP_BUILD_OPTIONS=(
  14. "-DBUILD_TESTING=OFF"
  15. "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
  16. "-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR"
  17. )
  18. if [ ! -z "${CXX_STANDARD}" ]; then
  19. ABSEIL_CPP_BUILD_OPTIONS+=("-DCMAKE_CXX_STANDARD=${CXX_STANDARD}")
  20. ABSEIL_CPP_BUILD_OPTIONS+=("-DCMAKE_CXX_STANDARD_REQUIRED=ON")
  21. ABSEIL_CPP_BUILD_OPTIONS+=("-DCMAKE_CXX_EXTENSIONS=OFF")
  22. fi
  23. #
  24. # ABSEIL_CPP_VERSION="20240116.1" fails to build with CMake 3.30
  25. # ABSEIL_CPP_VERSION="20240116.2" fails to build with CMake 3.30
  26. # note that somehow the same builds with CMake 3.29.6
  27. #
  28. # Error reported:
  29. # CMake Error at CMake/AbseilHelpers.cmake:317 (target_link_libraries):
  30. # The link interface of target "test_allocator" contains:
  31. #
  32. # GTest::gmock
  33. #
  34. # but the target was not found. Possible reasons include:
  35. #
  36. # * There is a typo in the target name.
  37. # * A find_package call is missing for an IMPORTED target.
  38. # * An ALIAS target is missing.
  39. #
  40. # Call Stack (most recent call first):
  41. # absl/container/CMakeLists.txt:206 (absl_cc_library)
  42. #
  43. # Root cause:
  44. # https://github.com/abseil/abseil-cpp/pull/1536
  45. #
  46. # Applying fix from abseil commit 779a3565ac6c5b69dd1ab9183e500a27633117d5
  47. #
  48. # TODO(marcalff) Cleanup once abseil is upgraded to the next LTS
  49. if [ "${ABSEIL_CPP_VERSION}" = "20240116.1" ] || [ "${ABSEIL_CPP_VERSION}" = "20240116.2" ]; then
  50. echo "Patching abseil"
  51. patch -p1 < ${TOPDIR}/ci/fix-abseil-cpp-issue-1536.patch
  52. else
  53. echo "Not patching abseil"
  54. fi
  55. echo "Building abseil ${ABSEIL_CPP_VERSION}"
  56. echo "CMake build options:" "${ABSEIL_CPP_BUILD_OPTIONS[@]}"
  57. mkdir build && pushd build
  58. cmake "${ABSEIL_CPP_BUILD_OPTIONS[@]}" ..
  59. make -j $(nproc)
  60. make install
  61. popd
  62. popd
  63. export PATH=${INSTALL_DIR}/bin:$PATH # ensure to use the installed abseil