gstreamer-rs/gstreamer-sys/build.rs

78 lines
2.1 KiB
Rust
Raw Normal View History

2017-04-05 14:17:26 +00:00
extern crate pkg_config;
use pkg_config::{Config, Error};
use std::env;
use std::io::prelude::*;
use std::io;
use std::process;
fn main() {
if let Err(s) = find() {
let _ = writeln!(io::stderr(), "{}", s);
process::exit(1);
}
}
fn find() -> Result<(), Error> {
let package_name = "gstreamer-1.0";
let shared_libs = ["gstreamer-1.0"];
let version = if cfg!(feature = "v1_12") {
"1.12"
} else if cfg!(feature = "v1_10") {
"1.10"
} else if cfg!(feature = "v1_8") {
"1.8"
} else if cfg!(feature = "v1_6") {
"1.6"
} else if cfg!(feature = "v1_4") {
"1.4"
} else if cfg!(feature = "v1_2_3") {
"1.2.3"
} else if cfg!(feature = "v1_2") {
"1.2"
} else if cfg!(feature = "v1_0_10") {
"1.0.10"
2017-04-05 14:17:26 +00:00
} else {
"1.0"
};
if let Ok(lib_dir) = env::var("GTK_LIB_DIR") {
for lib_ in shared_libs.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib_);
}
println!("cargo:rustc-link-search=native={}", lib_dir);
return Ok(())
}
2017-06-07 14:14:32 +00:00
let target = env::var("TARGET").expect("TARGET environment variable doesn't exist");
2017-04-05 14:17:26 +00:00
let hardcode_shared_libs = target.contains("windows");
let mut config = Config::new();
config.atleast_version(version);
if hardcode_shared_libs {
config.cargo_metadata(false);
}
match config.probe(package_name) {
Ok(library) => {
if hardcode_shared_libs {
for lib_ in shared_libs.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib_);
}
for path in library.link_paths.iter() {
2017-06-07 14:14:32 +00:00
println!("cargo:rustc-link-search=native={}",
path.to_str().expect("library path doesn't exist"));
2017-04-05 14:17:26 +00:00
}
}
Ok(())
}
Err(Error::EnvNoPkgConfig(_)) | Err(Error::Command { .. }) => {
for lib_ in shared_libs.iter() {
println!("cargo:rustc-link-lib=dylib={}", lib_);
}
Ok(())
}
Err(err) => Err(err),
}
}