forked from georust/gdal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
34 lines (27 loc) · 1.24 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
use std::{env, str::FromStr};
fn main() {
let gdal_version_string = env::var("DEP_GDAL_VERSION_NUMBER")
.expect("The gdal-sys crate must emit the version of libgdal via cargo:version_number");
println!("GDAL version string: \"{gdal_version_string}\"");
// this version string is the result of:
// #define GDAL_COMPUTE_VERSION(maj,min,rev) ((maj)*1000000+(min)*10000+(rev)*100)
// so we can get the parts by doing the following
let gdal_version = i64::from_str(&gdal_version_string)
.expect("Could not convert gdal version string into number.");
let major = gdal_version / 1000000;
let minor = (gdal_version - major * 1000000) / 10000;
let patch = (gdal_version - major * 1000000 - minor * 10000) / 100;
if major < 3 {
panic!("The GDAL crate requires a GDAL version >= 3.0.0. Found {major}.{minor}.{patch}");
}
println!("cargo:rustc-cfg=gdal_{major}");
println!("cargo:rustc-cfg=gdal_{major}_{minor}");
println!("cargo:rustc-cfg=major_is_{major}");
println!("cargo:rustc-cfg=minor_is_{minor}");
for major in 3..=major {
println!("cargo:rustc-cfg=major_ge_{major}");
}
for minor in 0..=minor {
println!("cargo:rustc-cfg=minor_ge_{minor}");
}
}