Skip to content

Commit 2750291

Browse files
authored
Merge pull request #47 from gferon/master
Skip CMake configure step when CMakeCache.txt is present in build folder
2 parents cf623eb + 701fd80 commit 2750291

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub struct Config {
7171
env: Vec<(OsString, OsString)>,
7272
static_crt: Option<bool>,
7373
uses_cxx11: bool,
74+
always_configure: bool,
7475
}
7576

7677
/// Builds the native library rooted at `path` with the default cmake options.
@@ -112,7 +113,8 @@ impl Config {
112113
cmake_target: None,
113114
env: Vec::new(),
114115
static_crt: None,
115-
uses_cxx11: false
116+
uses_cxx11: false,
117+
always_configure: true,
116118
}
117119
}
118120

@@ -234,6 +236,15 @@ impl Config {
234236
self
235237
}
236238

239+
/// Forces CMake to always run before building the custom target.
240+
///
241+
/// In some cases, when you have a big project, you can disable
242+
/// subsequents runs of cmake to make `cargo build` faster.
243+
pub fn always_configure(&mut self, always_configure: bool) -> &mut Config {
244+
self.always_configure = always_configure;
245+
self
246+
}
247+
237248
/// Run this configuration, compiling the library with all the configured
238249
/// options.
239250
///
@@ -496,7 +507,10 @@ impl Config {
496507
cmd.env(k, v);
497508
}
498509

499-
run(cmd.env("CMAKE_PREFIX_PATH", cmake_prefix_path), "cmake");
510+
if self.always_configure || !build.join("CMakeCache.txt").exists() {
511+
println!("CMake project was already configured. Skipping configuration step.");
512+
run(cmd.env("CMAKE_PREFIX_PATH", cmake_prefix_path), "cmake");
513+
}
500514

501515
let mut makeflags = None;
502516
let mut parallel_args = Vec::new();

0 commit comments

Comments
 (0)