use cmake::Config;
use std::path::PathBuf;
fn main() {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let v4_path = manifest_dir.join("vendor/V4");
let v4front_path = manifest_dir.join("vendor/V4-front");
let mut v4_config = Config::new(&v4_path);
v4_config
.define("V4_BUILD_TESTS", "OFF")
.define("V4_BUILD_TOOLS", "OFF")
.define("V4_ENABLE_MOCK_HAL", "OFF")
.out_dir(manifest_dir.join("target/v4"));
#[cfg(target_os = "windows")]
{
if cfg!(debug_assertions) {
v4_config.profile("Debug");
} else {
v4_config.profile("Release");
}
}
let v4_dst = v4_config.build();
let mut v4front_config = Config::new(&v4front_path);
v4front_config
.define("V4FRONT_BUILD_TESTS", "OFF")
.define("V4_SRC_DIR", v4_path.to_str().unwrap())
.out_dir(manifest_dir.join("target/v4front"));
#[cfg(target_os = "windows")]
{
if cfg!(debug_assertions) {
v4front_config.profile("Debug");
} else {
v4front_config.profile("Release");
}
}
let v4front_dst = v4front_config.build();
#[cfg(target_os = "windows")]
{
let profile = if cfg!(debug_assertions) {
"Debug"
} else {
"Release"
};
let v4_lib_path = v4_dst.join("lib");
println!("cargo:rustc-link-search=native={}", v4_lib_path.display());
println!("cargo:warning=V4 lib path: {}", v4_lib_path.display());
let v4front_build_path = v4front_dst.join("build").join(&profile);
println!(
"cargo:rustc-link-search=native={}",
v4front_build_path.display()
);
println!(
"cargo:warning=V4-front build path: {}",
v4front_build_path.display()
);
let v4front_build_root = v4front_dst.join("build");
println!(
"cargo:rustc-link-search=native={}",
v4front_build_root.display()
);
if let Ok(entries) = std::fs::read_dir(&v4front_build_path) {
println!("cargo:warning=V4-front build/{} contents:", profile);
for entry in entries.flatten() {
println!("cargo:warning= - {}", entry.file_name().to_string_lossy());
}
} else {
println!("cargo:warning=V4-front build/{} does not exist!", profile);
}
if let Ok(entries) = std::fs::read_dir(&v4front_build_root) {
println!("cargo:warning=V4-front build/ root contents:");
for entry in entries.flatten() {
let name = entry.file_name();
println!("cargo:warning= - {}", name.to_string_lossy());
}
} else {
println!("cargo:warning=V4-front build/ root does not exist!");
}
if let Ok(entries) = std::fs::read_dir(&v4front_dst) {
println!(
"cargo:warning=V4-front dst ({}) contents:",
v4front_dst.display()
);
for entry in entries.flatten() {
println!("cargo:warning= - {}", entry.file_name().to_string_lossy());
}
}
}
#[cfg(not(target_os = "windows"))]
{
println!("cargo:rustc-link-search=native={}/lib", v4_dst.display());
println!(
"cargo:rustc-link-search=native={}/build",
v4front_dst.display()
);
}
println!("cargo:rustc-link-lib=static=v4vm");
println!("cargo:rustc-link-lib=static=v4front");
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-lib=c++");
#[cfg(all(not(target_os = "macos"), not(target_os = "windows")))]
println!("cargo:rustc-link-lib=stdc++");
println!("cargo:rerun-if-changed={}/src", v4_path.display());
println!("cargo:rerun-if-changed={}/include", v4_path.display());
println!("cargo:rerun-if-changed={}/src", v4front_path.display());
println!("cargo:rerun-if-changed={}/include", v4front_path.display());
}