Skip to content

Commit f10922d

Browse files
hatzeltilpner
authored andcommitted
Only call pkg_config if the feature is enabled (meh#66)
1 parent 5eb1ccc commit f10922d

File tree

1 file changed

+20
-30
lines changed

1 file changed

+20
-30
lines changed

sys/build.rs

+20-30
Original file line numberDiff line numberDiff line change
@@ -515,40 +515,30 @@ fn main() {
515515
}
516516
// Fallback to pkg-config
517517
else {
518-
pkg_config::Config::new()
519-
.statik(statik)
520-
.probe("libavformat")
521-
.unwrap();
522-
523-
pkg_config::Config::new()
524-
.statik(statik)
525-
.probe("libavfilter")
526-
.unwrap();
527-
528-
pkg_config::Config::new()
529-
.statik(statik)
530-
.probe("libavdevice")
531-
.unwrap();
532-
533-
pkg_config::Config::new()
534-
.statik(statik)
535-
.probe("libavresample")
536-
.unwrap();
537-
538518
pkg_config::Config::new()
539519
.statik(statik)
540520
.probe("libavutil")
541-
.unwrap();
542-
543-
pkg_config::Config::new()
544-
.statik(statik)
545-
.probe("libswscale")
546-
.unwrap();
521+
.unwrap()
522+
.include_paths;
523+
524+
let libs = vec![
525+
("libavformat", "AVFORMAT"),
526+
("libavfilter", "AVFILTER"),
527+
("libavdevice", "AVDEVICE"),
528+
("libavresample", "AVRESAMPLE"),
529+
("libswscale", "SWSCALE"),
530+
("libswresample", "SWRESAMPLE"),
531+
];
547532

548-
pkg_config::Config::new()
549-
.statik(statik)
550-
.probe("libswresample")
551-
.unwrap();
533+
for (lib_name, env_variable_name) in libs.iter() {
534+
if env::var(format!("CARGO_FEATURE_{}", env_variable_name)).is_ok() {
535+
pkg_config::Config::new()
536+
.statik(statik)
537+
.probe(lib_name)
538+
.unwrap()
539+
.include_paths;
540+
}
541+
};
552542

553543
pkg_config::Config::new()
554544
.statik(statik)

0 commit comments

Comments
 (0)