|
| 1 | +fn main() { |
| 2 | + let sqlite3_include_dir = |
| 3 | + std::env::var("DEP_SQLITE3_INCLUDE").expect("This is set by libsqlite3-sys"); |
| 4 | + let sqlite3_lib_dir = std::env::var("DEP_SQLITE3_LIB_DIR").expect("set by libsqlite3-sys"); |
| 5 | + let proj_root = PathBuf::from(std::env::var("DEP_PROJ_ROOT").expect("set by proj-sys")); |
| 6 | + let proj_lib = if proj_root.join("lib").join("proj_d.lib").exists() { |
| 7 | + "proj_d.lib" |
| 8 | + } else if proj_root.join("lib").join("proj.lib").exists() { |
| 9 | + "proj.lib" |
| 10 | + } else { |
| 11 | + "libproj.a" |
| 12 | + }; |
| 13 | + |
| 14 | + let res = cmake::Config::new("source") |
| 15 | + .define("GDAL_BUILD_OPTIONAL_DRIVERS", "OFF") |
| 16 | + .define("OGR_BUILD_OPTIONAL_DRIVERS", "OFF") |
| 17 | + .define("GDAL_USE_INTERNAL_LIBS", "ON") |
| 18 | + .define("GDAL_USE_EXTERNAL_LIBS", "OFF") |
| 19 | + .define("BUILD_SHARED_LIBS", "OFF") |
| 20 | + .define("BUILD_STATIC_LIBS", "ON") |
| 21 | + .define("BUILD_APPS", "OFF") |
| 22 | + .define("BUILD_DOCS", "OFF") |
| 23 | + .define("BUILD_TESTING", "OFF") |
| 24 | + .define("BUILD_GMOCK", "OFF") |
| 25 | + .define("PROJ_INCLUDE_DIR", format!("{proj_root}/include")) |
| 26 | + .define("PROJ_LIBRARY", format!("{proj_root}/lib/{proj_lib}")) |
| 27 | + // enable the gpkg driver |
| 28 | + .define("GDAL_USE_SQLITE3", "ON") |
| 29 | + .define("SQLite3_INCLUDE_DIR", sqlite3_include_dir) |
| 30 | + .define("SQLite3_LIBRARY", format!("{sqlite3_lib_dir}/libsqlite3.a")) |
| 31 | + .define("OGR_ENABLE_DRIVER_GPKG", "ON") |
| 32 | + .pic(true) |
| 33 | + .build(); |
| 34 | + |
| 35 | + // sometimes it's lib and sometimes it's lib64 and sometimes `build/lib` |
| 36 | + let lib_dir = res.join("lib64"); |
| 37 | + println!( |
| 38 | + "cargo:rustc-link-search=native={}", |
| 39 | + lib_dir.to_str().unwrap() |
| 40 | + ); |
| 41 | + let lib_dir = res.join("lib"); |
| 42 | + println!( |
| 43 | + "cargo:rustc-link-search=native={}", |
| 44 | + lib_dir.to_str().unwrap() |
| 45 | + ); |
| 46 | + let lib_dir = res.join("build/lib"); |
| 47 | + println!( |
| 48 | + "cargo:rustc-link-search=native={}", |
| 49 | + lib_dir.to_str().unwrap() |
| 50 | + ); |
| 51 | + |
| 52 | + //gdal likes to create gdal_d when configured as debug and on MSVC, so link to that one if it exists |
| 53 | + if res.join("lib").join("gdald.lib").exists() { |
| 54 | + println!("cargo:rustc-link-lib=static=gdald"); |
| 55 | + } else { |
| 56 | + println!("cargo:rustc-link-lib=static=gdal"); |
| 57 | + } |
| 58 | +} |
0 commit comments