From a62e1e78f1e7dfc54485ea249e227ef33e8ca3b0 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Sat, 5 Sep 2020 00:50:46 +0800 Subject: [PATCH] Include libavutil/hwcontext_drm.h only when it exists This header was introduced in FFmpeg 3.4 so doesn't exist in earlier versions. --- build.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 598f3b3..9a560e8 100644 --- a/build.rs +++ b/build.rs @@ -604,6 +604,15 @@ fn search_include(include_paths: &[PathBuf], header: &str) -> String { format!("/usr/include/{}", header) } +fn maybe_search_include(include_paths: &[PathBuf], header: &str) -> Option { + let path = search_include(include_paths, header); + if fs::metadata(&path).is_ok() { + Some(path) + } else { + None + } +} + fn link_to_libraries(statik: bool) { let ffmpeg_ty = if statik { "static" } else { "dylib" }; for lib in LIBRARIES { @@ -1200,7 +1209,6 @@ fn main() { .header(search_include(&include_paths, "libavutil/hash.h")) .header(search_include(&include_paths, "libavutil/hmac.h")) .header(search_include(&include_paths, "libavutil/hwcontext.h")) - .header(search_include(&include_paths, "libavutil/hwcontext_drm.h")) .header(search_include(&include_paths, "libavutil/imgutils.h")) .header(search_include(&include_paths, "libavutil/lfg.h")) .header(search_include(&include_paths, "libavutil/log.h")) @@ -1243,6 +1251,12 @@ fn main() { builder = builder.header(search_include(&include_paths, "libswscale/swscale.h")); } + if let Some(hwcontext_drm_header) = + maybe_search_include(&include_paths, "libavutil/hwcontext_drm.h") + { + builder = builder.header(hwcontext_drm_header); + } + // Finish the builder and generate the bindings. let bindings = builder .generate()