about summary refs log tree commit diff
path: root/CMake
diff options
context:
space:
mode:
Diffstat (limited to 'CMake')
-rw-r--r--CMake/AbseilHelpers.cmake21
-rw-r--r--CMake/AbseilInstallDirs.cmake20
-rwxr-xr-xCMake/install_test_project/test.sh92
3 files changed, 96 insertions, 37 deletions
diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake
index 6d26169dbbb7..be9a0e9ccf37 100644
--- a/CMake/AbseilHelpers.cmake
+++ b/CMake/AbseilHelpers.cmake
@@ -16,7 +16,7 @@
 
 include(CMakeParseArguments)
 include(AbseilConfigureCopts)
-include(GNUInstallDirs)
+include(AbseilInstallDirs)
 
 # The IDE folder for Abseil that will be used if Abseil is included in a CMake
 # project that sets
@@ -105,13 +105,15 @@ function(absl_cc_library)
       target_include_directories(${_NAME}
         PUBLIC
           $<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
-          $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+          $<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
       )
       target_compile_options(${_NAME}
         PRIVATE ${ABSL_CC_LIB_COPTS})
       target_link_libraries(${_NAME}
         PUBLIC ${ABSL_CC_LIB_DEPS}
-        PRIVATE ${ABSL_CC_LIB_LINKOPTS}
+        PRIVATE
+          ${ABSL_CC_LIB_LINKOPTS}
+          ${ABSL_DEFAULT_LINKOPTS}
       )
       target_compile_definitions(${_NAME} PUBLIC ${ABSL_CC_LIB_DEFINES})
 
@@ -140,10 +142,13 @@ function(absl_cc_library)
       target_include_directories(${_NAME}
         INTERFACE
           $<BUILD_INTERFACE:${ABSL_COMMON_INCLUDE_DIRS}>
-          $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+          $<INSTALL_INTERFACE:${ABSL_INSTALL_INCLUDEDIR}>
         )
       target_link_libraries(${_NAME}
-        INTERFACE ${ABSL_CC_LIB_DEPS} ${ABSL_CC_LIB_LINKOPTS}
+        INTERFACE
+          ${ABSL_CC_LIB_DEPS}
+          ${ABSL_CC_LIB_LINKOPTS}
+          ${ABSL_DEFAULT_LINKOPTS}
       )
       target_compile_definitions(${_NAME} INTERFACE ${ABSL_CC_LIB_DEFINES})
     endif()
@@ -152,9 +157,9 @@ function(absl_cc_library)
     # installed abseil can't be tested.
     if (NOT ABSL_CC_LIB_TESTONLY)
       install(TARGETS ${_NAME} EXPORT ${PROJECT_NAME}Targets
-            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
-            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
-            ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${ABSL_INSTALL_BINDIR}
+            LIBRARY DESTINATION ${ABSL_INSTALL_LIBDIR}
+            ARCHIVE DESTINATION ${ABSL_INSTALL_LIBDIR}
       )
     endif()
 
diff --git a/CMake/AbseilInstallDirs.cmake b/CMake/AbseilInstallDirs.cmake
new file mode 100644
index 000000000000..5b67008bc68c
--- /dev/null
+++ b/CMake/AbseilInstallDirs.cmake
@@ -0,0 +1,20 @@
+include(GNUInstallDirs)
+
+# absl_VERSION is only set if we are an LTS release being installed, in which
+# case it may be into a system directory and so we need to make subdirectories
+# for each installed version of Abseil.  This mechanism is implemented in
+# Abseil's internal Copybara (https://github.com/google/copybara) workflows and
+# isn't visible in the CMake buildsystem itself.
+
+if (absl_VERSION)
+  set(ABSL_SUBDIR "${PROJECT_NAME}_${PROJECT_VERSION}")
+  set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}/${ABSL_SUBDIR}")
+  set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${ABSL_SUBDIR}")
+  set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/{ABSL_SUBDIR}")
+  set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${ABSL_SUBDIR}")
+else()
+  set(ABSL_INSTALL_BINDIR "${CMAKE_INSTALL_BINDIR}")
+  set(ABSL_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
+  set(ABSL_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
+  set(ABSL_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
+endif()
\ No newline at end of file
diff --git a/CMake/install_test_project/test.sh b/CMake/install_test_project/test.sh
index 3e77e79a4fe8..99989b031d36 100755
--- a/CMake/install_test_project/test.sh
+++ b/CMake/install_test_project/test.sh
@@ -24,15 +24,6 @@
 
 # Fail on any error. Treat unset variables an error. Print commands as executed.
 set -euox pipefail
-absl_dir=/abseil-cpp
-absl_build_dir=/buildfs/absl-build
-project_dir="${absl_dir}"/CMake/install_test_project
-project_build_dir=/buildfs/project-build
-install_dir="${project_build_dir}"/install
-
-mkdir -p "${absl_build_dir}"
-mkdir -p "${project_build_dir}"
-mkdir -p "${install_dir}"
 
 install_absl() {
   pushd "${absl_build_dir}"
@@ -51,10 +42,41 @@ uninstall_absl() {
   mkdir -p "${absl_build_dir}"
 }
 
+lts_install=""
+
+while getopts ":l" lts; do
+  case "${lts}" in
+    l )
+      lts_install="true"
+      ;;
+  esac
+done
+
+absl_dir=/abseil-cpp
+absl_build_dir=/buildfs/absl-build
+project_dir="${absl_dir}"/CMake/install_test_project
+project_build_dir=/buildfs/project-build
+
+mkdir -p "${absl_build_dir}"
+mkdir -p "${project_build_dir}"
+
+if [[ "${lts_install}" ]]; then
+  install_dir="/usr/local"
+else
+  install_dir="${project_build_dir}"/install
+fi
+mkdir -p "${install_dir}"
+
 # Test build, install, and link against installed abseil
-install_absl "${install_dir}"
 pushd "${project_build_dir}"
-cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}"
+if [[ "${lts_install}" ]]; then
+  install_absl
+  cmake "${project_dir}"
+else
+  install_absl "${install_dir}"
+  cmake "${project_dir}" -DCMAKE_PREFIX_PATH="${install_dir}"
+fi
+
 cmake --build . --target simple
 
 output="$(${project_build_dir}/simple "printme" 2>&1)"
@@ -64,14 +86,16 @@ if [[ "${output}" != *"Arg 1: printme"* ]]; then
   exit 1
 fi
 
+popd
+
 # Test that we haven't accidentally made absl::abslblah
 pushd "${install_dir}"
 
 # Starting in CMake 3.12 the default install dir is lib$bit_width
-if [[ -d lib ]]; then
-  libdir="lib"
-elif [[ -d lib64 ]]; then
+if [[ -d lib64 ]]; then
   libdir="lib64"
+elif [[ -d lib ]]; then
+  libdir="lib"
 else
   echo "ls *, */*, */*/*:"
   ls *
@@ -80,7 +104,15 @@ else
   echo "unknown lib dir"
 fi
 
-if ! grep absl::strings "${libdir}"/cmake/absl/abslTargets.cmake;  then
+if [[ "${lts_install}" ]]; then
+  # LTS versions append the date of the release to the subdir.
+  # 9999/99/99 is the dummy date used in the local_lts workflow.
+  absl_subdir="absl_99999999"
+else
+  absl_subdir="absl"
+fi
+
+if ! grep absl::strings "${libdir}/cmake/${absl_subdir}/abslTargets.cmake"; then
   cat "${libdir}"/cmake/absl/abslTargets.cmake
   echo "CMake targets named incorrectly"
   exit 1
@@ -89,22 +121,24 @@ fi
 uninstall_absl
 popd
 
-# Test that we warn if installed without a prefix or a system prefix
-output="$(install_absl 2>&1)"
-if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
-  echo "Install without prefix didn't warn as expected. Output:"
-  echo "${output}"
-  exit 1
-fi
-uninstall_absl
+if [[ ! "${lts_install}" ]]; then
+  # Test that we warn if installed without a prefix or a system prefix
+  output="$(install_absl 2>&1)"
+  if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
+    echo "Install without prefix didn't warn as expected. Output:"
+    echo "${output}"
+    exit 1
+  fi
+  uninstall_absl
 
-output="$(install_absl /usr 2>&1)"
-if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
-  echo "Install with /usr didn't warn as expected. Output:"
-  echo "${output}"
-  exit 1
+  output="$(install_absl /usr 2>&1)"
+  if [[ "${output}" != *"Please set CMAKE_INSTALL_PREFIX"* ]]; then
+    echo "Install with /usr didn't warn as expected. Output:"
+    echo "${output}"
+    exit 1
+  fi
+  uninstall_absl
 fi
-uninstall_absl
 
 echo "Install test complete!"
 exit 0