Skip to content
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

fix: the cmake run command #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
44 changes: 24 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ pub struct Config {
static_crt: Option<bool>,
uses_cxx11: bool,
always_configure: bool,
no_build_target: bool,
verbose_cmake: bool,
verbose_make: bool,
pic: Option<bool>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
Loading