diff options
Diffstat (limited to 'utils/cmake/download.cmake')
-rw-r--r-- | utils/cmake/download.cmake | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/utils/cmake/download.cmake b/utils/cmake/download.cmake new file mode 100644 index 0000000000..bd3df4d83d --- /dev/null +++ b/utils/cmake/download.cmake | |||
@@ -0,0 +1,47 @@ | |||
1 | # | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # | ||
9 | # All files in this archive are subject to the GNU General Public License. | ||
10 | # See the file COPYING in the source tree root for full license agreement. | ||
11 | # | ||
12 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
13 | # KIND, either express or implied. | ||
14 | # | ||
15 | |||
16 | # This is a separate cmake script, to be invoked as | ||
17 | # cmake -P -DURL=<url-to-download> -DOUTDIR=<output-folder> | ||
18 | # Downloads the file and store it in OUTDIR, using the file basename as output | ||
19 | # filename. | ||
20 | # The downloaded file gets its executable flag set. | ||
21 | |||
22 | function(gettempdir basedir tmpdir) | ||
23 | # Create a random filename in current directory. | ||
24 | # Result stored in tmpdir. | ||
25 | string(RANDOM LENGTH 24 _tmp) | ||
26 | while(EXISTS "${basedir}/${_tmp}.tmp") | ||
27 | string(RANDOM LENGTH 24 _tmp) | ||
28 | endwhile() | ||
29 | set("${tmpdir}" "${basedir}/${_tmp}.tmp" PARENT_SCOPE) | ||
30 | endfunction() | ||
31 | |||
32 | get_filename_component(fname "${URL}" NAME) | ||
33 | |||
34 | if(EXISTS "${OUTDIR}/${fname}") | ||
35 | message("-- Found ${fname}") | ||
36 | else() | ||
37 | message("-- Downloading ${URL} ...") | ||
38 | gettempdir(${OUTDIR} tmp) | ||
39 | |||
40 | # cmake CHOWN is 3.19+, thus download to a temporary folder, then copy. | ||
41 | file(DOWNLOAD "${URL}" "${tmp}/${fname}") | ||
42 | file(COPY "${tmp}/${fname}" DESTINATION "${OUTDIR}" | ||
43 | FILE_PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ) | ||
44 | file(REMOVE_RECURSE "${tmp}") | ||
45 | endif() | ||
46 | |||
47 | |||