-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
91 lines (78 loc) · 2.9 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// From: https://docs.rs/crate/gdcm_conv/0.1.0/s
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
fn build() {
// run GDCM cmake
let mut cfg = cmake::Config::new("GDCM");
let dst = cfg
.define("GDCM_BUILD_TESTING", "OFF")
.define("GDCM_DOCUMENTATION", "OFF")
.define("GDCM_BUILD_EXAMPLES", "OFF")
.define("GDCM_BUILD_DOCBOOK_MANPAGES", "OFF")
.define("CMAKE_CXX_STANDARD", "14")
.build();
// set GDCM include path
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let include_dir = out_path.join("include").join("gdcm-3.1");
// create library
cc::Build::new()
.file("gdcm_wrapper.cc")
.cpp(true)
.std("c++14")
.include(include_dir)
.compile("gdcm_wrapper");
// set libs paths
println!("cargo:rustc-link-search={}", dst.join("lib").display());
println!("cargo:rustc-link-search={}", dst.display());
// set libs
println!("cargo:rustc-link-lib=static=gdcm_wrapper");
// gdcm libs
println!("cargo:rustc-link-lib=static=gdcmMSFF");
println!("cargo:rustc-link-lib=static=gdcmCommon");
println!("cargo:rustc-link-lib=static=gdcmDICT");
println!("cargo:rustc-link-lib=static=gdcmDSED");
println!("cargo:rustc-link-lib=static=gdcmIOD");
println!("cargo:rustc-link-lib=static=gdcmexpat");
println!("cargo:rustc-link-lib=static=gdcmjpeg12");
println!("cargo:rustc-link-lib=static=gdcmjpeg16");
println!("cargo:rustc-link-lib=static=gdcmjpeg8");
println!("cargo:rustc-link-lib=static=gdcmopenjp2");
if env::consts::OS != "windows" {
println!("cargo:rustc-link-lib=static=gdcmuuid");
}
println!("cargo:rustc-link-lib=static=gdcmMEXD");
println!("cargo:rustc-link-lib=static=gdcmzlib");
#[cfg(feature = "charls")]
println!("cargo:rustc-link-lib=static=gdcmcharls");
println!("Building for {}", env::consts::OS);
match env::consts::OS {
"macos" => {
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-search=framework=/System/Library/Frameworks");
}
"windows" => {
println!("cargo:rustc-link-lib=dylib=rpcrt4");
println!("cargo:rustc-link-lib=dylib=crypt32");
println!("cargo:rustc-link-lib=static=socketxx");
}
_ => {
println!("cargo:rustc-link-lib=dylib=stdc++");
}
};
}
fn main() {
// re-build if files change
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=gdcm_wrapper.cc");
println!("cargo:rerun-if-changed=wrapper.h");
// unset DESTDIR envar to avoid others libs destinations
env::remove_var("DESTDIR");
// update git
if !Path::new("GDCM/.git").exists() {
let _ = Command::new("git")
.args(["submodule", "update", "--init"])
.status();
}
build();
}