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
use std::env;
fn main() {
// TODO: find out if liblsl already present on system and usable (if so, link to that instead)
// println!("cargo:warning={}", "rebuilding...");
build_liblsl();
}
// Build the liblsl library from source using cmake
fn build_liblsl() {
let target = env::var("TARGET").unwrap();
// build with cmake
let mut cfg = cmake::Config::new("liblsl");
cfg
.define("LSL_NO_FANCY_LIBNAME", "ON")
.define("LSL_BUILD_STATIC", "ON");
if target.contains("msvc") {
// override some C/CXX flags that the cmake crate splices in on Windows
// (these cause the build to fail)...
// * /EHsc sets the correct exception handling mode
// * /GR enables RTTI
// * /MD links in the msvcrt as a DLL instead of statically
let cxx_args = " /nologo /EHsc /MD /GR";
cfg
.define("WIN32", "1")
.define("_WINDOWS", "1")
.define("CMAKE_C_FLAGS", cxx_args)
.define("CMAKE_CXX_FLAGS", cxx_args)
.define("CMAKE_C_FLAGS_DEBUG", cxx_args)
.define("CMAKE_CXX_FLAGS_DEBUG", cxx_args)
.define("CMAKE_C_FLAGS_RELEASE", cxx_args)
.define("CMAKE_CXX_FLAGS_RELEASE", cxx_args);
}
let install_dir = cfg.build();
// emit link directives
let libdir = install_dir.join("lib");
let libname = "lsl-static";
println!(
"cargo:rustc-link-search=native={}",
libdir.to_str().unwrap()
);
println!("cargo:rustc-link-lib=static={}", libname);
// make sure we also link some additional libs
if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else if target.contains("windows") {
// TODO: this is a shortcoming in the current cmake file, which should be
// linking in this library (once this is fixed, we should remove this)
println!("cargo:rustc-link-lib=dylib=bcrypt");
} else {
println!("cargo:rustc-link-lib=dylib=c++");
}
}