Skip to content

Commit b81600c

Browse files
committed
Avoid double installation by creating temporary no-op cmake install abseil
1 parent f59b9e6 commit b81600c

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

cpp/cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,19 +3012,17 @@ macro(build_absl)
30123012

30133013
# Configure Abseil options before FetchContent
30143014
set(ABSL_PROPAGATE_CXX_STD ON)
3015-
# TODO: Investigate why with this abseil gets installed also on our install dir (along with Arrow)
3016-
# Must enable install to generate abslConfig.cmake so GRPC can find Abseil
3015+
# We have to enable abseil install to generate abslConfig.cmake
3016+
# so GRPC can find Abseil thorught ExternalProject_Add
30173017
set(ABSL_ENABLE_INSTALL ON)
30183018

30193019
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
30203020
string(APPEND CMAKE_CXX_FLAGS " -include stdint.h")
30213021
endif()
30223022

3023-
fetchcontent_declare(
3024-
absl
3025-
URL ${ABSL_SOURCE_URL}
3026-
URL_HASH "SHA256=${ARROW_ABSL_BUILD_SHA256_CHECKSUM}"
3027-
)
3023+
fetchcontent_declare(absl
3024+
URL ${ABSL_SOURCE_URL}
3025+
URL_HASH "SHA256=${ARROW_ABSL_BUILD_SHA256_CHECKSUM}")
30283026

30293027
prepare_fetchcontent()
30303028

@@ -3109,18 +3107,44 @@ macro(build_absl)
31093107
absl::time
31103108
absl::time_zone)
31113109

3112-
# Install Abseil to ABSL_PREFIX. This is necessary for gRPC to find Abseil
3113-
# when using ExternalProject_Add.
3114-
add_custom_command(
3115-
OUTPUT "${ABSL_PREFIX}/.absl_installed"
3116-
COMMAND ${CMAKE_COMMAND} --install ${absl_BINARY_DIR} --prefix ${ABSL_PREFIX} || ${CMAKE_COMMAND} -E true
3117-
COMMAND ${CMAKE_COMMAND} -E touch "${ABSL_PREFIX}/.absl_installed"
3118-
DEPENDS absl_built
3119-
COMMENT "Installing Abseil (errors about scoped_set_env are expected and ignored)"
3120-
VERBATIM
3121-
)
3122-
3123-
add_custom_target(absl_ep ALL DEPENDS "${ABSL_PREFIX}/.absl_installed")
3110+
# GRPC requires Abseil to be installed to a known location.
3111+
# We have to do this in two steps to avoid double installation of Abseil
3112+
# when Arrow is installed.
3113+
# Disable Abseil's install script this target runs after Abseil is built
3114+
# and replaces its cmake_install.cmake with a no-op so Arrow does not install it
3115+
# outside of the build tree.
3116+
add_custom_command(OUTPUT "${absl_BINARY_DIR}/cmake_install.cmake.saved"
3117+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
3118+
"${absl_BINARY_DIR}/cmake_install.cmake"
3119+
"${absl_BINARY_DIR}/cmake_install.cmake.saved"
3120+
COMMAND ${CMAKE_COMMAND} -E echo
3121+
"# Abseil install disabled to prevent double installation with Arrow"
3122+
> "${absl_BINARY_DIR}/cmake_install.cmake"
3123+
DEPENDS absl_built
3124+
COMMENT "Disabling Abseil's install to prevent double installation"
3125+
VERBATIM)
3126+
3127+
add_custom_target(absl_install_disabled ALL
3128+
DEPENDS "${absl_BINARY_DIR}/cmake_install.cmake.saved")
3129+
3130+
# Install Abseil to ABSL_PREFIX for gRPC to find
3131+
# Using the saved original cmake_install.cmake.saved install script
3132+
# for other dependencies to find Abseil
3133+
add_custom_command(OUTPUT "${ABSL_PREFIX}/.absl_installed"
3134+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
3135+
"${absl_BINARY_DIR}/cmake_install.cmake.saved"
3136+
"${absl_BINARY_DIR}/cmake_install.cmake.tmp"
3137+
COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${ABSL_PREFIX}
3138+
-DCMAKE_INSTALL_CONFIG_NAME=$<CONFIG> -P
3139+
"${absl_BINARY_DIR}/cmake_install.cmake.tmp" ||
3140+
${CMAKE_COMMAND} -E true
3141+
COMMAND ${CMAKE_COMMAND} -E touch "${ABSL_PREFIX}/.absl_installed"
3142+
DEPENDS absl_install_disabled
3143+
COMMENT "Installing Abseil to ${ABSL_PREFIX} for gRPC"
3144+
VERBATIM)
3145+
3146+
# Make absl_ep depend on the install completion marker
3147+
add_custom_target(absl_ep DEPENDS "${ABSL_PREFIX}/.absl_installed")
31243148

31253149
if(APPLE)
31263150
# This is due to upstream absl::cctz issue

0 commit comments

Comments
 (0)