Skip to content

Commit 1374d9d

Browse files
authored
Merge branch 'master' into push-qtwvolruuqpx
2 parents cc85030 + 136c2e2 commit 1374d9d

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

cmake/FetchedSharedLibrary.cmake

+31-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
# Helper function to download and extract an archive
22
function(download_and_extract archive_name url)
3-
get_filename_component(extension ${url} EXT)
4-
set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}${extension}")
5-
set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}")
3+
cmake_path(GET url FILENAME filename_with_ext)
4+
cmake_path(GET url STEM LAST_ONLY file_stem)
5+
set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${filename_with_ext}")
6+
set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${file_stem}")
67

7-
if(EXISTS ${url})
8-
message(STATUS "Using local file for ${archive_name}: ${url}")
9-
set(archive_path ${url})
8+
# Check if already extracted
9+
file(GLOB EXTRACT_DIR_CONTENTS "${extract_dir}/*")
10+
if(EXTRACT_DIR_CONTENTS)
11+
message(STATUS "Using existing extracted files in ${extract_dir}")
1012
else()
11-
message(STATUS "Fetching ${archive_name} from ${url}")
12-
file(
13-
DOWNLOAD ${url} ${archive_path}
14-
# SHOW_PROGRESS
15-
STATUS status
16-
)
17-
18-
list(GET status 0 status_code)
19-
list(GET status 1 status_string)
20-
if(NOT status_code EQUAL 0)
13+
# Check if archive already exists
14+
if(EXISTS ${url})
15+
message(STATUS "Using local file for ${archive_name}: ${url}")
16+
set(archive_path ${url})
17+
elseif(EXISTS ${archive_path})
2118
message(
22-
WARNING
23-
"Failed to download ${archive_name} from ${url}: ${status_string}"
19+
STATUS
20+
"Using existing archive for ${archive_name}: ${archive_path}"
2421
)
25-
return()
22+
else()
23+
message(STATUS "Fetching ${archive_name} from ${url}")
24+
file(DOWNLOAD ${url} ${archive_path} STATUS status)
25+
26+
list(GET status 0 status_code)
27+
list(GET status 1 status_string)
28+
if(NOT status_code EQUAL 0)
29+
message(
30+
WARNING
31+
"Failed to download ${archive_name} from ${url}: ${status_string}"
32+
)
33+
return()
34+
endif()
2635
endif()
27-
endif()
2836

29-
file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir})
37+
file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir})
38+
message(STATUS "${archive_name} extracted to ${extract_dir}")
39+
endif()
3040

3141
set(${archive_name}_SOURCE_DIR ${extract_dir} PARENT_SCOPE)
32-
message(STATUS "${archive_name} downloaded and extracted to ${extract_dir}")
3342
endfunction()
3443

3544
# Add rules to copy & install shared library of name 'library_name' in the 'module_subdir' directory.

0 commit comments

Comments
 (0)