|
1 | 1 | extern crate cmake;
|
| 2 | +use cmake::Config; |
2 | 3 |
|
3 | 4 | use std::env;
|
4 | 5 | use std::path::Path;
|
5 | 6 | use std::process::Command;
|
6 |
| -use cmake::Config; |
7 | 7 |
|
8 | 8 | fn main() {
|
9 |
| - println!("cargo:rerun-if-changed=libui"); |
10 |
| - init_git_submodule(); |
11 |
| - |
12 |
| - let mut cfg = Config::new("libui"); |
13 |
| - if static_library() { |
14 |
| - cfg.define("BUILD_SHARED_LIBS", "OFF"); |
| 9 | + if !Path::new("libui/.git").exists() { |
| 10 | + Command::new("git").args(&["submodule", "update", "--init"]).status().unwrap(); |
15 | 11 | }
|
16 |
| - let mut dst = cfg.build_target("all").build(); |
17 |
| - |
18 |
| - dst.push("build"); |
19 |
| - dst.push("out"); |
20 |
| - |
21 |
| - // Without explicit notion of Appkit, |
22 |
| - // compilation of static binary fails |
23 |
| - #[cfg(target_os="macos")] |
24 |
| - println!("cargo:rustc-link-lib=framework=Appkit"); |
25 | 12 |
|
26 |
| - println!("cargo:rustc-link-search=native={}", dst.display()); |
27 |
| - println!("cargo:rustc-link-lib=ui"); |
28 |
| -} |
| 13 | + let target = env::var("TARGET").unwrap(); |
| 14 | + let msvc = target.contains("msvc"); |
29 | 15 |
|
30 |
| -fn static_library() -> bool { |
31 |
| - // env::var_os("STATIC") |
32 |
| - // .map(|v| v.to_str() == Some("1")) |
33 |
| - // .unwrap_or(false) |
34 |
| - true |
35 |
| -} |
| 16 | + let dst = Config::new("libui") |
| 17 | + .build_target("") |
| 18 | + .build(); |
36 | 19 |
|
37 |
| -fn init_git_submodule() { |
38 |
| - if !Path::new("libui/.git").exists() { |
39 |
| - let cwd = env::current_dir().unwrap(); |
40 |
| - env::set_current_dir(&cwd.parent().unwrap()).expect("Could not change dir"); |
41 |
| - Command::new("git").args(&["submodule", "update", "--init"]).status().expect("Could not update libui submodule"); |
42 |
| - env::set_current_dir(&cwd).expect("Could not change dir"); |
| 20 | + let mut postfix = Path::new("build").join("out"); |
| 21 | + let libname; |
| 22 | + if msvc { |
| 23 | + postfix = postfix.join("Release"); |
| 24 | + libname = "libui"; |
| 25 | + } else { |
| 26 | + libname = "ui"; |
43 | 27 | }
|
| 28 | + let dst = dst.join(&postfix); |
| 29 | + |
| 30 | + println!("cargo:rustc-link-lib={}", libname); |
| 31 | + println!("cargo:rustc-link-search=native={}", dst.display()); |
44 | 32 | }
|
0 commit comments