diff --git a/src/lib.rs b/src/lib.rs index 035cead..725afe7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,6 @@ pub struct Config { static_crt: Option, uses_cxx11: bool, always_configure: bool, - no_build_target: bool, verbose_cmake: bool, verbose_make: bool, pic: Option, @@ -200,7 +199,6 @@ impl Config { static_crt: None, uses_cxx11: false, always_configure: true, - no_build_target: false, verbose_cmake: false, verbose_make: false, pic: None, @@ -289,14 +287,6 @@ impl Config { self } - /// Disables the cmake target option for this compilation. - /// - /// Note that this isn't related to the target triple passed to the compiler! - pub fn no_build_target(&mut self, no_build_target: bool) -> &mut Config { - self.no_build_target = no_build_target; - self - } - /// Sets the host triple for this compilation. /// /// This is automatically scraped from `$HOST` which is set for Cargo @@ -570,7 +560,14 @@ impl Config { cmd.arg("--debug-output"); } - cmd.arg(&self.path).current_dir(&build); + // not use the current dir, should use -B and -S + // In some cases, every time the project build.rs + // is changed, cmake is reloaded without reading + // the CMakeCache.txt + cmd.current_dir(&build); + cmd.arg("-S").arg(&self.path); + cmd.arg("-B").arg(&build); + let mut is_ninja = false; if let Some(ref generator) = generator { is_ninja = generator.to_string_lossy().contains("Ninja"); @@ -697,8 +694,8 @@ impl Config { .defines .iter() .find(|&&(ref a, _)| a == "CMAKE_BUILD_TYPE") - .map(|x| x.1.to_str().unwrap()) - .unwrap_or(&profile); + .map(|x| String::from(x.1.to_str().unwrap())) + .unwrap_or(profile.clone()); let build_type_upcase = build_type .chars() .flat_map(|c| c.to_uppercase()) @@ -847,17 +844,15 @@ impl Config { } } - cmd.arg("--build").arg("."); + // use the absolute path, not use relective path + cmd.arg("--build").arg(&build); - if !self.no_build_target { - let target = self - .cmake_target - .clone() - .unwrap_or_else(|| "install".to_string()); + // some projects may not have install targets + if let Some(target) = self.cmake_target.clone() { cmd.arg("--target").arg(target); } - cmd.arg("--config").arg(&profile); + cmd.arg("--config").arg(&build_type); // --parallel requires CMake 3.12: // https://cmake.org/cmake/help/latest/release/3.12.html#command-line @@ -874,6 +869,15 @@ impl Config { run(&mut cmd, "cmake"); + // run this install command + // projects that do not have an install + // target will work just fine + let mut cmd = self.cmake_build_command(&target); + cmd.arg("--install").arg(&build); + cmd.arg("--config").arg(&build_type); + + run(&mut cmd, "cmake"); + println!("cargo:root={}", dst.display()); dst }