summaryrefslogtreecommitdiffstats
path: root/cmake/FetchedSharedLibrary.cmake
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-11-30 00:51:11 +0800
committerGitHub <noreply@github.com>2024-11-30 00:51:11 +0800
commit136c2e22b80d3ebf500d09d5ce6f4fa47dcac8a0 (patch)
tree50ff4f0ca3ed0217c00ed81ed58b3bbfa78f7996 /cmake/FetchedSharedLibrary.cmake
parentc005fe9978ec7d432f0a72c0b38f545f215e1244 (diff)
fetch and extract prebuilt deps lazily (#5707)
Closes https://github.com/shader-slang/slang/issues/5706 and https://github.com/shader-slang/slang/issues/5657
Diffstat (limited to 'cmake/FetchedSharedLibrary.cmake')
-rw-r--r--cmake/FetchedSharedLibrary.cmake53
1 files changed, 31 insertions, 22 deletions
diff --git a/cmake/FetchedSharedLibrary.cmake b/cmake/FetchedSharedLibrary.cmake
index fa0bd9f5e..bd7eb10f9 100644
--- a/cmake/FetchedSharedLibrary.cmake
+++ b/cmake/FetchedSharedLibrary.cmake
@@ -1,35 +1,44 @@
# Helper function to download and extract an archive
function(download_and_extract archive_name url)
- get_filename_component(extension ${url} EXT)
- set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}${extension}")
- set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}")
+ cmake_path(GET url FILENAME filename_with_ext)
+ cmake_path(GET url STEM LAST_ONLY file_stem)
+ set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${filename_with_ext}")
+ set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${file_stem}")
- if(EXISTS ${url})
- message(STATUS "Using local file for ${archive_name}: ${url}")
- set(archive_path ${url})
+ # Check if already extracted
+ file(GLOB EXTRACT_DIR_CONTENTS "${extract_dir}/*")
+ if(EXTRACT_DIR_CONTENTS)
+ message(STATUS "Using existing extracted files in ${extract_dir}")
else()
- message(STATUS "Fetching ${archive_name} from ${url}")
- file(
- DOWNLOAD ${url} ${archive_path}
- # SHOW_PROGRESS
- STATUS status
- )
-
- list(GET status 0 status_code)
- list(GET status 1 status_string)
- if(NOT status_code EQUAL 0)
+ # Check if archive already exists
+ if(EXISTS ${url})
+ message(STATUS "Using local file for ${archive_name}: ${url}")
+ set(archive_path ${url})
+ elseif(EXISTS ${archive_path})
message(
- WARNING
- "Failed to download ${archive_name} from ${url}: ${status_string}"
+ STATUS
+ "Using existing archive for ${archive_name}: ${archive_path}"
)
- return()
+ else()
+ message(STATUS "Fetching ${archive_name} from ${url}")
+ file(DOWNLOAD ${url} ${archive_path} STATUS status)
+
+ list(GET status 0 status_code)
+ list(GET status 1 status_string)
+ if(NOT status_code EQUAL 0)
+ message(
+ WARNING
+ "Failed to download ${archive_name} from ${url}: ${status_string}"
+ )
+ return()
+ endif()
endif()
- endif()
- file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir})
+ file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir})
+ message(STATUS "${archive_name} extracted to ${extract_dir}")
+ endif()
set(${archive_name}_SOURCE_DIR ${extract_dir} PARENT_SCOPE)
- message(STATUS "${archive_name} downloaded and extracted to ${extract_dir}")
endfunction()
# Add rules to copy & install shared library of name 'library_name' in the 'module_subdir' directory.