Skip to content

Use cmake-file-api

CMake’s File API provides detailed build information that results in more accurate Bazel file generation.

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
  • CMake 3.14 or later
  • An existing CMake build directory (or ability to create one)
  1. Configure your CMake project

    Terminal window
    cd myproject
    cmake -S . -B build

    For a specific configuration:

    Terminal window
    cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
  2. Run migration with File API

    Terminal window
    rebaze migrate . --cmake-build-dir build

    For a specific configuration:

    Terminal window
    rebaze migrate . --cmake-build-dir build --cmake-config Release
  3. Require File API (optional)

    To fail if File API isn’t available:

    Terminal window
    rebaze migrate . --cmake-build-dir build --cmake-file-api-only
  1. rebaze reads the .cmake/api/v1/reply/ directory
  2. Parses the codemodel JSON files
  3. Extracts targets, sources, includes, and dependencies
  4. Generates Bazel files from this accurate data

Ensure CMake was configured with version 3.14+:

Terminal window
cmake --version

Re-run CMake configuration:

Terminal window
cmake -S . -B build

Some targets may only exist in certain configurations:

Terminal window
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
rebaze migrate . --cmake-build-dir build --cmake-config Debug