Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fltk-rs/fltk-build
Create native C/C++ fltk/cfltk modules to be used from Rust
https://github.com/fltk-rs/fltk-build
Last synced: about 2 months ago
JSON representation
Create native C/C++ fltk/cfltk modules to be used from Rust
- Host: GitHub
- URL: https://github.com/fltk-rs/fltk-build
- Owner: fltk-rs
- License: mit
- Created: 2021-11-19T04:31:13.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-03T11:53:34.000Z (about 3 years ago)
- Last Synced: 2024-08-08T22:15:52.685Z (5 months ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fltk-build
Allows creating native C/C++ fltk/cfltk modules to be used from Rust. This is done by exposing the include paths and lib paths from the built fltk-sys crate on your system.
## Usage
```toml
[dependencies] # or [dev-dependencies]
fltk = "1.2.17" # this won't work with fltk-bundled
# You might need fltk-sys and paste if you use fltk's trait macros[build-dependencies]
fltk-build = "0.1"
fltk-sys = "1.2.17"
cc = "1" # or cmake = "0.1"
```## Example
build.rs (using `cc`):
```rust
use fltk_build::fltk_out_dir;fn main() {
let fltk_out_dir = fltk_out_dir().unwrap();cc::Build::new()
.file("src/my_wid.cpp")
.cpp(true)
.flag_if_supported("-w")
.flag_if_supported("-fno-rtti")
.include(&fltk_out_dir.join("include"))
.compile("my_wid");
}
```build.rs (using `cmake-rs`):
```rust
use std::env;
use std::path::PathBuf;
use fltk_build::fltk_out_dir;fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let fltk_out_dir = fltk_out_dir().unwrap();cmake::Config::new("src")
.define(
"CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES",
fltk_out_dir.join("include"),
)
.build();println!(
"cargo:rustc-link-search=native={}",
out_dir.display()
);
println!("cargo:rustc-link-lib=static=my_wid");match target_os.as_str() {
"windows" => (), // doesn't need explicit linking to the C++ stdlib
"macos" => println!("cargo:rustc-link-lib=c++"),
_ => println!("cargo:rustc-link-lib=stdc++"),
}
}
```In your C/C++ files, you can directly access the FLTK and cfltk headers:
```c++
#include
#include
```If you're using CMake, a minimal CMakeLists.txt example:
```cmake
cmake_minimum_required(VERSION 3.0)
project(wid)if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions")
endif()add_library(my_wid my_wid.cpp)
install(TARGETS my_wid DESTINATION ${CMAKE_INSTALL_PREFIX})
```Example crate (not published on crates.io) using fltk-build:
https://github.com/fltk-rs/fltk-flow