build.rs 2.93 KB
Newer Older
1 2
// This file was generated by gir (https://github.com/gtk-rs/gir @ 1ee9edf)
// from gir-files (https://github.com/gtk-rs/gir-files @ a6c6926)
Sebastian Dröge's avatar
Sebastian Dröge committed
3 4
// DO NOT EDIT

Sebastian Dröge's avatar
Sebastian Dröge committed
5
#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
6 7
extern crate pkg_config;

Sebastian Dröge's avatar
Sebastian Dröge committed
8
#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
9
use pkg_config::{Config, Error};
Sebastian Dröge's avatar
Sebastian Dröge committed
10
#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
11
use std::env;
Sebastian Dröge's avatar
Sebastian Dröge committed
12
#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
13
use std::io;
Sebastian Dröge's avatar
Sebastian Dröge committed
14
#[cfg(not(feature = "dox"))]
15
use std::io::prelude::*;
Sebastian Dröge's avatar
Sebastian Dröge committed
16
#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
17 18
use std::process;

Sebastian Dröge's avatar
Sebastian Dröge committed
19 20 21 22
#[cfg(feature = "dox")]
fn main() {} // prevent linking libraries to avoid documentation failure

#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
23 24 25 26 27 28 29
fn main() {
    if let Err(s) = find() {
        let _ = writeln!(io::stderr(), "{}", s);
        process::exit(1);
    }
}

Sebastian Dröge's avatar
Sebastian Dröge committed
30
#[cfg(not(feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
31 32 33
fn find() -> Result<(), Error> {
    let package_name = "gstreamer-app-1.0";
    let shared_libs = ["gstapp-1.0"];
34 35 36
    let version = if cfg!(feature = "v1_16") {
        "1.16"
    } else if cfg!(feature = "v1_14") {
Sebastian Dröge's avatar
Sebastian Dröge committed
37
        "1.14"
38
    } else if cfg!(feature = "v1_12") {
Sebastian Dröge's avatar
Sebastian Dröge committed
39 40 41
        "1.12"
    } else if cfg!(feature = "v1_10") {
        "1.10"
42 43
    } else if cfg!(feature = "v1_8") {
        "1.8"
Sebastian Dröge's avatar
Sebastian Dröge committed
44 45
    } else if cfg!(feature = "v1_6") {
        "1.6"
46 47 48 49
    } else if cfg!(feature = "v1_4") {
        "1.4"
    } else if cfg!(feature = "v1_2") {
        "1.2"
Sebastian Dröge's avatar
Sebastian Dröge committed
50 51 52 53
    } else {
        "1.0"
    };

Sebastian Dröge's avatar
Sebastian Dröge committed
54 55 56
    if let Ok(inc_dir) = env::var("GTK_INCLUDE_DIR") {
        println!("cargo:include={}", inc_dir);
    }
Sebastian Dröge's avatar
Sebastian Dröge committed
57 58 59 60 61
    if let Ok(lib_dir) = env::var("GTK_LIB_DIR") {
        for lib_ in shared_libs.iter() {
            println!("cargo:rustc-link-lib=dylib={}", lib_);
        }
        println!("cargo:rustc-link-search=native={}", lib_dir);
62
        return Ok(());
Sebastian Dröge's avatar
Sebastian Dröge committed
63 64
    }

Sebastian Dröge's avatar
Sebastian Dröge committed
65
    let target = env::var("TARGET").expect("TARGET environment variable doesn't exist");
Sebastian Dröge's avatar
Sebastian Dröge committed
66 67 68 69
    let hardcode_shared_libs = target.contains("windows");

    let mut config = Config::new();
    config.atleast_version(version);
70
    config.print_system_libs(false);
Sebastian Dröge's avatar
Sebastian Dröge committed
71 72 73 74 75
    if hardcode_shared_libs {
        config.cargo_metadata(false);
    }
    match config.probe(package_name) {
        Ok(library) => {
Sebastian Dröge's avatar
Sebastian Dröge committed
76 77 78
            if let Ok(paths) = std::env::join_paths(library.include_paths) {
                println!("cargo:include={}", paths.to_string_lossy());
            }
Sebastian Dröge's avatar
Sebastian Dröge committed
79 80 81 82 83
            if hardcode_shared_libs {
                for lib_ in shared_libs.iter() {
                    println!("cargo:rustc-link-lib=dylib={}", lib_);
                }
                for path in library.link_paths.iter() {
84 85 86 87
                    println!(
                        "cargo:rustc-link-search=native={}",
                        path.to_str().expect("library path doesn't exist")
                    );
Sebastian Dröge's avatar
Sebastian Dröge committed
88 89 90 91 92 93 94 95 96 97 98 99 100
                }
            }
            Ok(())
        }
        Err(Error::EnvNoPkgConfig(_)) | Err(Error::Command { .. }) => {
            for lib_ in shared_libs.iter() {
                println!("cargo:rustc-link-lib=dylib={}", lib_);
            }
            Ok(())
        }
        Err(err) => Err(err),
    }
}