Add CMake Superbuild to build Abseil static and shared libraries in one pass
#69
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Historically, Abseil does not support shared libraries on Windows, and building both static and shared variants in a single workflow can be tricky. This change introduces a simplified CMake Superbuild that uses two ExternalProject calls to build static and shared libraries separately, while allowing them to coexist under the same install prefix.
The Superbuild is wrapped in a Bash script and uses Ninja Multi-Config when available to improve build speed and parallelism. This approach ensures both variants are installed in one execution without duplicating source checkout steps.
For example, this is the Bash driver to run Superbuild:
I've also added a
superbuild/CMakeLists.txtthat definesabsl_staticandabsl_sharedusingExternalProject_Add, with separate build directories for each variant to avoid conflicts. A single install_all target is introduced to install both variants in one step, and the configuration automatically skips building the shared variant on WIN32 platforms for compatibility:cmake_minimum_required(VERSION 3.20) project(absl_superbuild) include(ExternalProject) if(NOT DEFINED ENV{LOCAL_INSTALL}) message(FATAL_ERROR "LOCAL_INSTALL env not set") endif() if(NOT DEFINED ABSEIL_CPP_SOURCE_DIR) message(FATAL_ERROR "ABSEIL_CPP_SOURCE_DIR cache var not set") endif() set(PREFIX $ENV{LOCAL_INSTALL}) set(SRC_DIR "${CMAKE_SOURCE_DIR}/../${ABSEIL_CPP_SOURCE_DIR}") set(COMMON_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${PREFIX} -DABSL_ENABLE_INSTALL=ON -DABSL_BUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_INSTALL_RPATH=${PREFIX}/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON ) ExternalProject_Add(absl_static SOURCE_DIR "${SRC_DIR}" BINARY_DIR "${CMAKE_BINARY_DIR}/absl_static" DOWNLOAD_COMMAND "" CMAKE_ARGS ${COMMON_ARGS} -DBUILD_SHARED_LIBS=OFF BUILD_COMMAND ${CMAKE_COMMAND} --build . -j $ENV{BUILD_THREADS} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install -j $ENV{BUILD_THREADS} ) if(NOT WIN32) ExternalProject_Add(absl_shared SOURCE_DIR "${SRC_DIR}" BINARY_DIR "${CMAKE_BINARY_DIR}/absl_shared" DOWNLOAD_COMMAND "" CMAKE_ARGS ${COMMON_ARGS} -DBUILD_SHARED_LIBS=ON BUILD_COMMAND ${CMAKE_COMMAND} --build . -j $ENV{BUILD_THREADS} INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install -j $ENV{BUILD_THREADS} ) add_custom_target(install_all ALL DEPENDS absl_static absl_shared) else() add_custom_target(install_all ALL DEPENDS absl_static) endif()If you truly want Multi-Config (not just “Ninja”), detect and prefer it:
Thanks,
Michael Mendy