diff --git a/gdal-src/build.rs b/gdal-src/build.rs index b123a397..8025b98b 100644 --- a/gdal-src/build.rs +++ b/gdal-src/build.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + macro_rules! handle_ogr_driver { ($config: ident, $driver: literal) => { if cfg!(feature = $driver) { @@ -81,7 +83,11 @@ fn main() { .define("BUILD_GMOCK", "OFF") .define( "PROJ_INCLUDE_DIR", - format!("{}/include", proj_root.display()), + format!( + "{}{}include", + proj_root.display(), + std::path::MAIN_SEPARATOR + ), ) .define("PROJ_LIBRARY", proj_library) .define("ACCEPT_MISSING_LINUX_FS_HEADER", "ON"); @@ -194,11 +200,14 @@ fn main() { let sqlite3_include_dir = std::env::var("DEP_SQLITE3_INCLUDE").expect("This is set by libsqlite3-sys"); let sqlite3_lib_dir = std::env::var("DEP_SQLITE3_LIB_DIR").expect("set by libsqlite3-sys"); + let mut sqlite3_lib = PathBuf::from(sqlite3_lib_dir); + sqlite3_lib.push("libsqlite3.a"); + let sqlite3_include_dir = PathBuf::from(sqlite3_include_dir); config .define("GDAL_USE_SQLITE3", "ON") - .define("SQLite3_INCLUDE_DIR", sqlite3_include_dir) - .define("SQLite3_LIBRARY", format!("{sqlite3_lib_dir}/libsqlite3.a")) + .define("SQLite3_INCLUDE_DIR", print_path(&sqlite3_include_dir)) + .define("SQLite3_LIBRARY", print_path(&sqlite3_lib)) .define("OGR_ENABLE_DRIVER_SQLITE", "ON"); } else { config.define("GDAL_USE_SQLITE3", "OFF"); @@ -217,8 +226,17 @@ fn main() { println!("cargo:rustc-link-lib=static={hdf5_lib}"); config .define("GDAL_USE_HDF5", "ON") - .define("HDF5_C_COMPILER_EXECUTABLE", format!("{hdf5_dir}/bin/h5cc")) - .define("HDF5_C_INCLUDE_DIR", format!("{hdf5_dir}/include")) + .define( + "HDF5_C_COMPILER_EXECUTABLE", + format!( + "{hdf5_dir}{sep}bin{sep}h5cc", + sep = std::path::MAIN_SEPARATOR + ), + ) + .define( + "HDF5_C_INCLUDE_DIR", + format!("{hdf5_dir}{}include", std::path::MAIN_SEPARATOR), + ) .define("HDF5_hdf5_LIBRARY_DEBUG", &hdf5_lib_dir) .define("HDF5_hdf5_LIBRARY_RELEASE", &hdf5_lib_dir) .define("GDAL_ENABLE_DRIVER_HDF5", "ON") @@ -251,7 +269,10 @@ fn main() { println!("cargo:rustc-link-lib=static={hl_library}"); config .define("GDAL_USE_NETCDF", "ON") - .define("NETCDF_INCLUDE_DIR", format!("{netcdf_root_dir}/include")) + .define( + "NETCDF_INCLUDE_DIR", + format!("{netcdf_root_dir}{}include", std::path::MAIN_SEPARATOR), + ) .define("NETCDF_LIBRARY", netcdf_lib) .define("GDAL_ENABLE_DRIVER_NETCDF", "ON"); } else { @@ -262,11 +283,23 @@ fn main() { let curl_root = std::env::var("DEP_CURL_ROOT").expect("set from curl-sys"); config .define("GDAL_USE_CURL", "ON") - .define("CURL_INCLUDE_DIR", format!("{curl_root}/include")) - .define("CURL_LIBRARY_DEBUG", format!("{curl_root}/build/libcurl.a")) + .define( + "CURL_INCLUDE_DIR", + format!("{curl_root}{}include", std::path::MAIN_SEPARATOR), + ) + .define( + "CURL_LIBRARY_DEBUG", + format!( + "{curl_root}{sep}build{sep}libcurl.a", + sep = std::path::MAIN_SEPARATOR + ), + ) .define( "CURL_LIBRARY_RELEASE", - format!("{curl_root}/build/libcurl.a"), + format!( + "{curl_root}{sep}build{sep}libcurl.a", + sep = std::path::MAIN_SEPARATOR + ), ) .define("CURL_USE_STATIC_LIBS", "ON"); } else { @@ -318,7 +351,10 @@ fn main() { if cfg!(feature = "geos_static") { let geos_root = std::env::var("DEP_GEOSSRC_ROOT").expect("this is set by geos-src"); - config.define("GEOS_INCLUDE_DIR", format!("{geos_root}/include")); + config.define( + "GEOS_INCLUDE_DIR", + format!("{geos_root}{}include", std::path::MAIN_SEPARATOR), + ); let lib_path = find_library("geos", geos_root); config.define("GEOS_LIBRARY", lib_path); } @@ -348,7 +384,7 @@ fn main() { "cargo:rustc-link-search=native={}", lib_dir.to_str().unwrap() ); - let lib_dir = res.join("build/lib"); + let lib_dir = res.join("build").join("lib"); println!( "cargo:rustc-link-search=native={}", lib_dir.to_str().unwrap() @@ -361,3 +397,7 @@ fn main() { println!("cargo:rustc-link-lib=static=gdal"); } } + +fn print_path(path: &std::path::Path) -> String { + path.components().collect::>().join("/"); +}