forked from Xudong-Huang/pcap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
65 lines (54 loc) · 2.03 KB
/
Copy pathbuild.rs
File metadata and controls
65 lines (54 loc) · 2.03 KB
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
use std::path::Path;
use std::process::{self, Command};
fn main() {
println!("debug:Running the build for libpcap");
// we rerun the build if the `build.rs` file is changed.
println!("cargo:rerun-if-changed=build.rs");
// make sure that the Git submodule is checked out
if !Path::new("libpcap/.git").exists() {
let _ = Command::new("git")
.args(&["submodule", "update", "--init"])
.status();
}
// use and configure cmake to build the Paho C lib
let mut cmk_cfg = cmake::Config::new("libpcap/");
cmk_cfg
.define("BUILD_SHARED_LIBS", "off")
.define("DISABLE_USB", "on")
.define("DISABLE_BLUETOOTH", "on")
.define("DISABLE_NETMAP", "on")
.define("DISABLE_DBUS", "on")
.define("DISABLE_RDMA", "on")
.define("DISABLE_DAG", "on")
.define("DISABLE_SEPTEL", "on")
.define("DISABLE_SNF", "on")
.define("DISABLE_TC", "on");
// 'cmk' is a PathBuf to the cmake install directory
let cmk = cmk_cfg.build();
println!("debug:CMake output dir: {}", cmk.display());
// We check if the pcap library was compiled.
let lib_path = if cmk.join("lib").exists() {
"lib"
} else if cmk.join("lib64").exists() {
"lib64"
} else {
panic!("Unknown library directory.")
};
// Absolute path to pcap lib
let lib_dir = cmk.join(lib_path);
let lib_name = "pcap";
let pcap_link_name = if cfg!(windows) {
format!("{}.lib", lib_name)
} else {
format!("lib{}.a", lib_name)
};
let pcap_lib_path = lib_dir.join(pcap_link_name);
println!("debug:Using pcap library at: {}", pcap_lib_path.display());
if !pcap_lib_path.exists() {
println!("Error building pcap library: '{}'", pcap_lib_path.display());
process::exit(103);
}
// we add the folder where all the libraries are built to the path search
println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rustc-link-lib=static={}", lib_name);
}