forked from nrfconnect/suit-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
113 lines (101 loc) · 3.14 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# Copyright (c) 2022 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
if((NOT DEFINED ZEPHYR_ZCBOR_MODULE_DIR) OR (NOT EXISTS "${ZEPHYR_ZCBOR_MODULE_DIR}/zcbor/zcbor.py"))
message(STATUS "Use zcbor command")
set(ZCBOR_COMMAND zcbor)
else()
message(STATUS "Use python zcbor.py file")
set(ZCBOR_COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_ZCBOR_MODULE_DIR}/zcbor/zcbor.py)
endif()
set(ZCBOR_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# Generate and add COSE parser code
set(ZCBOR_COMMAND_COSE
${ZCBOR_COMMAND}
code
-c "${CMAKE_CURRENT_LIST_DIR}/cddl/cose_sign.cddl"
-d -e
-t COSE_Sign1_Tagged Sig_structure1
--output-cmake cose.cmake
--copy-sources
)
if(NOT EXISTS "${ZCBOR_DIR}/cose.cmake")
execute_process(
COMMAND ${ZCBOR_COMMAND_COSE}
WORKING_DIRECTORY ${ZCBOR_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
# Create cmake target to track changes in the input cddl file
add_custom_command(
OUTPUT "${ZCBOR_DIR}/cose.cmake"
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/cddl/cose_sign.cddl"
COMMAND ${ZCBOR_COMMAND_COSE}
WORKING_DIRECTORY "${ZCBOR_DIR}"
)
add_custom_target(zcbor_cose ALL
DEPENDS "${ZCBOR_DIR}/cose.cmake"
COMMENT "Generate cose encode/decode sources for parsing CBOR"
)
include("${ZCBOR_DIR}/cose.cmake")
# Specify the absolute path for ZCBOR-generated code include directory
target_include_directories(cose PUBLIC
${ZCBOR_DIR}/include
)
# Generate and add SUIT envelope parser code
set(ZCBOR_COMMAND_MANIFEST
${ZCBOR_COMMAND}
code
-c "${CMAKE_CURRENT_LIST_DIR}/cddl/manifest.cddl"
-c "${CMAKE_CURRENT_LIST_DIR}/cddl/trust_domains.cddl"
-d
-t SUIT_Envelope_Tagged SUIT_Manifest SUIT_Shared_Sequence SUIT_Command_Sequence
SUIT_Condition SUIT_Directive SUIT_Shared_Commands SUIT_Text_Map SUIT_Digest
--output-cmake manifest.cmake
--copy-sources
)
if(NOT EXISTS "${ZCBOR_DIR}/manifest.cmake")
execute_process(
COMMAND ${ZCBOR_COMMAND_MANIFEST}
WORKING_DIRECTORY ${ZCBOR_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
# Create cmake target to track changes in the input cddl file
add_custom_command(
OUTPUT "${ZCBOR_DIR}/manifest.cmake"
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/cddl/manifest.cddl"
DEPENDS "${CMAKE_CURRENT_LIST_DIR}/cddl/trust_domains.cddl"
COMMAND ${ZCBOR_COMMAND_MANIFEST}
WORKING_DIRECTORY "${ZCBOR_DIR}"
)
add_custom_target(zcbor_manifest ALL
DEPENDS "${ZCBOR_DIR}/manifest.cmake"
COMMENT "Generate manifest encode/decode sources for parsing CBOR"
)
include("${ZCBOR_DIR}/manifest.cmake")
# Specify the absolute path for ZCBOR-generated code include directory
target_include_directories(manifest PUBLIC
${ZCBOR_DIR}/include
)
# Define SUIT library
add_library(suit)
target_sources(suit PRIVATE
src/suit_manifest.c
src/suit_decoder.c
src/suit_schedule_seq.c
src/suit_seq_exec.c
src/suit_condition.c
src/suit_directive.c
src/suit.c
)
target_include_directories(suit PUBLIC
include
)
# Link with the auto-generated code
target_link_libraries(suit PUBLIC manifest)
target_link_libraries(suit PUBLIC cose)
# Canonical mode is required to encode the Signature1 structure correctly
add_compile_definitions(ZCBOR_CANONICAL)