This repository was archived by the owner on Jan 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsoncreate.cmake
More file actions
47 lines (37 loc) · 1.44 KB
/
jsoncreate.cmake
File metadata and controls
47 lines (37 loc) · 1.44 KB
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
set(CHKSUM_PREFIX1 "\"")
set(CHKSUM_PREFIX2 "\": \"")
set(CHKSUM_SUFFIX "\"")
if(NOT DEFINED EXECUTABLE)
set(EXECUTABLE CACHE STRING "EXECUTABLE")
endif()
if(NOT DEFINED OUT_DIR)
set(OUT_DIR CACHE STRING "OUT_DIR")
endif()
if(NOT DEFINED XML_FILE)
set(XML_FILE CACHE STRING "XML_FILE")
endif()
if(NOT DEFINED HOME)
set(HOME CACHE STRING "HOME")
endif()
set(EXEC_PATH ${OUT_DIR}/${EXECUTABLE})
message("Path: ${EXEC_PATH}")
if(EXISTS ${EXEC_PATH})
file(SHA1 ${EXEC_PATH} exe_sha1)
set(sha1_chksum "${CHKSUM_PREFIX1}sha1${CHKSUM_PREFIX2}${exe_sha1}${CHKSUM_SUFFIX}")
file(SHA512 ${EXEC_PATH} exe_sha512)
set(sha512_chksum "${CHKSUM_PREFIX1}sha512${CHKSUM_PREFIX2}${exe_sha512}${CHKSUM_SUFFIX}")
#Skip first hash to avoid fencepost issue for foreach loop
set(hashes ${sha512_chksum})
set(executable_details "\t\t\"${CMAKE_SYSTEM_NAME}\": {\n\t\t\t\"file_name\": \"${EXECUTABLE}\",\n")
set(executable_details "${executable_details}\t\t\t${sha1_chksum}")
foreach(hash IN LISTS hashes)
set(executable_details "${executable_details},\n\t\t\t${hash}")
endforeach()
set(executable_details "${executable_details}\n\t\t}")
else()
message(WARNING "The excutable does not exist! Skipping hashes.")
endif()
file(READ "${HOME}/resources/plugin.json" json)
STRING(REPLACE "\t\t\"!OS\": {}" "${executable_details}" json_out ${json})
STRING(REPLACE "!PLUGIN_NAME" "polyslack" json_out ${json_out})
file(WRITE "${OUT_DIR}/${JSON_FILE}" "${json_out}")