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

added boost version check #47805

Closed
wants to merge 4 commits into from
Closed
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
54 changes: 51 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ fn env_or_default(name: &str, defaults: &HashMap<String, String>) -> String {
}
}

fn write_cpp_conf_pri(path: &Path) -> Result<(), Box<dyn Error>> {
fn write_cpp_conf_pri(path: &Path, boost_include_path: &str) -> Result<(), Box<dyn Error>> {
let mut f = fs::File::create(path)?;

writeln!(&mut f)?;
writeln!(&mut f, "INCLUDEPATH = /usr/local/include")?;
println!(
"======= boost_include_path : {} =======",
boost_include_path
);
writeln!(&mut f, "INCLUDEPATH += /usr/local/include")?;

Ok(())
}
Expand All @@ -101,6 +105,38 @@ fn write_postbuild_conf_pri(
Ok(())
}

fn check_boost_version() -> Result<bool, Box<dyn Error>> {
let output = Command::new("bash")
.args(["-c", "grep \"BOOST_LIB_VERSION\" $(find /usr/local/Cellar/boost/ /usr/include /usr/local/include -name 'version.hpp' 2> /dev/null | grep 'boost/version.hpp') | grep -v \"//\" | cut -d '\"' -f2 | sed 's/_/./g'"])
.output()?;

let version_str = String::from_utf8(output.stdout)?.trim().to_string();
let version_parts: Vec<&str> = version_str.split('.').collect();

if version_parts.len() < 2 {
return Ok(false);
}

let major_version = version_parts[0].parse::<i32>()?;
let minor_version = version_parts[1].parse::<i32>()?;

Ok(major_version > 1 || (major_version == 1 && minor_version >= 71))
}

fn find_boost_include_path() -> Option<String> {
let possible_paths = vec!["/usr/local/include", "/usr/include"];
let boost_header = "boost/signals2.hpp";

for path in possible_paths {
let full_path = Path::new(path).join(boost_header);
if full_path.exists() {
return Some(path.to_string());
}
}

None
}

fn main() -> Result<(), Box<dyn Error>> {
let qt_host_bins = {
let pkg = "Qt5Core";
Expand Down Expand Up @@ -170,7 +206,19 @@ fn main() -> Result<(), Box<dyn Error>> {
fs::create_dir_all(cpp_out_dir.join(dir))?;
}

write_cpp_conf_pri(&cpp_out_dir.join("conf.pri"))?;
let mut boost_include_path = String::new();
match check_boost_version() {
Ok(true) => {
boost_include_path = find_boost_include_path().ok_or("Boost include path not found")?;
}
Ok(false) => {
return Err("Boost version is not sufficient.".to_string().into());
}
Err(_) => {
return Err("Error checking Boost version.".to_string().into());
}
}
write_cpp_conf_pri(&cpp_out_dir.join("conf.pri"), &boost_include_path)?;

write_postbuild_conf_pri(
&Path::new("postbuild").join("conf.pri"),
Expand Down
Loading