Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on Windows with Conan #348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[requires]
gdal/3.5.2

[generators]
pkg_config
64 changes: 3 additions & 61 deletions gdal-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use semver::Version;

use pkg_config::Config;
use std::env;
use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

#[cfg(feature = "bindgen")]
pub fn write_bindings(include_paths: Vec<String>, out_path: &Path) {
Expand Down Expand Up @@ -45,18 +43,6 @@ fn env_dir(var: &str) -> Option<PathBuf> {
dir
}

fn find_gdal_dll(lib_dir: &Path) -> io::Result<Option<String>> {
for e in fs::read_dir(lib_dir)? {
let e = e?;
let name = e.file_name();
let name = name.to_str().unwrap();
if name.starts_with("gdal") && name.ends_with(".dll") {
return Ok(Some(String::from(name)));
}
}
Ok(None)
}

fn add_docs_rs_helper(version: Option<&str>) {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("docs_rs_helper.rs");
let docs_helper_code = if let Some(version) = version {
Expand Down Expand Up @@ -119,9 +105,9 @@ fn main() {
println!("cargo:rerun-if-env-changed=GDAL_VERSION");

let mut need_metadata = true;
let mut lib_name = String::from("gdal");
let lib_name = String::from("gdal");

let mut prefer_static =
let prefer_static =
env::var_os("GDAL_STATIC").is_some() && env::var_os("GDAL_DYNAMIC").is_none();

let mut include_dir = env_dir("GDAL_INCLUDE_DIR");
Expand All @@ -131,50 +117,6 @@ fn main() {
.map(|vs| vs.to_string_lossy().to_string())
.and_then(|vs| Version::parse(vs.trim()).ok());

let mut found = false;
if cfg!(windows) {
// first, look for a static library in $GDAL_LIB_DIR or $GDAL_HOME/lib
// works in windows-msvc and windows-gnu
if let Some(ref lib_dir) = lib_dir {
let lib_path = lib_dir.join("gdal_i.lib");
if lib_path.exists() {
prefer_static = true;
lib_name = String::from("gdal_i");
found = true;
}
}
if !found {
if let Some(ref home_dir) = home_dir {
let home_lib_dir = home_dir.join("lib");
let lib_path = home_lib_dir.join("gdal_i.lib");
if lib_path.exists() {
prefer_static = true;
lib_name = String::from("gdal_i");
lib_dir = Some(home_lib_dir);
found = true;
}
}
}
if !found {
if cfg!(target_env = "msvc") {
panic!("windows-msvc requires gdal_i.lib to be present in either $GDAL_LIB_DIR or $GDAL_HOME\\lib.");
}

// otherwise, look for a gdalxxx.dll in $GDAL_HOME/bin
// works in windows-gnu
if let Some(ref home_dir) = home_dir {
let bin_dir = home_dir.join("bin");
if bin_dir.exists() {
if let Some(name) = find_gdal_dll(&bin_dir).unwrap() {
prefer_static = false;
lib_dir = Some(bin_dir);
lib_name = name;
}
}
}
}
}

if let Some(ref home_dir) = home_dir {
if include_dir.is_none() {
let dir = home_dir.join("include");
Expand Down