-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCMakeLists.txt
153 lines (132 loc) · 6.54 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
cmake_minimum_required(VERSION 3.21.0)
###########################################################################
# #
# Setup #
# #
###########################################################################
option(LT_USE_TREZOR_CRYPTO "Use trezor_crypto as a cryptography provider" OFF)
option(LT_CRYPTO_MBEDTLS "Use mbedtls as a cryptography provider" OFF)
option(LT_BUILD_DOCS "Build documentation" OFF)
option(LT_EXPERIMENTAL_SPI_UART "Experimental feature for spi slave to serial hw convertor" OFF)
option(LT_ADD_EXAMPLES "Compile example code as part of libtropic library" OFF)
option(LT_ENABLE_FW_UPDATE "Enable firmware update functions and compile firmware update in a form of byte array" OFF)
# This switch controls if helper utilities are compiled in. In most cases this should be ON,
# examples and tests need to have helpers utilities compiled.
# Switch it off to compile only basic libtropic API.
option(LT_UTILS "Compile helper function" ON)
###########################################################################
# #
# Building documentation #
# #
###########################################################################
if(LT_BUILD_DOCS)
find_package(Doxygen)
if(Doxygen_FOUND)
add_subdirectory(docs)
message(STATUS "Doxygen found, building docs")
else()
message(STATUS "Doxygen not found, not building docs")
endif()
endif()
# Check if cryptography provider is defined
if((NOT LT_USE_TREZOR_CRYPTO) AND (NOT LT_CRYPTO_MBEDTLS) AND (NOT LT_BUILD_DOCS))
message(FATAL_ERROR "Mbed TLS or trezor_crypto must be enabled!")
endif()
###########################################################################
# #
# Collect files: #
# #
# SDK_SRCS: source files #
# SDK_INCS: header files #
# SDK_DIRS_PRIV: private directories #
# SDK_DIRS_PUB: public directories #
# #
###########################################################################
project(libtropic_SDK
VERSION 0.0.1
DESCRIPTION "TROPIC01 software development kit"
HOMEPAGE_URL "www.tropicsquare.com"
LANGUAGES C)
# Collect source files which are always compiled
set(SDK_SRCS ${SDK_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/src/libtropic.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_crc16.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1_port_wrap.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2_frame_check.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l3.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_hkdf.c
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_random.c
)
set(SDK_SRCS ${SDK_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_aesgcm.c
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_ed25519.c
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_sha256.c
${CMAKE_CURRENT_SOURCE_DIR}/hal/crypto/trezor_crypto/lt_crypto_trezor_x25519.c
)
set(SDK_INCS ${SDK_INCS}
${CMAKE_CURRENT_SOURCE_DIR}/include/libtropic_common.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libtropic.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libtropic_port.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_crc16.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1_port_wrap.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l1.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l2_frame_check.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_l3.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_hkdf.h
${CMAKE_CURRENT_SOURCE_DIR}/src/lt_random.h
)
set(SDK_DIRS_PRIV ${SDK_DIRS_PRIV}
${CMAKE_CURRENT_SOURCE_DIR}/src/
)
set(SDK_DIRS_PUB ${SDK_DIRS_PUB}
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# Collect files to be compiled when "examples" are enabled
if(LT_ADD_EXAMPLES)
set(SDK_SRCS ${SDK_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/examples/lt_ex_hello_world.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/lt_ex_hw_wallet.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/lt_ex_test_reversible.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/lt_ex_test_ireversible.c
${CMAKE_CURRENT_SOURCE_DIR}/examples/keys.c
)
set(SDK_DIRS_PUB ${SDK_DIRS_PUB}
${CMAKE_CURRENT_SOURCE_DIR}/examples/
)
endif()
# Collect files to be compiled when "fw update" is enabled
if(LT_ENABLE_FW_UPDATE)
set(SDK_INCS ${SDK_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/TROPIC01_fw_update_files/boot_v1.0.1/fw_CPU_0_1_2.h
${CMAKE_CURRENT_SOURCE_DIR}/examples/lt_ex_fw_update.c
)
set(SDK_DIRS_PUB ${SDK_DIRS_PUB}
${CMAKE_CURRENT_SOURCE_DIR}/TROPIC01_fw_update_files/boot_v1.0.1/
)
endif()
add_library(tropic ${SDK_SRCS} ${SDK_INCS})
target_include_directories(tropic PRIVATE ${SDK_DIRS_PRIV})
target_include_directories(tropic PUBLIC ${SDK_DIRS_PUB})
target_compile_definitions(tropic PRIVATE "$<$<CONFIG:DEBUG>:LIBT_DEBUG>")
###########################################################################
# #
# Compile and link #
# #
###########################################################################
# This options just add 10ms synchronisation delay before read and write functions.
# Needed for hardware spi slave to uart converter.
if(LT_EXPERIMENTAL_SPI_UART)
target_compile_definitions(tropic PRIVATE LT_EXPERIMENTAL_SPI_UART=1)
endif()
if(LT_USE_TREZOR_CRYPTO)
add_subdirectory(vendor/trezor_crypto/ "trezor_crypto")
target_compile_definitions(trezor_crypto PRIVATE AES_VAR USE_INSECURE_PRNG)
target_link_libraries(tropic PRIVATE trezor_crypto)
target_compile_definitions(tropic PRIVATE LT_USE_TREZOR_CRYPTO)
endif()
if(LT_UTILS)
target_compile_definitions(tropic PRIVATE LT_UTILS)
endif()