-
Notifications
You must be signed in to change notification settings - Fork 34
/
CMakeLists.txt
72 lines (66 loc) · 2.94 KB
/
CMakeLists.txt
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
69
70
71
72
#
# Copyright Quadrivium LLC
# All Rights Reserved
# SPDX-License-Identifier: Apache-2.0
#
add_library(assets)
find_program(ECHO echo)
function(embedded_chainspec EMBEDDED_CHAINSPEC_NAME EMBEDDED_CHAINSPEC_SOURCE)
set(OUTPUT ${EMBEDDED_CHAINSPEC_NAME}.cpp)
if(EMBEDDINGS)
set(INPUT ${CMAKE_CURRENT_LIST_DIR}/embedded_chainspec.cpp.in)
file(READ ${EMBEDDED_CHAINSPEC_SOURCE} EMBEDDED_CHAINSPEC_CONTENT)
else()
set(INPUT ${CMAKE_CURRENT_LIST_DIR}/off/embedded_chainspec.cpp.in)
endif()
configure_file(${INPUT} ${OUTPUT})
set_source_files_properties(${OUTPUT} PROPERTIES GENERATED TRUE)
target_sources(assets PRIVATE ${OUTPUT})
endfunction()
embedded_chainspec(embedded_chainspec ${PROJECT_SOURCE_DIR}/examples/first_kagome_chain/localchain.json)
embedded_chainspec(embedded_chainspec_polkadot ${PROJECT_SOURCE_DIR}/examples/polkadot/polkadot.json)
embedded_chainspec(embedded_chainspec_kusama ${PROJECT_SOURCE_DIR}/examples/kusama/kusama.json)
embedded_chainspec(embedded_chainspec_rococo ${PROJECT_SOURCE_DIR}/examples/rococo/rococo.json)
embedded_chainspec(embedded_chainspec_westend ${PROJECT_SOURCE_DIR}/examples/westend/westend.json)
embedded_chainspec(embedded_chainspec_paseo ${PROJECT_SOURCE_DIR}/examples/paseo/paseo.json)
set(OUTPUT embedded_keys.cpp)
if(EMBEDDINGS)
set(SOURCE ${PROJECT_SOURCE_DIR}/examples/first_kagome_chain/base_path/chains/rococo_dev/keystore)
if(NOT IS_DIRECTORY ${SOURCE})
fatal_error("Not found resource for embedded assets: ${SOURCE}")
endif()
add_custom_command(
OUTPUT ${OUTPUT}
PRE_BUILD
COMMAND ${ECHO} ARGS "// Embedded keys. Generated by cmake from ${SOURCE}" > ${OUTPUT}
COMMAND ${ECHO} ARGS >> ${OUTPUT}
COMMAND ${ECHO} ARGS "#include <assets/assets.hpp>" >> ${OUTPUT}
COMMAND ${ECHO} ARGS >> ${OUTPUT}
COMMAND ${ECHO} ARGS "#include <vector>" >> ${OUTPUT}
COMMAND ${ECHO} ARGS >> ${OUTPUT}
COMMAND ${ECHO} ARGS "namespace kagome::assets {" >> "${OUTPUT}"
COMMAND ${ECHO} ARGS >> ${OUTPUT}
COMMAND ${ECHO} ARGS " const std::vector<std::pair<const char *, const char *>> embedded_keys{" >> ${OUTPUT}
COMMAND sh ARGS -c "cd ${SOURCE};\
for key in * ; do\
${ECHO} -n \" {\\\"\";\
${ECHO} -n $key;\
${ECHO} \"\\\",\";\
${ECHO} -n \" \\\"\";\
cat $key;\
${ECHO} \"\\\"},\";\
done"
>> ${OUTPUT}
COMMAND ${ECHO} ARGS " };" >> ${OUTPUT}
COMMAND ${ECHO} ARGS >> ${OUTPUT}
COMMAND ${ECHO} ARGS "} // namespace kagome::assets" >> ${OUTPUT}
MAIN_DEPENDENCY ${SOURCE}
DEPENDS ${SOURCE}
COMMENT "Generating ${OUTPUT} with embedding keys"
VERBATIM
)
else()
file(COPY ${CMAKE_CURRENT_LIST_DIR}/off/embedded_keys.cpp DESTINATION .)
endif()
target_sources(assets PRIVATE ${OUTPUT})
kagome_install(assets)