|
| 1 | +macro_rules! feature { |
| 2 | + ($feature:expr) => { |
| 3 | + std::env::var(concat!("CARGO_FEATURE_", $feature)) |
| 4 | + }; |
| 5 | +} |
| 6 | + |
1 | 7 | fn main() { |
| 8 | + println!("cargo:rerun-if-changed=build.rs"); |
| 9 | + if feature!("STATIC").is_ok() { |
| 10 | + build(); |
| 11 | + return; |
| 12 | + } |
| 13 | + // Link to the system netcdf |
2 | 14 | println!("cargo:rustc-link-lib=netcdf"); |
3 | 15 | println!("cargo:rerun-if-changed=build.rs"); |
4 | 16 | } |
| 17 | + |
| 18 | +fn build() { |
| 19 | + let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap(); |
| 20 | + let hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap(); |
| 21 | + let hdf5_hl_lib = std::env::var("DEP_HDF5_HL_LIBRARY").unwrap(); |
| 22 | + |
| 23 | + |
| 24 | + let netcdf = cmake::Config::new("source") |
| 25 | + .define("BUILD_SHARED_LIBS", "OFF") |
| 26 | + .define("NC_FIND_SHARED_LIBS", "OFF") |
| 27 | + .define("BUILD_UTILITIES", "OFF") |
| 28 | + .define("ENABLE_EXAMPLES", "OFF") |
| 29 | + .define("ENABLE_DAP_REMOTE_TESTS", "OFF") |
| 30 | + .define("ENABLE_TESTS", "OFF") |
| 31 | + .define("ENABLE_EXTREME_NUMBERS", "OFF") |
| 32 | + .define("ENABLE_PARALLEL_TESTS", "OFF") |
| 33 | + .define("ENABLE_FILTER_TESTING", "OFF") |
| 34 | + .define("ENABLE_BASH_SCRIPT_TESTING", "OFF") |
| 35 | + // |
| 36 | + .define("HDF5_C_LIBRARY", &hdf5_lib) |
| 37 | + .define("HDF5_HL_LIBRARY", &hdf5_hl_lib) |
| 38 | + .define("HDF5_INCLUDE_DIR", hdf5_incdir) |
| 39 | + // |
| 40 | + .define("ENABLE_DAP", "OFF") // TODO: feature flag, requires curl |
| 41 | + // |
| 42 | + .profile("RelWithDebInfo") // TODO: detect opt-level |
| 43 | + .very_verbose(true) |
| 44 | + .build(); |
| 45 | + |
| 46 | + println!("cargo:rustc-link-lib=static=netcdf"); |
| 47 | + println!("cargo:rustc-link-search=native={}/lib", netcdf.display()); |
| 48 | +} |
0 commit comments