//! Snappy compression library build module.

use super::{C_STANDARD, CXX_STANDARD};
use crate::linker;
use std::path::{Path, PathBuf};

pub fn build(install_dir: &Path) -> PathBuf {
    println!("[snappy] Building");
    let mut config = cmake::Config::new(std::path::Path::new("deps").join("snappy"));
    config
        .define("CMAKE_CXX_STANDARD", CXX_STANDARD)
        .define("CMAKE_C_STANDARD", C_STANDARD)
        .define("BUILD_SHARED_LIBS", "OFF")
        .define("SNAPPY_BUILD_TESTS", "OFF")
        .define("SNAPPY_BUILD_BENCHMARKS", "OFF")
        .define("HAVE_LIBZ", "OFF")
        .define("CMAKE_INSTALL_LIBDIR", install_dir);
    linker::apply_cmake_flags(&mut config);

    let dest_prefix = config.build();
    assert_eq!(
        dest_prefix.join(install_dir.file_name().unwrap()),
        install_dir,
        "CMake should build Snappy in provided install_dir"
    );
    dest_prefix
}
