diff --git a/build.rs b/build.rs index a6457a0a..6aea5ce4 100644 --- a/build.rs +++ b/build.rs @@ -73,11 +73,15 @@ fn env_or_default(name: &str, defaults: &HashMap) -> String { } } -fn write_cpp_conf_pri(path: &Path) -> Result<(), Box> { +fn write_cpp_conf_pri(path: &Path, boost_include_path: &str) -> Result<(), Box> { 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(()) } @@ -101,6 +105,38 @@ fn write_postbuild_conf_pri( Ok(()) } +fn check_boost_version() -> Result> { + 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::()?; + let minor_version = version_parts[1].parse::()?; + + Ok(major_version > 1 || (major_version == 1 && minor_version >= 71)) +} + +fn find_boost_include_path() -> Option { + 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> { let qt_host_bins = { let pkg = "Qt5Core"; @@ -170,7 +206,19 @@ fn main() -> Result<(), Box> { 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"),