Skip to content

Commit

Permalink
add CMAKE_CACHE_DIR env
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaraj-bh committed Oct 26, 2023
1 parent 28cd46e commit b242132
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ pub struct XWinOptions {
#[arg(long, env = "XWIN_CACHE_DIR", hide = true)]
pub xwin_cache_dir: Option<PathBuf>,

/// cmake cache directory
#[arg(long, env = "CMAKE_CACHE_DIR", hide = true)]
pub cmake_cache_dir: Option<PathBuf>,

/// The architectures to include in CRT/SDK
#[arg(
long,
Expand Down Expand Up @@ -60,6 +64,7 @@ impl Default for XWinOptions {
fn default() -> Self {
Self {
xwin_cache_dir: None,
cmake_cache_dir: None,
xwin_arch: vec![xwin::Arch::X86_64, xwin::Arch::Aarch64],
xwin_variant: vec![xwin::Variant::Desktop],
xwin_version: "16".to_string(),
Expand Down Expand Up @@ -396,16 +401,18 @@ impl XWinOptions {
}

fn setup_cmake_toolchain(&self, target: &str, xwin_cache_dir: &Path) -> Result<PathBuf> {
let cache_dir = dirs::cache_dir()
.unwrap_or_else(|| env::current_dir().expect("Failed to get current dir"))
.join(env!("CARGO_PKG_NAME"));
let cmake = cache_dir.join("cmake");
fs::create_dir_all(&cmake)?;
let cmake_cache_dir = self.cmake_cache_dir.clone().unwrap_or_else(|| {
dirs::cache_dir()
.unwrap_or_else(|| env::current_dir().expect("Failed to get current dir"))
.join(env!("CARGO_PKG_NAME"))
.join("cmake")
});
fs::create_dir_all(&cmake_cache_dir)?;

let override_file = cmake.join("override.cmake");
let override_file = cmake_cache_dir.join("override.cmake");
fs::write(override_file, include_bytes!("override.cmake"))?;

let toolchain_file = cmake.join(format!("{}-toolchain.cmake", target));
let toolchain_file = cmake_cache_dir.join(format!("{}-toolchain.cmake", target));
let target_arch = target
.split_once('-')
.map(|(x, _)| x)
Expand Down

0 comments on commit b242132

Please sign in to comment.