extern crate cc;
use std::env;
use std::path::Path;
use std::process::Command;
fn build_library(backend_macro: &str) {
let target = env::var("TARGET").unwrap();
let mut config = cc::Build::new();
config.flag_if_supported("-w");
config.include("nanovg/src");
config.file("nanovg/src/nanovg.c");
config.file("nanovg_shim.c");
config.define(backend_macro, None);
if target.contains("linux") {
println!("cargo:rustc-link-lib=GL");
} else if target.contains("darwin") {
println!("cargo:rustc-link-lib=framework=OpenGL");
} else if target.contains("windows") {
config.file("glad/glad.c");
config.include("glad");
}
config.compile("nanovg");
}
fn main() {
let backend_macro = ["GL3", "GL2", "GLES3", "GLES2"]
.iter()
.filter(|f| env::var(format!("CARGO_FEATURE_{}", f)).is_ok())
.map(|f| format!("NANOVG_{}_IMPLEMENTATION", f))
.next()
.expect(
"Unable to determine the backend / implementation. Have you enabled one of the features?",
);
if !Path::new("nanovg/.git").exists() {
let _ = Command::new("git").args(&["submodule", "update", "--init"])
.status();
}
build_library(&backend_macro);
}