What Build System Does Abseil C++ Use? Bazel and CMake Configuration Guide
Abseil C++ officially supports both Bazel and CMake, providing complete build configurations in the abseil/abseil-cpp repository to accommodate Google's internal workflows and traditional C++ development environments.
Abseil C++ is a production-quality collection of C++ library code maintained by Google. When integrating this library into your project, understanding what build system Abseil C++ uses is essential, as the repository maintains parallel build configurations that enable compilation via Bazel (Google's build tool) or CMake (the industry-standard meta-build system).
Bazel: The Primary Build System
Bazel serves as the primary build system for Abseil C++, reflecting its origin as a Google project. The configuration relies on two core file types located at the repository root and within each subdirectory.
MODULE.bazel Dependencies
The MODULE.bazel file declares the module metadata and external dependencies required to build the library. According to the Abseil C++ source code, this file registers dependencies such as rules_cc, bazel_skylib, and platforms, which provide essential build rules and platform constraints for the cc_library and cc_test targets defined throughout the project.
BUILD.bazel Targets
Each subdirectory contains a BUILD.bazel file that defines granular Bazel targets using rules like cc_library and cc_test. This structure enables fine-grained incremental builds and remote caching. For example, components in absl/base and absl/strings are compiled as separate targets, allowing Bazel to rebuild only changed translation units.
CMake: The Alternative Build System
CMake provides a traditional build environment for users who require integration with existing CMake-based projects or prefer standard tooling. The Abseil C++ CMake configuration produces an installable package that downstream projects can consume via find_package.
Root CMakeLists.txt Configuration
The top-level CMakeLists.txt aggregates individual component directories (such as absl/base and absl/strings) and configures compiler options. As implemented in abseil/abseil-cpp, this file explicitly sets the C++ standard to C++17 using flags like -std=c++17, ensuring compatibility with Abseil's language requirements. The configuration also generates an absl export target that can be installed system-wide.
CMake Integration Support
The CMake/README.md file documents specific options for consumers, including how to control test compilation and install paths. The build system creates an installable target that exports CMake configuration files, allowing downstream projects to link against specific components like absl::base or absl::strings using modern CMake target syntax.
Building Abseil C++ with Bazel
To compile the library using Bazel, run the following commands from the repository root. The bazel tool automatically discovers BUILD.bazel files and constructs the dependency graph.
# Build the entire library
bazel build //absl/...
# Run the full test suite
bazel test //absl/...
# Build with AddressSanitizer (optional)
bazel test //absl/... --config=asan
Building Abseil C++ with CMake
CMake builds use an out-of-source directory pattern. The root CMakeLists.txt detects the platform and configures the build accordingly.
# Configure the build directory
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
# Compile the library
cmake --build build
# Install to system or local directory
cmake --install build
Integrating Abseil into Your Project
CMake Consumption
Once installed, Abseil C++ provides CMake package configuration files. Link against specific components using the absl:: namespace to leverage modern CMake target propagation:
find_package(absl CONFIG REQUIRED)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE absl::base absl::strings absl::synchronization)
Bazel Consumption
For Bazel-based projects, add Abseil as a dependency in your MODULE.bazel file or WORKSPACE configuration, then reference targets using the @abseil-cpp repository prefix (depending on your Bazel version and module setup).
Summary
- Abseil C++ maintains dual build system support for Bazel and CMake, ensuring compatibility with both Google-internal workflows and standard open-source practices.
- Bazel configuration relies on
MODULE.bazelfor dependency management andBUILD.bazelfiles forcc_librarytargets. - CMake configuration uses a root
CMakeLists.txtto aggregate components, enforce C++17, and create installable targets. - Both systems compile identical source code from directories like
absl/baseandabsl/strings, differing only in build metadata. - Downstream CMake projects consume Abseil via
find_package(absl CONFIG REQUIRED)and link against namespaced targets likeabsl::base.
Frequently Asked Questions
Does Abseil C++ require Bazel, or can I use CMake exclusively?
Abseil C++ fully supports CMake as a first-class build system. While Bazel is the primary system used internally at Google, the CMake configuration is officially maintained and supports standard workflows including installation, packaging, and find_package integration.
What C++ standard does the Abseil C++ build system require?
Both the Bazel and CMake build configurations enforce C++17 or higher. The CMakeLists.txt explicitly sets compile options such as -std=c++17, and the Bazel cc_library rules assume C++17-compatible toolchains.
Where are the main build configuration files located in the repository?
The key files are located at the repository root: MODULE.bazel and BUILD.bazel for Bazel builds, and CMakeLists.txt for CMake builds. Detailed CMake instructions are additionally documented in CMake/README.md.
Can I build only specific components of Abseil C++?
Yes. In Bazel, you can build specific targets such as //absl/strings or //absl/base rather than //absl/.... In CMake, you can disable unwanted components using cache variables defined in the top-level CMakeLists.txt, though the default configuration builds all standard libraries.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →