Skip to content
This repository was archived by the owner on May 8, 2018. It is now read-only.

tomaka/cmake-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cmake-rs

This library allows you to invoke CMake during the compilation of a Rust program or library. This is very useful when you want to link C or C++ libraries with your Rust libraries.

It defines the cmake! macro which takes as parameter the path to CMakeLists.txt.

cmake!("path/to/cmakelists")

Example

Let's say that you want to create a library that links to C library which you can compile with CMake.

First, include the source code of the C library in your repository (usually with a git submodule).

mylib
|~c_library
| |~src
| | | ...
| | CMakeLists.txt
|~src
| | mylib.rs
| Cargo.toml

Then, add cmake-rs as a dependency to your project.

[dependencies.cmake]
git = "http://github.com/Tomaka17/cmake-rs"

Import cmake-rs your main rust file:

#![feature(phase)]

#[phase(plugin)]
extern crate cmake;

And finally, call the cmake! macro somewhere in the code:

cmake!("c_library")

The argument of the macro is the location of the CMakeLists.txt.

Now the C library will be built and will be available for the Rust compiler:

#[link(name="c_library")]
extern {
    ...
}

How does it work?

The cmake! macro will invoke CMake and output all libraries to <path_of_lib>/cmake-build-result. It will use <path_of_lib>/cmake-build as the build directory.

<path_of_lib>/cmake-build-result is then added to the list of directories where the Rust compiler will look for libraries. You still need to add #[link(name="lib")] inside your project.

About

Easily build projets using CMake with the Rust compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages