Use cmake-file-api
CMake’s File API provides detailed build information that results in more accurate Bazel file generation.
Why Use cmake-file-api?
Section titled “Why Use cmake-file-api?”The default CMakeLists.txt parser works well for most projects, but cmake-file-api provides:
- Exact source lists - Including generated files
- Resolved paths - Absolute include directories
- Actual compiler flags - As CMake would use them
- Configuration-specific settings - Debug vs Release
Prerequisites
Section titled “Prerequisites”- CMake 3.14 or later
- An existing CMake build directory (or ability to create one)
-
Configure your CMake project
Terminal window cd myprojectcmake -S . -B buildFor a specific configuration:
Terminal window cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -
Run migration with File API
Terminal window rebaze migrate . --cmake-build-dir buildFor a specific configuration:
Terminal window rebaze migrate . --cmake-build-dir build --cmake-config Release -
Require File API (optional)
To fail if File API isn’t available:
Terminal window rebaze migrate . --cmake-build-dir build --cmake-file-api-only
How It Works
Section titled “How It Works”- rebaze reads the
.cmake/api/v1/reply/directory - Parses the codemodel JSON files
- Extracts targets, sources, includes, and dependencies
- Generates Bazel files from this accurate data
Troubleshooting
Section titled “Troubleshooting””Failed to load cmake-file-api”
Section titled “”Failed to load cmake-file-api””Ensure CMake was configured with version 3.14+:
cmake --versionRe-run CMake configuration:
cmake -S . -B buildMissing targets
Section titled “Missing targets”Some targets may only exist in certain configurations:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debugrebaze migrate . --cmake-build-dir build --cmake-config Debug