Skip to content

Commit 3716eb4

Browse files
committed
Indicate static linker flag for static libraries
1 parent 9952f69 commit 3716eb4

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed

build/cmake_probe.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl<'r> CmakeProbe<'r> {
159159
}
160160
} else if !arg.starts_with('-') {
161161
let path = Path::new(arg);
162+
let is_static = path.extension().map_or(false, |ext| ext.eq_ignore_ascii_case("a"));
162163
if let Some(file) = path.file_name().and_then(super::cleanup_lib_filename) {
163164
if let Some(parent) = path.parent().map(|p| p.to_owned()) {
164165
if !link_paths.contains(&parent) {
@@ -167,7 +168,12 @@ impl<'r> CmakeProbe<'r> {
167168
} else {
168169
panic!("{}", arg.to_string());
169170
}
170-
link_libs.push(file.to_str().expect("Non-UTF8 filename").to_string());
171+
let file = file.to_str().expect("Non-UTF8 filename");
172+
if is_static {
173+
link_libs.push(format!("static={}", file));
174+
} else {
175+
link_libs.push(file.to_string());
176+
}
171177
}
172178
} else {
173179
eprintln!("=== Unexpected cmake compiler argument found: {arg}");

tests/build.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ fn test_extract_from_cmdline() {
2121
];
2222
assert_eq!(expect_link_paths, link_paths);
2323
let expect_link_libs = vec![
24-
"opencv_calib3d4d",
25-
"opencv_core4d",
26-
"opencv_features2d4d",
27-
"opencv_flann4d",
28-
"opencv_highgui4d",
29-
"opencv_imgcodecs4d",
30-
"opencv_imgproc4d",
31-
"opencv_ml4d",
32-
"opencv_objdetect4d",
33-
"opencv_photo4d",
34-
"opencv_stitching4d",
35-
"opencv_video4d",
36-
"opencv_videoio4d",
37-
"opencv_imgcodecs4d",
38-
"jpeg",
39-
"tiffd",
40-
"lzma",
41-
"jpeg",
42-
"tiffd",
43-
"lzma",
24+
"static=opencv_calib3d4d",
25+
"static=opencv_core4d",
26+
"static=opencv_features2d4d",
27+
"static=opencv_flann4d",
28+
"static=opencv_highgui4d",
29+
"static=opencv_imgcodecs4d",
30+
"static=opencv_imgproc4d",
31+
"static=opencv_ml4d",
32+
"static=opencv_objdetect4d",
33+
"static=opencv_photo4d",
34+
"static=opencv_stitching4d",
35+
"static=opencv_video4d",
36+
"static=opencv_videoio4d",
37+
"static=opencv_imgcodecs4d",
38+
"static=jpeg",
39+
"static=tiffd",
40+
"static=lzma",
41+
"static=jpeg",
42+
"static=tiffd",
43+
"static=lzma",
4444
"m",
4545
"AppKit.framework",
4646
"Accelerate.framework",
@@ -50,14 +50,14 @@ fn test_extract_from_cmdline() {
5050
"CoreVideo.framework",
5151
"QuartzCore.framework",
5252
"Cocoa.framework",
53-
"opencv_calib3d4d",
54-
"opencv_features2d4d",
55-
"opencv_flann4d",
56-
"opencv_imgproc4d",
57-
"opencv_core4d",
58-
"z",
53+
"static=opencv_calib3d4d",
54+
"static=opencv_features2d4d",
55+
"static=opencv_flann4d",
56+
"static=opencv_imgproc4d",
57+
"static=opencv_core4d",
58+
"static=z",
5959
"OpenCL.framework",
60-
"tegra_hald",
60+
"static=tegra_hald",
6161
];
6262
assert_eq!(expect_link_libs, link_libs);
6363
}

0 commit comments

Comments
 (0)