fn main() {
println!("cargo:rerun-if-changed=build.rs");
let json_c_path = cmake::Config::new("json-c")
.define("BUILD_SHARED_LIBS", "OFF")
.define("BUILD_TESTING", "OFF")
.build();
let gsl_path = cmake::Config::new("gsl")
.define("BUILD_SHARED_LIBS", "OFF")
.define("NO_AMPL_BINDINGS", "1")
.build();
let mut config = cmake::Config::new("source");
config.define("MEOS", "1").very_verbose(true).define("BUILD_SHARED_LIBS", "OFF").define("NPOINT", "OFF");
let mut prefix_paths = Vec::new();
prefix_paths.push(json_c_path.display().to_string());
prefix_paths.push(gsl_path.display().to_string());
let geos_include_env = std::env::var("DEP_GEOS_INCLUDEDIR")
.or_else(|_| std::env::var("DEP_GEOS_INCLUDE"));
if let Ok(geos_root) = std::env::var("DEP_GEOSSRC_ROOT") {
let root_path = std::path::Path::new(&geos_root);
let include_path = root_path.join("include");
let lib_path = root_path.join("lib").join("libgeos_c.a");
config.define("GEOS_INCLUDE_DIR", include_path);
config.define("GEOS_LIBRARY", lib_path);
prefix_paths.push(geos_root);
} else if let Ok(geos_include) = geos_include_env {
config.define("GEOS_INCLUDE_DIR", &geos_include);
let path = std::path::Path::new(&geos_include);
if let Some(parent) = path.parent() {
if parent.join("libgeos_c.a").exists() {
config.define("GEOS_LIBRARY", parent.join("libgeos_c.a").as_os_str());
if let Some(grandparent) = parent.parent() {
prefix_paths.push(grandparent.to_string_lossy().to_string());
}
} else {
prefix_paths.push(parent.to_string_lossy().to_string());
let lib_path = parent.join("lib").join("libgeos_c.a");
if lib_path.exists() {
config.define("GEOS_LIBRARY", lib_path.as_os_str());
} else {
let build_lib_path = parent.join("build").join("lib").join("libgeos_c.a");
if build_lib_path.exists() {
config.define("GEOS_LIBRARY", build_lib_path.as_os_str());
}
}
}
}
}
if let Ok(proj_root) = std::env::var("DEP_PROJ_ROOT") {
let root_path = std::path::Path::new(&proj_root);
let include_path = root_path.join("include");
let lib_path = root_path.join("lib").join("libproj.a");
config.define("PROJ_INCLUDE_DIRS", include_path);
config.define("PROJ_LIBRARIES", lib_path);
prefix_paths.push(proj_root);
} else if let Ok(proj_include) = std::env::var("DEP_PROJ_INCLUDE") {
config.define("PROJ_INCLUDE_DIRS", &proj_include);
let path = std::path::Path::new(&proj_include);
if let Some(parent) = path.parent() {
prefix_paths.push(parent.to_string_lossy().to_string());
let lib_path = parent.join("lib").join("libproj.a");
if lib_path.exists() {
config.define("PROJ_LIBRARIES", lib_path.as_os_str());
} else {
let build_lib_path = parent.join("build").join("lib").join("libproj.a");
if build_lib_path.exists() {
config.define("PROJ_LIBRARIES", build_lib_path.as_os_str());
}
}
}
}
if !prefix_paths.is_empty() {
let joined_paths = prefix_paths.join(";"); config.define("CMAKE_PREFIX_PATH", joined_paths);
}
let libmeos = config.build();
println!("cargo:lib=meos");
let search_path = libmeos.display().to_string();
assert!(std::path::Path::new(&search_path).exists());
println!("cargo:search={}", search_path);
println!("cargo:rustc-link-search=native={}/lib", json_c_path.display());
println!("cargo:rustc-link-search=native={}/lib64", json_c_path.display()); println!("cargo:rustc-link-lib=static=json-c");
println!("cargo:rustc-link-search=native={}/lib", gsl_path.display());
println!("cargo:rustc-link-search=native={}/lib64", gsl_path.display());
println!("cargo:rustc-link-lib=static=gsl");
println!("cargo:rustc-link-lib=static=gslcblas");
}