use std::env;
use std::path::PathBuf;
fn main() {
if env::var("CARGO_FEATURE_TURBOJPEG").is_err() {
return;
}
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
match target_os.as_str() {
"macos" => {
let homebrew_paths = vec![
"/opt/homebrew/opt/jpeg-turbo/lib", "/usr/local/opt/jpeg-turbo/lib", ];
for path in homebrew_paths {
let path_buf = PathBuf::from(path);
if path_buf.exists() {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-lib=turbojpeg");
return;
}
}
println!("cargo:rustc-link-lib=turbojpeg");
}
"linux" => {
if let Ok(target_arch) = env::var("CARGO_CFG_TARGET_ARCH") {
let lib_path = match target_arch.as_str() {
"x86_64" => "/usr/lib/x86_64-linux-gnu",
"aarch64" => "/usr/lib/aarch64-linux-gnu",
"arm" => "/usr/lib/arm-linux-gnueabihf",
_ => "/usr/lib",
};
println!("cargo:rustc-link-search=native={}", lib_path);
}
println!("cargo:rustc-link-lib=turbojpeg");
}
"windows" => {
if let Ok(vcpkg_root) = env::var("VCPKG_ROOT") {
let lib_path = format!("{}\\installed\\x64-windows\\lib", vcpkg_root);
println!("cargo:rustc-link-search=native={}", lib_path);
} else if let Ok(vcpkg_root) = env::var("VCPKG_INSTALLATION_ROOT") {
let lib_path = format!("{}\\installed\\x64-windows\\lib", vcpkg_root);
println!("cargo:rustc-link-search=native={}", lib_path);
}
println!("cargo:rustc-link-lib=turbojpeg");
}
_ => {
println!("cargo:rustc-link-lib=turbojpeg");
}
}
}