Skip to content

Getting Started with CMake Bindings

This guide walks you through generating CMake build files for Rice C++ bindings.

Prerequisites

You must first generate Rice C++ bindings. See Getting Started with Rice.

1. Create a configuration file

Create a file named cmake-bindings.yaml:

project: my_extension
output: ./ext/generated
format: CMake

include_dirs:
  - "${CMAKE_CURRENT_SOURCE_DIR}/../include"

Key options:

  • project — name used in the CMake project() command and build target. When omitted, only subdirectory CMakeLists.txt files are generated — useful when you manage the root project files yourself.
  • output — directory containing the Rice *-rb.cpp files. input defaults to output for CMake.
  • include_dirs — include directories added via target_include_directories. These are CMake expressions written directly into the generated CMakeLists.txt.

See Configuration for all options.

2. Generate CMake files

Run this after generating Rice bindings:

ruby-bindgen cmake-bindings.yaml

3. Build

cd ./ext/generated
cmake --preset linux-debug    # or macos-debug, msvc-debug, mingw-debug, etc.
cmake --build build/linux-debug

See Output for details on the available presets and generated files.