-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
179 lines (144 loc) · 5.71 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#######################################
# General
cmake_minimum_required(VERSION 3.10)
include(CMakeDependentOption)
if(NOT DEFINED ESP_PLATFORM)
project(libmicrofido2 C)
endif()
set(PRODUCT_NAME microfido2)
#######################################
# Options
set(_build_examples_default ON)
if(ESP_PLATFORM OR ZEPHYR)
set(_build_examples_default OFF)
endif()
option(BUILD_EXAMPLES "Build example applications" ${_build_examples_default})
#######################################
# Compilation
set(libmicrofido2_release_flags -O3)
set(libmicrofido2_debug_flags -ggdb -O0)
string (REPLACE ";" " " libmicrofido2_debug_flags_str "${libmicrofido2_debug_flags}")
string (REPLACE ";" " " libmicrofido2_release_flags_str "${libmicrofido2_release_flags}")
set(CMAKE_C_FLAGS_RELEASE "${libmicrofido2_release_flags_str}")
set(CMAKE_C_FLAGS_DEBUG "${libmicrofido2_debug_flags_str}")
set(libmicrofido2_definitions
-D_FIDO_INTERNAL
)
set(libmicrofido2_compile_options
-std=gnu99
-fstack-usage
-ffunction-sections
-fdata-sections
-fshort-enums
-Wall
)
file(GLOB SRC_FILES "src/*.c") # Load all files in src folder
set(libmicrofido2_include_dir
${CMAKE_CURRENT_SOURCE_DIR}/include
)
if(NOT DEFINED ESP_PLATFORM)
include_directories(${libmicrofido2_include_dir})
add_library(${PRODUCT_NAME} STATIC ${SRC_FILES})
endif()
if(NOT DEFINED ESP_PLATFORM)
add_compile_options(
${libmicrofido2_compile_options}
)
add_definitions(
${libmicrofido2_definitions}
)
endif()
set(libmicrofido2_external_lib_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/external/aes_gcm/include
${CMAKE_CURRENT_SOURCE_DIR}/external/cb0r/include
${CMAKE_CURRENT_SOURCE_DIR}/external/sha256/include
${CMAKE_CURRENT_SOURCE_DIR}/external/tinf/include
${CMAKE_CURRENT_SOURCE_DIR}/external/Monocypher/include
)
if(NOT DEFINED ESP_PLATFORM)
include_directories(${libmicrofido2_external_lib_include_dirs})
endif()
#######################################
# ESP IDF
if(ESP_PLATFORM)
idf_component_register(
SRCS ${SRC_FILES}
INCLUDE_DIRS ${libmicrofido2_include_dir}
PRIV_INCLUDE_DIRS ${libmicrofido2_external_lib_include_dirs}
)
set(libmicrofido2_build_options ${libmicrofido2_compile_options} ${libmicrofido2_definitions} ${libmicrofido2_release_flags})
target_compile_options(${COMPONENT_LIB} PRIVATE ${libmicrofido2_build_options})
unset(libmicrofido2_build_options)
endif()
option(ENABLE_SOFTWARE_CRYPTO "disable building software cryptography algorithms" ON)
if(ESP_PLATFORM AND CONFIG_USE_HW_CRYPTO)
set(ENABLE_SOFTWARE_CRYPTO OFF)
endif()
cmake_dependent_option(USE_SOFTWARE_CRYPTO_AES_GCM_ENCRYPT "include software AES GCM encryption" ON "ENABLE_SOFTWARE_CRYPTO" OFF)
if(NOT USE_SOFTWARE_CRYPTO_AES_GCM_ENCRYPT)
add_compile_definitions(NO_SOFTWARE_CRYPTO_AES_GCM_ENCRYPT)
endif()
cmake_dependent_option(USE_SOFTWARE_CRYPTO_AES_GCM_DECRYPT "include software AES GCM decryption" ON "ENABLE_SOFTWARE_CRYPTO" OFF)
if(NOT USE_SOFTWARE_CRYPTO_AES_GCM_DECRYPT)
add_compile_definitions(NO_SOFTWARE_CRYPTO_AES_GCM_DECRYPT)
endif()
cmake_dependent_option(USE_SOFTWARE_CRYPTO_ED25519_SIGN "include software ed25519 signature generation" OFF "ENABLE_SOFTWARE_CRYPTO" OFF)
if(NOT USE_SOFTWARE_CRYPTO_ED25519_SIGN)
add_compile_definitions(NO_SOFTWARE_CRYPTO_ED25519_SIGN)
endif()
cmake_dependent_option(USE_SOFTWARE_CRYPTO_ED25519_VERIFY "include software ed25519 signature verification" ON "ENABLE_SOFTWARE_CRYPTO" OFF)
if(NOT USE_SOFTWARE_CRYPTO_ED25519_VERIFY)
add_compile_definitions(NO_SOFTWARE_CRYPTO_ED25519_VERIFY)
endif()
cmake_dependent_option(USE_SOFTWARE_CRYPTO_SHA256 "include software SHA256" ON "ENABLE_SOFTWARE_CRYPTO" OFF)
if(NOT USE_SOFTWARE_CRYPTO_SHA256)
add_compile_definitions(NO_SOFTWARE_CRYPTO_SHA256)
endif()
cmake_dependent_option(USE_SOFTWARE_CRYPTO_SHA512 "include software SHA512" ON "ENABLE_SOFTWARE_CRYPTO" OFF)
if(NOT USE_SOFTWARE_CRYPTO_SHA512)
add_compile_definitions(NO_SOFTWARE_CRYPTO_SHA512)
endif()
# TODO: This should also be disabled when not using software crypto.
cmake_dependent_option(USE_SOFTWARE_RNG "include software RNG" ON "ENABLE_SOFTWARE_CRYPTO" ON)
if(NOT USE_SOFTWARE_RNG)
add_compile_definitions(NO_SOFTWARE_RNG)
endif()
#######################################
# External libraries
# Add AES GCM library
if(USE_SOFTWARE_CRYPTO_AES_GCM_ENCRYPT OR USE_SOFTWARE_CRYPTO_AES_GCM_DECRYPT)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/aes_gcm)
list(APPEND libmicrofido2_link_libs aes-gcm)
endif()
# Add cb0r library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/cb0r)
list(APPEND libmicrofido2_link_libs cb0r)
# Add SHA256 library
if(USE_SOFTWARE_CRYPTO_SHA256)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/sha256)
list(APPEND libmicrofido2_link_libs sha256)
endif()
# Add tinf library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/tinf)
list(APPEND libmicrofido2_link_libs tinf)
# Add Monocypher library
if (USE_SOFTWARE_CRYPTO_ED25519_SIGN OR USE_SOFTWARE_CRYPTO_ED25519_VERIFY)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/Monocypher)
target_compile_definitions(Monocypher PRIVATE PERIODICALLY_RESET_WATCHDOG)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Use -Os in debug build because otherwise it wouldn't fit on AVR.
target_compile_options(Monocypher PRIVATE -Os)
endif()
list(APPEND libmicrofido2_link_libs Monocypher)
endif()
# Link the object libraries
if(${ESP_PLATFORM})
target_link_libraries(${COMPONENT_LIB} PUBLIC ${libmicrofido2_link_libs})
else()
target_link_libraries(${PRODUCT_NAME} PUBLIC ${libmicrofido2_link_libs})
endif()
#######################################
# Examples
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()