use std::env;
use std::path::PathBuf;
use std::process::Command;
use bindgen;
use cmake;
fn main() {
let docs = cfg!(feature = "docs-only");
if !docs {
if !PathBuf::from("transmission/.git").exists() {
let _ = Command::new("git")
.args(&["submodule", "update", "--init --recursive"])
.status();
}
let dst = cmake::Config::new("transmission")
.define("ENABLE_DAEMON", "OFF")
.define("ENABLE_GTK", "OFF")
.define("ENABLE_QT", "OFF")
.define("ENABLE_MAC", "OFF")
.define("ENABLE_UTILS", "OFF")
.define("ENABLE_CLI", "OFF")
.define("ENABLE_TESTS", "OFF")
.define("ENABLE_LIGHTWEIGHT", "OFF")
.define("ENABLE_NLS", "OFF")
.define("INSTALL_DOC", "OFF")
.define("USE_SYSTEM_DHT", "OFF")
.define("USE_SYSTEM_MINIUPNPC", "OFF")
.define("USE_SYSTEM_NATPMP", "OFF")
.define("USE_SYSTEM_UTP", "OFF")
.define("USE_SYSTEM_B64", "OFF")
.define("WITH_INOTIFY", "OFF")
.define("WITH_KQUEUE", "OFF")
.define("WITH_LIBAPPINDICATOR", "OFF")
.define("WITH_SYSTEMD", "OFF")
.define("ENABLE_UTP", "ON")
.define("INSTALL_LIB", "ON")
.define("WITH_CRYPTO", "openssl")
.define("USE_SYSTEM_EVENT2", "ON")
.build();
println!(
"cargo:rustc-link-search=native={}",
dst.join("lib64").display()
);
println!("cargo:rustc-link-lib=static=transmission");
let dst_natpmp = cmake::Config::new("transmission/third-party/libnatpmp").build();
println!(
"cargo:rustc-link-search=native={}",
dst_natpmp.join("lib").display()
);
println!("cargo:rustc-link-lib=static=natpmp");
let dst_utp = cmake::Config::new("transmission/third-party/libutp").build();
println!(
"cargo:rustc-link-search=native={}",
dst_utp.join("lib").display()
);
println!("cargo:rustc-link-lib=static=utp");
let dst_miniupnpc = cmake::Config::new("transmission/third-party/miniupnpc").build();
println!(
"cargo:rustc-link-search=native={}",
dst_miniupnpc.join("lib").display()
);
println!("cargo:rustc-link-lib=static=miniupnpc");
let dst_dht = cmake::Config::new("transmission/third-party/dht").build();
println!(
"cargo:rustc-link-search=native={}",
dst_dht.join("lib").display()
);
println!("cargo:rustc-link-lib=static=dht");
let dst_b64 = cmake::Config::new("transmission/third-party/libb64").build();
println!(
"cargo:rustc-link-search=native={}",
dst_b64.join("lib").display()
);
println!("cargo:rustc-link-lib=static=b64");
}
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.layout_tests(false)
.default_enum_style(bindgen::EnumVariation::Rust)
.rustfmt_bindings(docs)
.generate()
.expect("Failed to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Failed to write bindings");
}