|
1 |
| -extern crate make_cmd; |
| 1 | +extern crate cmake; |
2 | 2 |
|
3 | 3 | use std::env;
|
4 |
| -use std::path::{Path, PathBuf}; |
| 4 | +use std::path::Path; |
5 | 5 | use std::process::Command;
|
6 |
| -use std::fs::{self, File}; |
7 |
| -use std::io::Write; |
| 6 | +use cmake::Config; |
8 | 7 |
|
9 | 8 | fn main() {
|
10 | 9 | println!("cargo:rerun-if-changed=libui");
|
11 |
| - if !Path::new("libui/.git").exists() { |
12 |
| - Command::new("git").args(&["submodule", "update", "--init"]).status().expect("Could not update libui submodule"); |
13 |
| - } |
14 |
| - |
15 |
| - let cwd = env::current_dir().unwrap(); |
16 |
| - |
17 |
| - let libui_path = cwd.join("libui"); |
18 |
| - env::set_current_dir(&libui_path).expect("Could not change dir"); |
19 |
| - |
20 |
| - // Run CMake |
21 |
| - //let cmake_cache_path = (&libui_path).join("CMakeCache.txt"); |
22 |
| - //if cmake_cache_path.exists() { |
23 |
| - // fs::remove_file(cmake_cache_path).expect("Could not remove cmake cache"); |
24 |
| - //} |
25 |
| - Command::new("cmake").arg(".").output().expect("cmake failed"); |
26 |
| - |
27 |
| - // Run Make |
28 |
| - let libui_out_path = (&libui_path).join("out"); |
29 |
| - if ! libui_out_path.exists() { |
30 |
| - println!("Creating out dir"); |
31 |
| - fs::create_dir(&libui_out_path).expect("Could not create out dir"); |
32 |
| - } |
33 |
| - make_cmd::gnu_make().status().expect("Make failed"); |
34 |
| - |
35 |
| - // Copy the output to the build folder |
36 |
| - let out_dir = env::var("OUT_DIR").unwrap(); |
37 |
| - let out_path = Path::new(&out_dir); |
38 |
| - for entry in fs::read_dir(&libui_out_path).unwrap() { |
39 |
| - let entry = entry.expect("IO error while reading"); |
40 |
| - let name = entry.file_name(); |
41 |
| - let target = out_path.join(name); |
42 |
| - fs::copy(&entry.path(), &target).expect("Could not copy file"); |
43 |
| - println!("Copying file from {} to {}", entry.path().display(), target.display()); |
| 10 | + init_git_submodule(); |
| 11 | + |
| 12 | + let mut cfg = Config::new("libui"); |
| 13 | + if static_library() { |
| 14 | + cfg.define("BUILD_SHARED_LIBS", "OFF"); |
44 | 15 | }
|
45 |
| - |
| 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"); |
46 | 25 |
|
47 |
| - // Configure cargo |
48 |
| - println!("cargo:rustc-link-lib=dylib=ui"); |
49 |
| - println!("cargo:rustc-link-search={}", out_dir); |
50 |
| - //panic!(); |
| 26 | + println!("cargo:rustc-link-search=native={}", dst.display()); |
| 27 | + println!("cargo:rustc-link-lib=ui"); |
51 | 28 | }
|
52 | 29 |
|
| 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 | +} |
| 36 | + |
| 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"); |
| 43 | + } |
| 44 | +} |
0 commit comments