Skip to content

Instantly share code, notes, and snippets.

@Dushistov
Created January 19, 2018 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dushistov/b924c8c31a956ad4da74d7765009ed35 to your computer and use it in GitHub Desktop.
Save Dushistov/b924c8c31a956ad4da74d7765009ed35 to your computer and use it in GitHub Desktop.
libspatialite rust wrapper
extern crate bindgen_make;
extern crate cmake;
use std::path::Path;
use std::env;
fn main() {
let dst = cmake::Config::new(Path::new("3rdparty")).build();
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=geos_c");
println!("cargo:rustc-link-lib=static=spatialite");
let target = env::var("TARGET").expect("target env var not setted");
//geos requires std::
if target.contains("linux-gnu") {
println!("cargo:rustc-link-lib=stdc++");
println!("cargo:rustc-link-lib=z");
}
println!(
"rustc-env=SQLITE3_INCLUDE_DIR={}",
Path::new("3rdparty")
.join("sqlite-amalgamation-3210000")
.display()
);
println!("rustc-env=SQLITE3_LIB_DIR={}", dst.display());
let out_dir = env::var("OUT_DIR").unwrap();
bindgen_make::gen_binding(
&target,
&[
Path::new("3rdparty").join("sqlite-amalgamation-3210000"),
Path::new("3rdparty")
.join("libspatialite")
.join("src")
.join("headers"),
],
&["spatialite.h", "sqlite3.h"],
&Path::new(&out_dir).join("spatialite_header.rs"),
).expect("generate binding for c failed");
}
cmake_minimum_required(VERSION 3.9)
add_definitions(
-DUSE_UNSTABLE_GEOS_CPP_API)
#enable_testing()
add_subdirectory(sqlite-amalgamation-3210000)
add_subdirectory(geos)
set(SQLITE_INCLUDE_DIR sqlite-amalgamation-3210000)
set(SQLITE3_LIBRARY sqlite3)
set(GEOS_C_INCLUDE_DIR ${PROJECT_BINARY_DIR}/geos/capi)
set(GEOS_C_LIBRARY geos_c)
add_subdirectory(libspatialite)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment