Skip to content

Commit

Permalink
Bring back the Windows linking code
Browse files Browse the repository at this point in the history
  • Loading branch information
lnicola committed Feb 17, 2018
1 parent 809a5b8 commit 76000c6
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions gdal-sys/build.rs
Expand Up @@ -7,12 +7,50 @@ use std::env;
use std::path::PathBuf;

fn main() {
#[cfg(windows)]
{
use std::path::Path;

// get the path to GDAL_HOME
let home_path = env::var("GDAL_HOME").expect("Environment variable $GDAL_HOME not found!");

// detect the path to gdal_i.lib (works for MSVC and GNU)
let lib_suffix = "_i";
let lib_search_path = Path::new(&home_path).join("lib");
let lib_path = lib_search_path.join(&format!("{}{}.lib", lib_name, lib_suffix));

if lib_search_path.exists() && lib_path.exists() {
println!("cargo:rustc-link-search={}", lib_search_path.to_string_lossy());
println!("cargo:rustc-link-lib={}={}", link_type, format!("{}{}",lib_name, lib_suffix));
} else {
#[cfg(target_env="msvc")]
{
panic!("windows-msvc requires gdal_i.lib to be found in $GDAL_HOME\\lib.");
}

#[cfg(target_env="gnu")]
{
// detect if a gdal{version}.dll is available
let versions = [201, 200, 111, 110];
let bin_path = Path::new(&home_path).join("bin");
if let Some(version) = versions.iter().find(|v| bin_path.join(&format!("{}{}.dll", lib_name, v)).exists()){
println!("cargo:rustc-link-search={}", bin_path.to_string_lossy());
println!("cargo:rustc-link-lib={}={}", link_type, format!("{}{}",lib_name, version));
}
else {
panic!("windows-gnu requires either gdal_i.lib in $GDAL_HOME\\lib OR gdal{version}.dll in $GDAL_HOME\\bin.");
}
}
}
}

let mut builder = Builder::default();

let gdal = Config::new().probe("gdal").unwrap();
for path in &gdal.include_paths {
builder = builder.clang_arg("-I");
builder = builder.clang_arg(path.to_str().unwrap());
if let Ok(gdal) = Config::new().probe("gdal") {
for path in &gdal.include_paths {
builder = builder.clang_arg("-I");
builder = builder.clang_arg(path.to_str().unwrap());
}
}

let bindings = builder
Expand Down

0 comments on commit 76000c6

Please sign in to comment.