extern crate cmake;
use std::env;
use cmake::Config;
fn main() {
let mut cfg = Config::new("rocksdb");
cfg.define("CMAKE_VERBOSE_MAKEFILE", "ON")
.register_dep("SNAPPY")
.define("WITH_SNAPPY", "ON")
.define("FAIL_ON_WARNINGS", "OFF")
.build_target("rocksdb");
let snappy = env::var_os("DEP_SNAPPY_INCLUDE").expect("DEP_SNAPPY_INCLUDE is set in snappy.");
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS is set by cargo.");
let target_env = env::var("CARGO_CFG_TARGET_ENV").expect("CARGO_CFG_TARGET_ENV is set by cargo.");
if target_os.contains("windows") {
println!("cargo:rustc-link-lib=dylib={}", "rpcrt4");
println!("cargo:rustc-link-lib=dylib={}", "shlwapi");
}
if target_env.contains("msvc") {
cfg.env("SNAPPY_INCLUDE", snappy);
let features = env::var("CARGO_CFG_TARGET_FEATURE")
.expect("CARGO_CFG_TARGET_FEATURE is set by cargo.");
if features.contains("crt-static") {
cfg.define("WITH_MD_LIBRARY", "OFF");
}
} else {
cfg.define("SNAPPY_INCLUDE_DIR", snappy)
.define("SNAPPY_LIBRARIES", "/dev/null");
}
let portable = match &*env::var("PORTABLE").unwrap_or("ON".to_owned()) {
"OFF" => false,
_ => true,
};
if portable {
cfg.define("PORTABLE", "ON");
}
let out = cfg.build();
let mut build = out.join("build");
if target_os.contains("windows") && target_env.contains("msvc") {
let profile = match &*env::var("PROFILE").unwrap_or("debug".to_owned()) {
"bench" | "release" => "Release",
_ => "Debug",
};
build = build.join(profile);
}
println!("cargo:rustc-link-search=native={}", build.display());
println!("cargo:rustc-link-lib=static=rocksdb");
println!("cargo:rustc-link-lib=static=snappy");
if target_os.contains("macos") || target_os.contains("freebsd") || target_os.contains("openbsd") {
println!("cargo:rustc-link-lib=c++");
} else if !target_env.contains("msvc") && !target_os.contains("android") {
println!("cargo:rustc-link-lib=stdc++");
}
}