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

Add build.rs to gdal-sys #33

Merged
merged 3 commits into from
Feb 26, 2017
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ documentation = "https://georust.github.io/rust-gdal/"

[dependencies]
error-chain = "0.7.2"
libc = "0.2.18"
libc = "0.2.20"
geo = "0.0.5"
gdal-sys = { path = "gdal-sys", version = "0.1.0"}

Expand Down
4 changes: 3 additions & 1 deletion gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
name = "gdal-sys"
version = "0.1.0"
authors = ["Johannes Drönner <[email protected]>"]
build="build.rs"


[dependencies]
libc = "0.2.13"
libc = "0.2.20"
51 changes: 51 additions & 0 deletions gdal-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@


fn main() {

let link_type = "dylib";
let lib_name = "gdal";

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

// 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.");
}
}
}
}

#[cfg(unix)]
{
println!("cargo:rustc-link-lib={}={}", link_type, lib_name);
}
}
2 changes: 1 addition & 1 deletion gdal-sys/src/cpl_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use libc::{c_int, c_char};

#[derive(Clone, Copy, Debug, PartialEq)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum CPLErr {
CE_None = 0,
Expand All @@ -11,7 +12,6 @@ pub enum CPLErr {
CE_Fatal = 4
}

#[link(name="gdal")]
extern {
/// Erase any traces of previous errors.
pub fn CPLErrorReset();
Expand Down
2 changes: 1 addition & 1 deletion gdal-sys/src/gdal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use libc::{c_int, c_char, c_double, c_void};
use gdal_enums::*;
use cpl_error::{CPLErr};

#[link(name="gdal")]
extern {
// driver
pub fn GDALAllRegister();
Expand Down Expand Up @@ -73,6 +72,7 @@ extern {
pub fn GDALGetDescription(hGdalMayorObject: *const c_void) -> *const c_char;
pub fn GDALGetMetadataItem(hGdalMayorObject: *const c_void, pszName: *const c_char, pszDomain: *const c_char) -> *const c_char;
pub fn GDALSetMetadataItem(hGdalMayorObject: *const c_void, pszName: *const c_char, pszValue: *const c_char, pszDomain: *const c_char ) -> CPLErr;
pub fn GDALVersionInfo(key: *const c_char) -> *const c_char;
}

pub static REPROJECT_MEMORY_LIMIT: c_double = 0.0;
4 changes: 4 additions & 0 deletions gdal-sys/src/gdal_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use libc::{c_int};

#[derive(Clone, Copy, Debug, PartialEq)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum GDALDataType {
GDT_Unknown = 0, // Unknown or unspecified type
Expand Down Expand Up @@ -38,6 +39,7 @@ impl GDALDataType {

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum GDALRWFlag {
GF_Read, //Read data
Expand All @@ -46,6 +48,7 @@ pub enum GDALRWFlag {

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum GDALAccess {
GA_ReadOnly, //Read only (no update) access
Expand All @@ -54,6 +57,7 @@ pub enum GDALAccess {

#[derive(Clone, Copy, Debug)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum GDALResampleAlg {
GRA_NearestNeighbour, //Nearest neighbour (select on one input pixel)
Expand Down
2 changes: 1 addition & 1 deletion gdal-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ pub mod ogr_enums;
pub mod osr;

// cpl modules
pub mod cpl_error;
pub mod cpl_error;
1 change: 0 additions & 1 deletion gdal-sys/src/ogr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use libc::{c_int, c_char, c_double, c_void};
use ogr_enums::*;

#[link(name="gdal")]
extern {
pub fn OGRRegisterAll();
pub fn OGRGetDriverByName(pszName: *const c_char) -> *const c_void;
Expand Down
2 changes: 2 additions & 0 deletions gdal-sys/src/ogr_enums.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[derive(Clone, Copy, Debug, PartialEq)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum OGRErr {
OGRERR_NONE = 0,
Expand All @@ -16,6 +17,7 @@ pub enum OGRErr {

#[derive(Clone, Copy, Debug, PartialEq)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub enum OGRFieldType {
OFTInteger = 0,
Expand Down
1 change: 0 additions & 1 deletion gdal-sys/src/osr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use libc::{c_int, c_char, c_double, c_void};
use ogr_enums::*;

#[link(name="gdal")]
extern {
pub fn OSRNewSpatialReference(pszWKT: *const c_char) -> *mut c_void;
pub fn OSRClone(hSRS: *const c_void) -> *mut c_void;
Expand Down
7 changes: 1 addition & 6 deletions src/version.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use libc::c_char;
use std::ffi::CString;
use utils::_string;

#[link(name="gdal")]
extern {
fn GDALVersionInfo(key: *const c_char) -> *const c_char;
}
use gdal_sys::gdal::GDALVersionInfo;

pub fn version_info(key: &str) -> String {
let c_key = CString::new(key.as_bytes()).unwrap();
Expand Down