Skip to content

Commit 3eaa0b4

Browse files
committed
Merge pull request #8 from caipre/master
Add function to specify build-tool generator
2 parents dbbf9d4 + e5f7711 commit 3eaa0b4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use std::process::Command;
5757
/// Builder style configuration for a pending CMake build.
5858
pub struct Config {
5959
path: PathBuf,
60+
generator: Option<OsString>,
6061
cflags: OsString,
6162
defines: Vec<(OsString, OsString)>,
6263
deps: Vec<String>,
@@ -94,6 +95,7 @@ impl Config {
9495
pub fn new<P: AsRef<Path>>(path: P) -> Config {
9596
Config {
9697
path: env::current_dir().unwrap().join(path),
98+
generator: None,
9799
cflags: OsString::new(),
98100
defines: Vec::new(),
99101
deps: Vec::new(),
@@ -106,6 +108,12 @@ impl Config {
106108
}
107109
}
108110

111+
/// Sets the build-tool generator (`-G`) for this compilation.
112+
pub fn generator<T: AsRef<OsStr>>(&mut self, generator: T) -> &mut Config {
113+
self.generator = Some(generator.as_ref().to_owned());
114+
self
115+
}
116+
109117
/// Adds a custom flag to pass down to the compiler, supplementing those
110118
/// that this library already passes.
111119
pub fn cflag<P: AsRef<OsStr>>(&mut self, flag: P) -> &mut Config {
@@ -237,7 +245,9 @@ impl Config {
237245
// On MinGW we need to coerce cmake to not generate a visual
238246
// studio build system but instead use makefiles that MinGW can
239247
// use to build.
240-
cmd.arg("-G").arg("MSYS Makefiles");
248+
if self.generator.is_none() {
249+
cmd.arg("-G").arg("MSYS Makefiles");
250+
}
241251
} else {
242252
// If we're cross compiling onto windows, then set some
243253
// variables which will hopefully get things to succeed. Some
@@ -262,7 +272,12 @@ impl Config {
262272
} else if msvc {
263273
// If we're on MSVC we need to be sure to use the right generator or
264274
// otherwise we won't get 32/64 bit correct automatically.
265-
cmd.arg("-G").arg(self.visual_studio_generator(&target));
275+
if self.generator.is_none() {
276+
cmd.arg("-G").arg(self.visual_studio_generator(&target));
277+
}
278+
}
279+
if let Some(ref generator) = self.generator {
280+
cmd.arg("-G").arg(generator);
266281
}
267282
let profile = self.profile.clone().unwrap_or_else(|| {
268283
match &getenv_unwrap("PROFILE")[..] {

0 commit comments

Comments
 (0)