extern crate bindgen;
use std::env;
use std::path::PathBuf;
fn main() {
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
let mut dir_builder = std::fs::DirBuilder::new();
dir_builder.recursive(true);
let cyclonedds_dir = out_dir.join("cyclonedds-build");
dir_builder.create(&cyclonedds_dir).unwrap();
let mut cyclonedds = cmake::Config::new("cyclonedds");
let mut cyclonedds = cyclonedds.out_dir(cyclonedds_dir);
let mut bindings = bindgen::Builder::default();
#[cfg(feature = "iceoryx")]
{
let supported;
#[cfg(target_os = "windows")]
{
print!("cargo:warning=Cyclone DDS Iceoryx PSMX plugin is not supported on Windows!");
supported = false;
}
#[cfg(not(target_os = "windows"))]
{
supported = true;
}
if !supported {
std::process::exit(1);
}
let iceoryx_dir = out_dir.join("iceoryx-build");
dir_builder.create(&iceoryx_dir).unwrap();
let mut iceoryx = cmake::Config::new("iceoryx/iceoryx_meta");
let iceoryx = iceoryx
.define("BUILD_SHARED_LIBS", "OFF")
.out_dir(iceoryx_dir)
.build();
let iceoryx_install_path = iceoryx.as_os_str();
let iceoryx_lib = iceoryx.join("lib");
println!("cargo:rustc-link-search=native={}", iceoryx_lib.display());
println!("cargo:rustc-link-lib=static=iceoryx_hoofs");
println!("cargo:rustc-link-lib=static=iceoryx_posh");
println!("cargo:rustc-link-lib=static=iceoryx_platform");
cyclonedds = cyclonedds
.env("iceoryx_hoofs_DIR", iceoryx_install_path)
.env("iceoryx_posh_DIR", iceoryx_install_path)
.define("ENABLE_ICEORYX", "YES");
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=acl");
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
println!("cargo:rustc-link-lib=stdc++");
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-lib=c++");
}
#[cfg(not(feature = "iceoryx"))]
{
cyclonedds = cyclonedds.define("ENABLE_ICEORYX", "NO");
}
cyclonedds = cyclonedds
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_IDLC", "OFF")
.define("BUILD_DDSPERF", "OFF")
.define("ENABLE_LTO", "NO")
.define("ENABLE_SSL", "NO")
.define("ENABLE_SECURITY", "NO")
.define("CMAKE_INSTALL_LIBDIR", "lib");
#[cfg(all(debug_assertions, target_os = "windows"))]
let cyclonedds = cyclonedds.profile("Release");
let cyclonedds = cyclonedds.build();
let cyclonedds_include = cyclonedds.join("include");
let cyclonedds_lib = cyclonedds.join("lib");
println!(
"cargo:rustc-link-search=native={}",
cyclonedds_lib.display()
);
println!("cargo:rustc-link-lib=static=ddsc");
#[cfg(target_os = "windows")]
println!("cargo:rustc-link-lib=Iphlpapi");
#[cfg(target_os = "windows")]
println!("cargo:rustc-link-lib=DbgHelp");
#[cfg(target_os = "windows")]
println!("cargo:rustc-link-lib=Bcrypt");
let cyclocut_dir = out_dir.join("cyclocut-build");
dir_builder.create(&cyclocut_dir).unwrap();
let mut cyclocut = cmake::Config::new("cyclocut");
#[cfg(all(debug_assertions, target_os = "windows"))]
let cyclocut = cyclocut.profile("Release");
let cyclocut = cyclocut
.env("CYCLONE_INCLUDE", &cyclonedds_include)
.env("CYCLONE_LIB", &cyclonedds_lib)
.define("CYCLONE_INCLUDE", cyclonedds_include.clone())
.define("CYCLONE_LIB", cyclonedds_lib.clone())
.define("BUILD_SHARED_LIBS", "OFF")
.define("CMAKE_INSTALL_LIBDIR", "lib")
.out_dir(cyclocut_dir)
.build();
let cyclocut_include = cyclocut.join("include");
let cyclocut_lib = cyclocut.join("lib");
println!("cargo:rustc-link-search=native={}", cyclocut_lib.display());
println!("cargo:rustc-link-lib=static=cdds-util");
bindings = bindings
.header("wrapper.h")
.clang_arg(format!("-I{}", cyclonedds_include.to_str().unwrap()))
.clang_arg(format!("-I{}", cyclocut_include.to_str().unwrap()))
.generate_comments(false);
#[cfg(target_os = "windows")]
let bindings = bindings
.clang_arg("-Wno-invalid-token-paste")
.blocklist_type("^(.*IMAGE_TLS_DIRECTORY.*)$");
let bindings = bindings.generate().expect("Unable to generate bindings");
bindings
.write_to_file(out_dir.join("bindings.rs"))
.expect("Couldn't write bindings!");
}