allow NETCDF_DIR to control linked lib

This commit is contained in:
Magnus Ulimoen 2020-11-17 09:36:38 +01:00
parent c1bae434ab
commit fec7949272
2 changed files with 12 additions and 2 deletions

View File

@ -2,3 +2,7 @@
Rust bindings to `netcdf-c` to locate and link the system libraries neccessary to use `netcdf`.
This library can also build `hdf5` and `netcdf` from source, to allow a fully static linking experience. This is enabled with the `static` feature.
## Detection of netCDF
By default the crate uses the system installed `netCDF`. The environment variable `NETCDF_DIR` can be used to use a particular version of `netCDF`. This variable is ignored if compiling from sources.

View File

@ -14,7 +14,13 @@ fn main() {
println!("cargo:rustc-link-lib=static={}", netcdf_lib);
println!("cargo:rustc-link-search=native={}", netcdf_path);
} else {
// Link to the system netcdf
println!("cargo:rustc-link-lib=netcdf");
println!("cargo:rerun-if-env-changed=NETCDF_DIR");
if let Ok(dir) = std::env::var("NETCDF_DIR") {
println!("cargo:rustc-link-search={}/lib", dir);
println!("cargo:rustc-link-lib=netcdf");
} else {
// Link to the system netcdf
println!("cargo:rustc-link-lib=netcdf");
}
}
}