Skip to content

Add function to specify build-tool generator #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use std::process::Command;
/// Builder style configuration for a pending CMake build.
pub struct Config {
path: PathBuf,
generator: Option<OsString>,
cflags: OsString,
defines: Vec<(OsString, OsString)>,
deps: Vec<String>,
Expand Down Expand Up @@ -94,6 +95,7 @@ impl Config {
pub fn new<P: AsRef<Path>>(path: P) -> Config {
Config {
path: env::current_dir().unwrap().join(path),
generator: None,
cflags: OsString::new(),
defines: Vec::new(),
deps: Vec::new(),
Expand All @@ -106,6 +108,12 @@ impl Config {
}
}

/// Sets the build-tool generator (`-G`) for this compilation.
pub fn generator<T: AsRef<OsStr>>(&mut self, generator: T) -> &mut Config {
self.generator = Some(generator.as_ref().to_owned());
self
}

/// Adds a custom flag to pass down to the compiler, supplementing those
/// that this library already passes.
pub fn cflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config {
Expand Down Expand Up @@ -237,7 +245,9 @@ impl Config {
// 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 self.generator.is_none() {
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
Expand All @@ -262,7 +272,12 @@ impl Config {
} 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.
cmd.arg("-G").arg(self.visual_studio_generator(&target));
if self.generator.is_none() {
cmd.arg("-G").arg(self.visual_studio_generator(&target));
}
}
if let Some(ref generator) = self.generator {
cmd.arg("-G").arg(generator);
}
let profile = self.profile.clone().unwrap_or_else(|| {
match &getenv_unwrap("PROFILE")[..] {
Expand Down