Skip to content

Commit

Permalink
Indicate static linker flag for static libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedfall committed Jul 14, 2024
1 parent 7184a1e commit e680a22
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
8 changes: 7 additions & 1 deletion build/cmake_probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl<'r> CmakeProbe<'r> {
}
} else if !arg.starts_with('-') {
let path = Path::new(arg);
let is_static = path.extension().map_or(false, |ext| ext.eq_ignore_ascii_case("a"));
if let Some(file) = path.file_name().and_then(super::cleanup_lib_filename) {
if let Some(parent) = path.parent().map(|p| p.to_owned()) {
if !link_paths.contains(&parent) {
Expand All @@ -167,7 +168,12 @@ impl<'r> CmakeProbe<'r> {
} else {
panic!("{}", arg.to_string());
}
link_libs.push(file.to_str().expect("Non-UTF8 filename").to_string());
let file = file.to_str().expect("Non-UTF8 filename");
if is_static {
link_libs.push(format!("static={}", file));
} else {
link_libs.push(file.to_string());
}
}
} else {
eprintln!("=== Unexpected cmake compiler argument found: {arg}");
Expand Down
54 changes: 27 additions & 27 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ fn test_extract_from_cmdline() {
];
assert_eq!(expect_link_paths, link_paths);
let expect_link_libs = vec![
"opencv_calib3d4d",
"opencv_core4d",
"opencv_features2d4d",
"opencv_flann4d",
"opencv_highgui4d",
"opencv_imgcodecs4d",
"opencv_imgproc4d",
"opencv_ml4d",
"opencv_objdetect4d",
"opencv_photo4d",
"opencv_stitching4d",
"opencv_video4d",
"opencv_videoio4d",
"opencv_imgcodecs4d",
"jpeg",
"tiffd",
"lzma",
"jpeg",
"tiffd",
"lzma",
"static=opencv_calib3d4d",
"static=opencv_core4d",
"static=opencv_features2d4d",
"static=opencv_flann4d",
"static=opencv_highgui4d",
"static=opencv_imgcodecs4d",
"static=opencv_imgproc4d",
"static=opencv_ml4d",
"static=opencv_objdetect4d",
"static=opencv_photo4d",
"static=opencv_stitching4d",
"static=opencv_video4d",
"static=opencv_videoio4d",
"static=opencv_imgcodecs4d",
"static=jpeg",
"static=tiffd",
"static=lzma",
"static=jpeg",
"static=tiffd",
"static=lzma",
"m",
"AppKit.framework",
"Accelerate.framework",
Expand All @@ -50,14 +50,14 @@ fn test_extract_from_cmdline() {
"CoreVideo.framework",
"QuartzCore.framework",
"Cocoa.framework",
"opencv_calib3d4d",
"opencv_features2d4d",
"opencv_flann4d",
"opencv_imgproc4d",
"opencv_core4d",
"z",
"static=opencv_calib3d4d",
"static=opencv_features2d4d",
"static=opencv_flann4d",
"static=opencv_imgproc4d",
"static=opencv_core4d",
"static=z",
"OpenCL.framework",
"tegra_hald",
"static=tegra_hald",
];
assert_eq!(expect_link_libs, link_libs);
}

0 comments on commit e680a22

Please sign in to comment.