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 CMakeproject()command and build target. When omitted, only subdirectoryCMakeLists.txtfiles are generated — useful when you manage the root project files yourself.output— directory containing the Rice*-rb.cppfiles.inputdefaults tooutputfor CMake.include_dirs— include directories added viatarget_include_directories. These are CMake expressions written directly into the generatedCMakeLists.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.