Add vcpkg support on windows

Closes #2.

Signed-off-by: Zhiming Wang <i@zhimingwang.org>
This commit is contained in:
0xd34d10cc
2023-05-24 21:49:22 +02:00
committed by Till Höppner
parent f3791bbf27
commit c5e44b117b
2 changed files with 40 additions and 0 deletions
+3
View File
@@ -25,6 +25,9 @@ pkg-config = "0.3"
bindgen = "0.54"
regex = "1.3"
[target.'cfg(target_env = "msvc")'.build-dependencies]
vcpkg = "0.2"
[features]
default = ["avcodec", "avdevice", "avfilter", "avformat", "swresample", "swscale"]
+37
View File
@@ -341,6 +341,25 @@ fn build() -> io::Result<()> {
Ok(())
}
#[cfg(not(target_env = "msvc"))]
fn try_vcpkg(_statik: bool) -> Option<Vec<PathBuf>> {
None
}
#[cfg(target_env = "msvc")]
fn try_vcpkg(statik: bool) -> Option<Vec<PathBuf>> {
if !statik {
env::set_var("VCPKGRS_DYNAMIC", "1");
}
vcpkg::find_package("ffmpeg")
.map_err(|e| {
println!("Could not find ffmpeg with vcpkg: {}", e);
})
.map(|library| library.include_paths)
.ok()
}
fn check_features(
include_paths: Vec<PathBuf>,
infos: &Vec<(&'static str, Option<&'static str>, &'static str)>,
@@ -574,6 +593,24 @@ fn main() {
);
link_to_libraries(statik);
vec![ffmpeg_dir.join("include")]
} else if let Some(paths) = try_vcpkg(statik) {
// vcpkg doesn't detect the "system" dependencies
if statik {
if cfg!(feature = "avcodec") || cfg!(feature = "avdevice") {
println!("cargo:rustc-link-lib=ole32");
}
if cfg!(feature = "avformat") {
println!("cargo:rustc-link-lib=secur32");
println!("cargo:rustc-link-lib=ws2_32");
}
// avutil depdendencies
println!("cargo:rustc-link-lib=bcrypt");
println!("cargo:rustc-link-lib=user32");
}
paths
}
// Fallback to pkg-config
else {