1use std::env;
2
3#[cfg(all(not(feature = "vendored"), not(windows)))]
4use std::process::Command;
5
6#[cfg(feature = "vendored")]
7fn dep_links() -> String {
8 let target = env::var("TARGET").unwrap().replace('-', "_").to_uppercase();
9 if target.contains("APPLE") {
10 "UNIVERSAL_APPLE_DARWIN".to_owned()
11 } else {
12 target
13 }
14}
15
16#[cfg(feature = "vendored")]
17pub fn wx_config(args: &[&str]) -> Vec<String> {
18 let flags: Vec<_> = env::var(format!("DEP_WX_{}_CFLAGS", dep_links()))
19 .unwrap()
20 .split_whitespace()
21 .map(ToOwned::to_owned)
22 .collect();
23 let (ldflags, cflags): (Vec<_>, Vec<_>) = flags
24 .into_iter()
25 .partition(|f| f.starts_with("-l") || f.starts_with("-L"));
26 return if args.contains(&"--cflags") {
27 cflags
28 } else {
29 ldflags
30 };
31}
32
33#[cfg(all(not(feature = "vendored"), not(windows)))]
34pub fn wx_config(args: &[&str]) -> Vec<String> {
35 let output = Command::new("wx-config")
36 .args(args)
37 .output()
38 .expect("failed execute wx-config command.");
39 let flags: Vec<String> = String::from_utf8_lossy(&output.stdout)
40 .to_string()
41 .split_whitespace()
42 .map(ToOwned::to_owned)
43 .collect();
44 let mut converted = Vec::new();
45 let mut next_is_framework_name = false;
46 for flag in flags.iter() {
47 if next_is_framework_name {
48 converted.push(format!("-lframework={}", flag));
49 next_is_framework_name = false;
50 } else if flag == "-framework" {
51 next_is_framework_name = true;
52 } else if flag.starts_with("-pthread") {
53 } else {
55 converted.push(flag.to_string());
56 }
57 }
58 converted
59}
60
61#[cfg(all(not(feature = "vendored"), windows))]
62pub fn wx_config(args: &[&str]) -> Vec<String> {
63 let wxwin = env::var("wxwin")
64 .expect("Set 'wxwin' environment variable to point the wxMSW binaries dir.");
65 let is_debug = false; let d_or_not = if is_debug { "d" } else { "" };
68 if args.contains(&"--cflags") {
69 let mut cflags = vec![
70 format!("-I{}\\include", wxwin),
71 format!("-I{}\\lib\\vc14x_x64_dll\\mswu{}", wxwin, d_or_not),
72 "-DWXUSINGDLL".to_string(),
73 ];
74 if is_debug {
75 cflags.push("-D_DEBUG".to_string());
76 } else {
77 cflags.push("-D__NO_VC_CRTDBG__".to_string());
78 cflags.push("-DwxDEBUG_LEVEL=0".to_string());
79 cflags.push("-DNDEBUG".to_string());
80 }
81 let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
82 if target_env.eq("msvc") {
83 cflags.push("/EHsc".to_string());
84 }
85 cflags
86 } else {
87 let libs = vec![
88 format!("-L{}\\lib\\vc14x_x64_dll", wxwin),
89 format!("-lwxbase32u{}", d_or_not),
90 format!("-lwxmsw32u{}_core", d_or_not),
91 ];
92 libs
93 }
94}