|
| 1 | +#[cfg(feature = "buildtime_bindgen")] |
| 2 | +extern crate bindgen; |
1 | 3 | extern crate cmake;
|
2 | 4 |
|
3 |
| -fn main() { |
4 |
| - let mut cfg = cmake::Config::new("openvr"); |
5 |
| - |
6 |
| - // Work around broken cmake build |
7 |
| - #[cfg(windows)] |
8 |
| - cfg.cxxflag("/DWIN32"); |
| 5 | +use std::env; |
9 | 6 |
|
10 |
| - #[cfg(target_os="macos")] |
11 |
| - cfg.define("BUILD_UNIVERSAL", "OFF"); |
12 |
| - |
13 |
| - let dst = cfg.build(); |
| 7 | +fn main() { |
| 8 | + let mut config = cmake::Config::new("openvr"); |
| 9 | + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); |
| 10 | + let target_pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap(); |
| 11 | + |
| 12 | + if target_os == "macos" { |
| 13 | + config.define("BUILD_UNIVERSAL", "OFF"); |
| 14 | + } else if target_os == "windows" { |
| 15 | + // Work around broken cmake build. |
| 16 | + config.cxxflag("/DWIN32"); |
| 17 | + } |
| 18 | + |
| 19 | + let dst = config.build(); |
14 | 20 | println!("cargo:rustc-link-search=native={}/lib", dst.display());
|
15 | 21 |
|
16 |
| - #[cfg(all(windows, target_pointer_width = "64"))] |
17 |
| - println!("cargo:rustc-link-lib=static=openvr_api64"); |
18 |
| - |
19 |
| - #[cfg(not(all(windows, target_pointer_width = "64")))] |
20 |
| - println!("cargo:rustc-link-lib=static=openvr_api"); |
21 |
| - |
22 |
| - #[cfg(target_os="linux")] |
23 |
| - println!("cargo:rustc-link-lib=stdc++"); |
24 |
| - |
25 |
| - #[cfg(target_os="macos")] |
26 |
| - println!("cargo:rustc-link-lib=c++"); |
| 22 | + if target_os == "windows" && target_pointer_width == "64" { |
| 23 | + println!("cargo:rustc-link-lib=static=openvr_api64"); |
| 24 | + } else { |
| 25 | + println!("cargo:rustc-link-lib=static=openvr_api"); |
| 26 | + } |
| 27 | + |
| 28 | + if target_os == "linux" { |
| 29 | + println!("cargo:rustc-link-lib=stdc++"); |
| 30 | + } else if target_os == "macos" { |
| 31 | + println!("cargo:rustc-link-lib=c++"); |
| 32 | + } else if target_os == "windows" { |
| 33 | + println!("cargo:rustc-link-lib=shell32"); |
| 34 | + } |
| 35 | + |
| 36 | + // Generate bindings at build time. |
| 37 | + #[cfg(feature = "buildtime_bindgen")] |
| 38 | + bindgen::builder() |
| 39 | + .header("wrapper.hpp") |
| 40 | + .constified_enum(".*") |
| 41 | + .prepend_enum_name(false) |
| 42 | + .generate() |
| 43 | + .expect("could not generate bindings") |
| 44 | + .write_to_file("bindings.rs") |
| 45 | + .expect("could not write bindings.rs"); |
27 | 46 | }
|
0 commit comments