forked from georust/netcdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
102 lines (89 loc) · 3.71 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
macro_rules! feature {
($feature:expr) => {
std::env::var(concat!("CARGO_FEATURE_", $feature))
};
}
fn get_hdf5_version() -> String {
let (major, minor, patch) = std::env::vars()
.filter_map(|(key, value)| {
key.strip_prefix("DEP_HDF5_VERSION_").map(|key| {
assert_eq!(value, "1");
let mut version = key.split('_');
let major: usize = version.next().unwrap().parse().unwrap();
let minor: usize = version.next().unwrap().parse().unwrap();
let patch: usize = version.next().unwrap().parse().unwrap();
(major, minor, patch)
})
})
.max()
.expect("Crate hdf5 should have emitted a hdf5 version");
format!("{major}.{minor}.{patch}")
}
fn main() {
println!("cargo::rerun-if-changed=build.rs");
let hdf5_incdir = std::env::var("DEP_HDF5_INCLUDE").unwrap();
let mut hdf5_lib = std::env::var("DEP_HDF5_LIBRARY").unwrap();
let mut hdf5_hl_lib = std::env::var("DEP_HDF5_HL_LIBRARY").unwrap();
#[cfg(unix)]
{
let hdf5_root = format!("{hdf5_incdir}/../");
let mut hdf5_libdir = format!("{hdf5_root}/lib/");
if !std::path::Path::new(&hdf5_libdir).exists() {
hdf5_libdir = format!("{hdf5_root}/lib64/");
}
hdf5_lib = format!("{hdf5_libdir}/{hdf5_lib}.a");
hdf5_hl_lib = format!("{hdf5_libdir}/{hdf5_hl_lib}.a");
}
let hdf5_version = get_hdf5_version();
let mut netcdf_config = cmake::Config::new("source");
netcdf_config
.define("BUILD_SHARED_LIBS", "OFF")
.define("NC_FIND_SHARED_LIBS", "OFF")
.define("BUILD_UTILITIES", "OFF")
.define("ENABLE_EXAMPLES", "OFF")
.define("ENABLE_DAP_REMOTE_TESTS", "OFF")
.define("ENABLE_TESTS", "OFF")
.define("ENABLE_EXTREME_NUMBERS", "OFF")
.define("ENABLE_PARALLEL_TESTS", "OFF")
.define("ENABLE_FILTER_TESTING", "OFF")
.define("ENABLE_BASH_SCRIPT_TESTING", "OFF")
.define("ENABLE_PLUGINS", "OFF")
.define("PLUGIN_INSTALL_DIR", "OFF")
//
.define("HDF5_VERSION", &hdf5_version)
.define("HDF5_C_LIBRARY", &hdf5_lib)
.define("HDF5_HL_LIBRARY", &hdf5_hl_lib)
.define("HDF5_INCLUDE_DIR", hdf5_incdir)
//
.define("ENABLE_LIBXML2", "OFF") // Use bundled xml2
//
.define("ENABLE_PARALLEL4", "OFF") // TODO: Enable mpi support
//
.define("ENABLE_NCZARR", "OFF") // TODO: requires a bunch of deps
//
.define("ENABLE_DAP", "OFF") // TODO: feature flag, requires curl
.define("ENABLE_BYTERANGE", "OFF") // TODO: feature flag, requires curl
.define("ENABLE_DAP_REMOTE_TESTS", "OFF")
//
.profile("RelWithDebInfo"); // TODO: detect opt-level
let zlib_include_dir = std::env::var("DEP_Z_INCLUDE").unwrap();
netcdf_config.define("ZLIB_ROOT", format!("{zlib_include_dir}/.."));
if feature!("DAP").is_ok() {
netcdf_config.define("ENABLE_DAP", "ON");
netcdf_config.define("ENABLE_BYTERANGE", "ON");
}
if feature!("MPI").is_ok() {
panic!("MPI feature was requested but the static build of netcdf does not support this");
}
let netcdf = netcdf_config.build();
// Only forward link options to netcdf-sys, so netcdf-sys can
// optionally choose not to use this build
println!("cargo::metadata=lib=netcdf");
let search_path = format!("{}/lib", netcdf.display());
if std::path::Path::new(&search_path).exists() {
println!("cargo::metadata=search={search_path}");
} else {
let search_path = format!("{}/lib64", netcdf.display());
println!("cargo::metadata=search={search_path}");
}
}