use super::{collect_from_prefix, run, BuildOutput, DepBuilder};
use crate::error::Result;
use std::path::Path;
use std::process::Command;
pub struct CMakeBuilder;
impl DepBuilder for CMakeBuilder {
fn detect(src_dir: &Path) -> bool {
src_dir.join("CMakeLists.txt").exists()
}
fn name(&self) -> &'static str {
"cmake"
}
fn build(&self, src_dir: &Path, prefix: &Path) -> Result<BuildOutput> {
run(Command::new("cmake")
.args(["-S", ".", "-B", "build"])
.arg(format!("-DCMAKE_INSTALL_PREFIX={}", prefix.display()))
.arg("-DCMAKE_BUILD_TYPE=Release")
.current_dir(src_dir))?;
run(Command::new("cmake")
.args(["--build", "build", "--parallel"])
.current_dir(src_dir))?;
run(Command::new("cmake")
.args(["--install", "build"])
.current_dir(src_dir))?;
Ok(collect_from_prefix(prefix))
}
}