CMake Preset
A Rust library for building C++ code using CMake Presets in Rust projects.
Overview
This library provides a simple and type-safe way to integrate CMake builds into Rust projects. It uses the builder pattern with type states to ensure all required steps are performed in the correct order when building C++ code with CMake Presets.
Features
- Type-safe builder pattern that enforces correct build steps order
- Automatic Cargo integration for linking C++ libraries
- Cross-platform support (Windows with MSVC, Linux with GCC)
- CMake Preset support for consistent builds
Usage
Add this to your Cargo.toml:
[]
= { = "0.1.0" }
Create a build.rs file in your project:
use *;
Then you can link to and use your C++ functions in Rust:
unsafe extern "C"
Builder Pattern and Type States
The library uses Rust's type system to enforce correct usage at compile time:
StatusSetProjectDir- Initial state, requires setting the project directoryStatusSetConfigPreset- Requires setting the CMake preset nameStatusSetLibraryName- Requires setting the static library name of generatedStatusConfig- Ready to run CMake configurationStatusBuild- Ready to build the project
This ensures that all required steps are performed in the correct order.
Example
See the example directory for a complete example of how to use this library to build and link a C++ library in a Rust project.