-
Notifications
You must be signed in to change notification settings - Fork 28
/
cable.cmake
executable file
·68 lines (60 loc) · 1.95 KB
/
cable.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env -S cmake -P
# Cable: CMake Bootstrap Library <https://github.com/ethereum/cable>
# Copyright 2019-2020 Pawel Bylica.
# Licensed under the Apache License, Version 2.0.
# The cable command-line tool, version 1.0.0
#
# This CMake script allows installing or updating Cable modules.
# Commands:
# - list
# - install
# - update
#
# You can also include it from CMakeLists.txt to add Cable modules to
# CMAKE_MODULE_PATH.
if(NOT CMAKE_SCRIPT_MODE_FILE)
# Setup Cable modules when included as include(cable.cmake).
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
return()
endif()
set(repo_url https://github.com/ethereum/cable)
set(download_url ${repo_url}/raw/master)
set(cable_dir ${CMAKE_CURRENT_LIST_DIR})
function(get_modules_list OUTPUT_LIST)
file(GLOB modules_files RELATIVE ${cable_dir} "${cable_dir}/Cable*.cmake")
string(REPLACE ".cmake" "" modules "${modules_files}")
set(${OUTPUT_LIST} "${modules}" PARENT_SCOPE)
endfunction()
function(download MODULE_NAME)
set(module_file ${MODULE_NAME}.cmake)
set(src "${download_url}/${module_file}")
set(dst "${cable_dir}/${module_file}")
file(DOWNLOAD "${src}" "${dst}" STATUS status)
list(GET status 0 status_code)
list(GET status 1 error_msg)
if(status EQUAL 0)
set(msg DONE)
else()
file(REMOVE "${dst}")
set(msg "${status_code} ${error_msg}\n ${src}")
endif()
message("Downloading ${MODULE_NAME}: ${msg}")
endfunction()
set(cmd ${CMAKE_ARGV3}) # cmake -P cable.cmake ARGV3 ARGV4 ...
if(NOT cmd)
set(cmd list)
endif()
if(cmd STREQUAL list)
get_modules_list(modules)
string(REPLACE ";" "\n " modules "${modules}")
message("Installed modules:\n ${modules}")
elseif(cmd STREQUAL update)
get_modules_list(modules)
foreach(module ${modules})
download(${module})
endforeach()
elseif(cmd STREQUAL install)
download(${CMAKE_ARGV4})
else()
message(FATAL_ERROR "Unknown command '${cmd}'")
endif()