diff --git a/netcdf-sys/README.md b/netcdf-sys/README.md index e03a127..f0a33e1 100644 --- a/netcdf-sys/README.md +++ b/netcdf-sys/README.md @@ -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. diff --git a/netcdf-sys/build.rs b/netcdf-sys/build.rs index f1010a6..e6843d2 100644 --- a/netcdf-sys/build.rs +++ b/netcdf-sys/build.rs @@ -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"); + } } }