Skip to content

Commit

Permalink
Assist in cross-compiling to Windows from Unix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Feb 14, 2016
1 parent 6ee3b62 commit a9f74a4
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,32 @@ impl Config {
cmd.arg(&self.path)
.current_dir(&build);
if target.contains("windows-gnu") {
// On MinGW we need to coerce cmake to not generate a visual studio
// build system but instead use makefiles that MinGW can use to
// build.
cmd.arg("-G").arg("MSYS Makefiles");
if host.contains("windows") {
// On MinGW we need to coerce cmake to not generate a visual
// studio build system but instead use makefiles that MinGW can
// use to build.
cmd.arg("-G").arg("MSYS Makefiles");
} else {
// If we're cross compiling onto windows, then set some
// variables which will hopefully get things to succeed. Some
// systems may need the `windres` or `dlltool` variables set, so
// set them if possible.
if !self.defined("CMAKE_SYSTEM_NAME") {
cmd.arg("-DCMAKE_SYSTEM_NAME=Windows");
}
if !self.defined("CMAKE_RC_COMPILER") {
let exe = find_exe(c_compiler.path());
if let Some(name) = exe.file_name().unwrap().to_str() {
let name = name.replace("gcc", "windres");
let windres = exe.with_file_name(name);
if windres.is_file() {
let mut arg = OsString::from("-DCMAKE_RC_COMPILER=");
arg.push(&windres);
cmd.arg(arg);
}
}
}
}
} else if msvc {
// If we're on MSVC we need to be sure to use the right generator or
// otherwise we won't get 32/64 bit correct automatically.
Expand Down

0 comments on commit a9f74a4

Please sign in to comment.