Beautify cmake files.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-03-07 13:30:37 +01:00
parent 6c7b254183
commit 4c88d712b4
7 changed files with 245 additions and 189 deletions

View File

@@ -1,23 +1,23 @@
# #
# This file is part of the Pico Keys SDK distribution (https://github.com/polhenarejos/pico-keys-sdk). # This file is part of the Pico Keys SDK distribution (https://github.com/polhenarejos/pico-keys-sdk).
# Copyright (c) 2022 Pol Henarejos. # Copyright (c) 2022 Pol Henarejos.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3. # the Free Software Foundation, version 3.
# #
# This program is distributed in the hope that it will be useful, but # This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of # WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details. # General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
if(ESP_PLATFORM) if(ESP_PLATFORM)
set(EXTRA_COMPONENT_DIRS src) set(EXTRA_COMPONENT_DIRS src)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
else() else()
@@ -35,7 +35,7 @@ else()
set(__FOR_CI 0) set(__FOR_CI 0)
endif() endif()
if(__FOR_CI) if(__FOR_CI)
add_definitions(-D__FOR_CI) add_compile_definitions(__FOR_CI)
endif() endif()
add_executable(pico_rescue) add_executable(pico_rescue)
@@ -48,7 +48,7 @@ include(pico_keys_sdk_import.cmake)
if(NOT ESP_PLATFORM) if(NOT ESP_PLATFORM)
set(SOURCES ${PICO_KEYS_SOURCES}) set(SOURCES ${PICO_KEYS_SOURCES})
endif() endif()
set(SOURCES ${SOURCES} list(APPEND SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/fs/files.c ${CMAKE_CURRENT_LIST_DIR}/src/fs/files.c
${CMAKE_CURRENT_LIST_DIR}/src/version.c ${CMAKE_CURRENT_LIST_DIR}/src/version.c
) )
@@ -63,40 +63,26 @@ if(NOT ESP_PLATFORM)
target_sources(pico_rescue PUBLIC ${SOURCES}) target_sources(pico_rescue PUBLIC ${SOURCES})
target_include_directories(pico_rescue PUBLIC ${INCLUDES}) target_include_directories(pico_rescue PUBLIC ${INCLUDES})
target_compile_options(pico_rescue PUBLIC target_compile_options(pico_rescue PRIVATE -Wall)
-Wall
)
if(NOT MSVC) if(NOT MSVC)
target_compile_options(pico_rescue PUBLIC target_compile_options(pico_rescue PRIVATE -Werror)
-Werror
)
endif() endif()
if(ENABLE_EMULATION) if(ENABLE_EMULATION)
if(NOT MSVC) if(NOT MSVC)
target_compile_options(pico_rescue PUBLIC target_compile_options(pico_rescue PRIVATE -fdata-sections -ffunction-sections)
-fdata-sections
-ffunction-sections
)
endif() endif()
if(APPLE) if(APPLE)
target_link_options(pico_rescue PUBLIC target_link_options(pico_rescue PRIVATE -Wl,-dead_strip)
-Wl,-dead_strip
)
elseif(MSVC) elseif(MSVC)
target_compile_options(pico_rescue PUBLIC target_compile_options(pico_rescue PRIVATE -WX)
-WX
)
target_link_libraries(pico_rescue PUBLIC wsock32 ws2_32 Bcrypt) target_link_libraries(pico_rescue PRIVATE wsock32 ws2_32 Bcrypt)
else() else()
target_link_options(pico_rescue PUBLIC target_link_options(pico_rescue PRIVATE -Wl,--gc-sections)
-Wl,--gc-sections endif()
)
endif(APPLE)
target_link_libraries(pico_rescue PRIVATE pthread m) target_link_libraries(pico_rescue PRIVATE pthread m)
else() else()
pico_add_extra_outputs(${CMAKE_PROJECT_NAME}) pico_add_extra_outputs(${CMAKE_PROJECT_NAME})
endif() endif()
endif() endif()

View File

@@ -1,4 +1,4 @@
function(dict command dict ) function(dict command dict)
if(command STREQUAL SET) if(command STREQUAL SET)
set(arg_key ${ARGV2}) set(arg_key ${ARGV2})
set(arg_value ${ARGV3}) set(arg_value ${ARGV3})
@@ -10,7 +10,6 @@ function(dict command dict )
list(APPEND ${dict} "${arg_key}=${arg_value}") list(APPEND ${dict} "${arg_key}=${arg_value}")
set(${dict} "${${dict}}" PARENT_SCOPE) set(${dict} "${${dict}}" PARENT_SCOPE)
elseif(command STREQUAL GET) elseif(command STREQUAL GET)
set(arg_key ${ARGV2}) set(arg_key ${ARGV2})
set(arg_outvar ${ARGV3}) set(arg_outvar ${ARGV3})
@@ -23,7 +22,6 @@ function(dict command dict )
list(GET ${dict} ${idx} kv) list(GET ${dict} ${idx} kv)
string(REGEX REPLACE "^[^=]+=(.*)" "\\1" value "${kv}") string(REGEX REPLACE "^[^=]+=(.*)" "\\1" value "${kv}")
set(${arg_outvar} "${value}" PARENT_SCOPE) set(${arg_outvar} "${value}" PARENT_SCOPE)
elseif(command STREQUAL _IDX) elseif(command STREQUAL _IDX)
set(arg_key ${ARGV2}) set(arg_key ${ARGV2})
set(arg_outvar ${ARGV3}) set(arg_outvar ${ARGV3})
@@ -34,10 +32,9 @@ function(dict command dict )
set(${arg_outvar} "${idx}" PARENT_SCOPE) set(${arg_outvar} "${idx}" PARENT_SCOPE)
return() return()
endif() endif()
math(EXPR idx ${idx}+1) math(EXPR idx ${idx} + 1)
endforeach() endforeach()
set(${arg_outvar} "-1" PARENT_SCOPE) set(${arg_outvar} "-1" PARENT_SCOPE)
else() else()
message(FATAL_ERROR "dict does not recognize sub-command ${command}") message(FATAL_ERROR "dict does not recognize sub-command ${command}")
endif() endif()

14
cmake/options.cmake Normal file
View File

@@ -0,0 +1,14 @@
macro(configure_bool_option option_name define_name enabled_msg disabled_msg)
if(${option_name})
if(NOT "${define_name}" STREQUAL "")
add_compile_definitions(${define_name}=1)
endif()
message(STATUS "${enabled_msg}")
else()
if(NOT "${define_name}" STREQUAL "")
add_compile_definitions(${define_name}=0)
endif()
message(STATUS "${disabled_msg}")
endif()
endmacro()

View File

@@ -1,37 +1,36 @@
macro(HEXCHAR2DEC VAR VAL) macro(HEXCHAR2DEC VAR VAL)
if(${VAL} MATCHES "[0-9]") if(${VAL} MATCHES "[0-9]")
SET(${VAR} ${VAL}) set(${VAR} ${VAL})
elseif(${VAL} MATCHES "[aA]") elseif(${VAL} MATCHES "[aA]")
SET(${VAR} 10) set(${VAR} 10)
elseif(${VAL} MATCHES "[bB]") elseif(${VAL} MATCHES "[bB]")
SET(${VAR} 11) set(${VAR} 11)
elseif(${VAL} MATCHES "[cC]") elseif(${VAL} MATCHES "[cC]")
SET(${VAR} 12) set(${VAR} 12)
elseif(${VAL} MATCHES "[dD]") elseif(${VAL} MATCHES "[dD]")
SET(${VAR} 13) set(${VAR} 13)
elseif(${VAL} MATCHES "[eE]") elseif(${VAL} MATCHES "[eE]")
SET(${VAR} 14) set(${VAR} 14)
elseif(${VAL} MATCHES "[fF]") elseif(${VAL} MATCHES "[fF]")
SET(${VAR} 15) set(${VAR} 15)
else() else()
MESSAGE(FATAL_ERROR "Invalid format for hexidecimal character") message(FATAL_ERROR "Invalid format for hexidecimal character")
endif() endif()
endmacro(HEXCHAR2DEC) endmacro()
macro(HEX2DEC VAR VAL) macro(HEX2DEC VAR VAL)
SET(CURINDEX 0) set(CURINDEX 0)
STRING(LENGTH "${VAL}" CURLENGTH) string(LENGTH "${VAL}" CURLENGTH)
SET(${VAR} 0) set(${VAR} 0)
while(CURINDEX LESS CURLENGTH) while(CURINDEX LESS CURLENGTH)
STRING(SUBSTRING "${VAL}" ${CURINDEX} 1 CHAR) string(SUBSTRING "${VAL}" ${CURINDEX} 1 CHAR)
HEXCHAR2DEC(CHAR ${CHAR}) HEXCHAR2DEC(CHAR ${CHAR})
MATH(EXPR POWAH "(1<<((${CURLENGTH}-${CURINDEX}-1)*4))") math(EXPR POWAH "(1 << ((${CURLENGTH} - ${CURINDEX} - 1) * 4))")
MATH(EXPR CHAR "(${CHAR}*${POWAH})") math(EXPR CHAR "(${CHAR} * ${POWAH})")
MATH(EXPR ${VAR} "${${VAR}}+${CHAR}") math(EXPR ${VAR} "${${VAR}} + ${CHAR}")
MATH(EXPR CURINDEX "${CURINDEX}+1") math(EXPR CURINDEX "${CURINDEX} + 1")
endwhile() endwhile()
endmacro(HEX2DEC) endmacro()
macro(SET_VERSION MAJOR MINOR FILE) macro(SET_VERSION MAJOR MINOR FILE)
set(ROLLBACK 3) set(ROLLBACK 3)
@@ -43,13 +42,22 @@ macro(SET_VERSION MAJOR MINOR FILE)
HEX2DEC(ver_minor ${ver_minor}) HEX2DEC(ver_minor ${ver_minor})
message(STATUS "Found version:\t\t ${ver_major}.${ver_minor}") message(STATUS "Found version:\t\t ${ver_major}.${ver_minor}")
if(PICO_PLATFORM) if(PICO_PLATFORM)
if (PICO_RP2350 AND SECURE_BOOT_PKEY) if(PICO_RP2350 AND SECURE_BOOT_PKEY)
message(STATUS "Setting rollback version:\t ${ROLLBACK}") message(STATUS "Setting rollback version:\t ${ROLLBACK}")
pico_set_binary_version(${CMAKE_PROJECT_NAME} MAJOR ${ver_major} MINOR ${ver_minor} ROLLBACK ${ROLLBACK}) pico_set_binary_version(
${CMAKE_PROJECT_NAME}
MAJOR ${ver_major}
MINOR ${ver_minor}
ROLLBACK ${ROLLBACK}
)
else() else()
pico_set_binary_version(${CMAKE_PROJECT_NAME} MAJOR ${ver_major} MINOR ${ver_minor}) pico_set_binary_version(
${CMAKE_PROJECT_NAME}
MAJOR ${ver_major}
MINOR ${ver_minor}
)
endif() endif()
endif() endif()
set(${MAJOR} ${ver_major}) set(${MAJOR} ${ver_major})
set(${MINOR} ${ver_minor}) set(${MINOR} ${ver_minor})
endmacro(SET_VERSION) endmacro()

View File

@@ -1,7 +1,39 @@
set(PICO_KEYS_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..) set(PICO_KEYS_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
set(PICO_KEYS_INCLUDE_DIRS
${PICO_KEYS_SDK_DIR}/src
${PICO_KEYS_SDK_DIR}/src/fs
${PICO_KEYS_SDK_DIR}/src/rng
${PICO_KEYS_SDK_DIR}/src/usb
${PICO_KEYS_SDK_DIR}/src/led
${PICO_KEYS_SDK_DIR}/tinycbor/src
)
set(PICO_KEYS_REQUIRES
bootloader_support
esp_partition
esp_tinyusb
efuse
mbedtls
tinycbor
)
if(ENABLE_PQC)
list(APPEND PICO_KEYS_INCLUDE_DIRS
${PICO_KEYS_SDK_DIR}/mlkem/mlkem
${PICO_KEYS_SDK_DIR}/config/mlkem
)
list(APPEND PICO_KEYS_REQUIRES
mlkem512
mlkem768
mlkem1024
)
endif()
idf_component_register( idf_component_register(
SRCS ${PICO_KEYS_SOURCES} SRCS ${PICO_KEYS_SOURCES}
INCLUDE_DIRS ${PICO_KEYS_SDK_DIR}/src ${PICO_KEYS_SDK_DIR}/src/fs ${PICO_KEYS_SDK_DIR}/src/rng ${PICO_KEYS_SDK_DIR}/src/usb ${PICO_KEYS_SDK_DIR}/src/led ${PICO_KEYS_SDK_DIR}/tinycbor/src ${PICO_KEYS_SDK_DIR}/mlkem/mlkem ${PICO_KEYS_SDK_DIR}/config/mlkem INCLUDE_DIRS ${PICO_KEYS_INCLUDE_DIRS}
REQUIRES bootloader_support esp_partition esp_tinyusb efuse mbedtls mlkem512 mlkem768 mlkem1024 tinycbor REQUIRES ${PICO_KEYS_REQUIRES}
) )
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)

View File

@@ -1,6 +1,8 @@
set(PICO_KEYS_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..) set(PICO_KEYS_SDK_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../..)
idf_component_register( idf_component_register(
SRCS ${CBOR_SOURCES} SRCS ${CBOR_SOURCES}
INCLUDE_DIRS ${PICO_KEYS_SDK_DIR}/tinycbor/src INCLUDE_DIRS ${PICO_KEYS_SDK_DIR}/tinycbor/src
) )
idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON) idf_component_set_property(${COMPONENT_NAME} WHOLE_ARCHIVE ON)

View File

@@ -16,6 +16,7 @@
# #
include(pico-keys-sdk/cmake/version.cmake OPTIONAL) include(pico-keys-sdk/cmake/version.cmake OPTIONAL)
include(pico-keys-sdk/cmake/options.cmake OPTIONAL)
option(VIDPID "Set specific VID/PID from a known platform {NitroHSM, NitroFIDO2, NitroStart, NitroPro, Nitro3, Yubikey5, YubikeyNeo, YubiHSM, Gnuk, GnuPG}" "None") option(VIDPID "Set specific VID/PID from a known platform {NitroHSM, NitroFIDO2, NitroStart, NitroPro, Nitro3, Yubikey5, YubikeyNeo, YubiHSM, Gnuk, GnuPG}" "None")
@@ -33,7 +34,6 @@ elseif(VIDPID STREQUAL "NitroStart")
elseif(VIDPID STREQUAL "NitroPro") elseif(VIDPID STREQUAL "NitroPro")
set(USB_VID 0x20A0) set(USB_VID 0x20A0)
set(USB_PID 0x4108) set(USB_PID 0x4108)
elseif(VIDPID STREQUAL "Nitro3") elseif(VIDPID STREQUAL "Nitro3")
set(USB_VID 0x20A0) set(USB_VID 0x20A0)
set(USB_PID 0x42B2) set(USB_PID 0x42B2)
@@ -66,12 +66,12 @@ endif()
if(NOT DEFINED USB_VID) if(NOT DEFINED USB_VID)
set(USB_VID 0x2E8A) set(USB_VID 0x2E8A)
endif() endif()
add_definitions(-DUSB_VID=${USB_VID}) add_compile_definitions(USB_VID=${USB_VID})
if(NOT DEFINED USB_PID) if(NOT DEFINED USB_PID)
set(USB_PID 0x10FD) set(USB_PID 0x10FD)
endif() endif()
add_definitions(-DUSB_PID=${USB_PID}) add_compile_definitions(USB_PID=${USB_PID})
if(NOT DEFINED DEBUG_APDU) if(NOT DEFINED DEBUG_APDU)
set(DEBUG_APDU 0) set(DEBUG_APDU 0)
@@ -82,29 +82,32 @@ endif()
include(${CMAKE_CURRENT_LIST_DIR}/cmake/openssl.cmake) include(${CMAKE_CURRENT_LIST_DIR}/cmake/openssl.cmake)
option(ENABLE_DELAYED_BOOT "Enable/disable delayed boot" OFF) option(ENABLE_DELAYED_BOOT "Enable/disable delayed boot" OFF)
configure_bool_option(
ENABLE_DELAYED_BOOT
""
"Delayed boot:\t\t enabled"
"Delayed boot:\t\t disabled"
)
if(ENABLE_DELAYED_BOOT) if(ENABLE_DELAYED_BOOT)
add_definitions(-DPICO_XOSC_STARTUP_DELAY_MULTIPLIER=64) add_compile_definitions(PICO_XOSC_STARTUP_DELAY_MULTIPLIER=64)
message(STATUS "Delayed boot:\t\t enabled") endif()
else()
message(STATUS "Delayed boot:\t\t disabled")
endif(ENABLE_DELAYED_BOOT)
if(USB_ITF_HID) if(USB_ITF_HID)
add_definitions(-DUSB_ITF_HID=1) add_compile_definitions(USB_ITF_HID=1)
message(STATUS "USB HID Interface:\t\t enabled") message(STATUS "USB HID Interface:\t\t enabled")
endif(USB_ITF_HID) endif()
if(USB_ITF_CCID) if(USB_ITF_CCID)
add_definitions(-DUSB_ITF_CCID=1) add_compile_definitions(USB_ITF_CCID=1)
message(STATUS "USB CCID Interface:\t\t enabled") message(STATUS "USB CCID Interface:\t\t enabled")
if(USB_ITF_WCID) if(USB_ITF_WCID)
add_definitions(-DUSB_ITF_WCID=1) add_compile_definitions(USB_ITF_WCID=1)
message(STATUS "USB WebCCID Interface:\t enabled") message(STATUS "USB WebCCID Interface:\t enabled")
endif(USB_ITF_WCID) endif()
endif(USB_ITF_CCID) endif()
add_definitions(-DDEBUG_APDU=${DEBUG_APDU}) add_compile_definitions(DEBUG_APDU=${DEBUG_APDU})
if(NOT ESP_PLATFORM) if(NOT ESP_PLATFORM)
add_definitions(-DMBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/config/mbedtls_config.h") add_compile_definitions(MBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/config/mbedtls_config.h")
else() else()
add_definitions(-DCFG_TUSB_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/src/usb/tusb_config.h") add_compile_definitions(CFG_TUSB_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/src/usb/tusb_config.h")
endif() endif()
message(STATUS "USB VID/PID:\t\t\t ${USB_VID}:${USB_PID}") message(STATUS "USB VID/PID:\t\t\t ${USB_VID}:${USB_PID}")
@@ -113,11 +116,12 @@ if(NOT ESP_PLATFORM)
set(NEED_UPDATE OFF) set(NEED_UPDATE OFF)
option(ENABLE_EDDSA "Enable/disable EdDSA support" OFF) option(ENABLE_EDDSA "Enable/disable EdDSA support" OFF)
if(ENABLE_EDDSA) configure_bool_option(
message(STATUS "EdDSA support:\t\t enabled") ENABLE_EDDSA
else() ""
message(STATUS "EdDSA support:\t\t disabled") "EdDSA support:\t\t enabled"
endif(ENABLE_EDDSA) "EdDSA support:\t\t disabled"
)
set(MBEDTLS_PATH "${CMAKE_SOURCE_DIR}/pico-keys-sdk/mbedtls") set(MBEDTLS_PATH "${CMAKE_SOURCE_DIR}/pico-keys-sdk/mbedtls")
execute_process( execute_process(
@@ -146,7 +150,12 @@ if(NOT ESP_PLATFORM)
set(NEED_UPDATE OFF) set(NEED_UPDATE OFF)
endif() endif()
add_definitions(-DMBEDTLS_ECP_DP_ED25519_ENABLED=1 -DMBEDTLS_ECP_DP_ED448_ENABLED=1 -DMBEDTLS_EDDSA_C=1 -DMBEDTLS_SHA3_C=1) add_compile_definitions(
MBEDTLS_ECP_DP_ED25519_ENABLED=1
MBEDTLS_ECP_DP_ED448_ENABLED=1
MBEDTLS_EDDSA_C=1
MBEDTLS_SHA3_C=1
)
else() else()
set(MBEDTLS_ORIGIN "https://github.com/Mbed-TLS/mbedtls.git") set(MBEDTLS_ORIGIN "https://github.com/Mbed-TLS/mbedtls.git")
@@ -212,15 +221,18 @@ if(NOT ESP_PLATFORM)
else() else()
message(STATUS "mbedTLS source code is up to date.") message(STATUS "mbedTLS source code is up to date.")
endif() endif()
endif(NOT ESP_PLATFORM) endif()
option(ENABLE_PQC "Enable/disable PQC support" OFF) option(ENABLE_PQC "Enable/disable PQC support" OFF)
configure_bool_option(
ENABLE_PQC
""
"PQC support:\t\t\t enabled"
"PQC support:\t\t\t disabled"
)
if(ENABLE_PQC) if(ENABLE_PQC)
message(STATUS "PQC support:\t\t\t enabled") add_compile_definitions(ENABLE_PQC)
add_definitions(-DENABLE_PQC) endif()
else()
message(STATUS "PQC support:\t\t\t disabled")
endif(ENABLE_PQC)
set(MBEDTLS_SOURCES set(MBEDTLS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aes.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aes.c
@@ -265,62 +277,65 @@ set(MBEDTLS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c
) )
if (ENABLE_EDDSA) if(ENABLE_EDDSA)
set(MBEDTLS_SOURCES ${MBEDTLS_SOURCES} list(APPEND MBEDTLS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/eddsa.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/eddsa.c
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/sha3.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/sha3.c
) )
endif() endif()
if(ENABLE_PQC) if(ENABLE_PQC)
if (NOT ESP_PLATFORM) if(NOT ESP_PLATFORM)
file(GLOB_RECURSE MLKEM_SOURCES file(GLOB_RECURSE MLKEM_SOURCES
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src/*.c ${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src/*.c
) )
list(FILTER MLKEM_SOURCES EXCLUDE REGEX "/native/") list(FILTER MLKEM_SOURCES EXCLUDE REGEX "/native/")
add_library(mlkem512 STATIC ${MLKEM_SOURCES}) add_library(mlkem512 STATIC ${MLKEM_SOURCES})
target_include_directories(mlkem512 PRIVATE target_include_directories(mlkem512 PRIVATE
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src ${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src
${CMAKE_CURRENT_LIST_DIR}/config/mlkem ${CMAKE_CURRENT_LIST_DIR}/config/mlkem
) )
target_compile_definitions(mlkem512 PRIVATE target_compile_definitions(mlkem512 PRIVATE
MLK_CONFIG_PARAMETER_SET=512 MLK_CONFIG_PARAMETER_SET=512
MLK_CONFIG_MULTILEVEL_WITH_SHARED MLK_CONFIG_MULTILEVEL_WITH_SHARED
MLK_CONFIG_NAMESPACE_PREFIX=mlkem MLK_CONFIG_NAMESPACE_PREFIX=mlkem
) )
add_library(mlkem768 STATIC ${MLKEM_SOURCES}) add_library(mlkem768 STATIC ${MLKEM_SOURCES})
target_include_directories(mlkem768 PRIVATE target_include_directories(mlkem768 PRIVATE
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src ${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src
${CMAKE_CURRENT_LIST_DIR}/config/mlkem ${CMAKE_CURRENT_LIST_DIR}/config/mlkem
) )
target_compile_definitions(mlkem768 PRIVATE target_compile_definitions(mlkem768 PRIVATE
MLK_CONFIG_PARAMETER_SET=768 MLK_CONFIG_PARAMETER_SET=768
MLK_CONFIG_MULTILEVEL_NO_SHARED MLK_CONFIG_MULTILEVEL_NO_SHARED
MLK_CONFIG_NAMESPACE_PREFIX=mlkem MLK_CONFIG_NAMESPACE_PREFIX=mlkem
) )
add_library(mlkem1024 STATIC ${MLKEM_SOURCES}) add_library(mlkem1024 STATIC ${MLKEM_SOURCES})
target_include_directories(mlkem1024 PRIVATE target_include_directories(mlkem1024 PRIVATE
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src ${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem/src
${CMAKE_CURRENT_LIST_DIR}/config/mlkem ${CMAKE_CURRENT_LIST_DIR}/config/mlkem
) )
target_compile_definitions(mlkem1024 PRIVATE target_compile_definitions(mlkem1024 PRIVATE
MLK_CONFIG_PARAMETER_SET=1024 MLK_CONFIG_PARAMETER_SET=1024
MLK_CONFIG_MULTILEVEL_NO_SHARED MLK_CONFIG_MULTILEVEL_NO_SHARED
MLK_CONFIG_NAMESPACE_PREFIX=mlkem MLK_CONFIG_NAMESPACE_PREFIX=mlkem
) )
endif() endif()
set(INCLUDES ${INCLUDES} list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem ${CMAKE_CURRENT_LIST_DIR}/mlkem/mlkem
${CMAKE_CURRENT_LIST_DIR}/config/mlkem ${CMAKE_CURRENT_LIST_DIR}/config/mlkem
) )
add_definitions(-DMLK_CONFIG_NAMESPACE_PREFIX=mlkem -DMLK_CONFIG_MULTILEVEL_BUILD=1) add_compile_definitions(
MLK_CONFIG_NAMESPACE_PREFIX=mlkem
MLK_CONFIG_MULTILEVEL_BUILD=1
)
endif() endif()
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/main.c ${CMAKE_CURRENT_LIST_DIR}/src/main.c
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb.c ${CMAKE_CURRENT_LIST_DIR}/src/usb/usb.c
${CMAKE_CURRENT_LIST_DIR}/src/fs/file.c ${CMAKE_CURRENT_LIST_DIR}/src/fs/file.c
@@ -339,19 +354,19 @@ set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES}
) )
if(ESP_PLATFORM) if(ESP_PLATFORM)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/led/led_neopixel.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led_neopixel.c
${CMAKE_CURRENT_LIST_DIR}/src/led/led_pico.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led_pico.c
) )
else() else()
if (NOT ENABLE_EMULATION) if(NOT ENABLE_EMULATION)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/led/led_cyw43.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led_cyw43.c
${CMAKE_CURRENT_LIST_DIR}/src/led/led_pico.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led_pico.c
${CMAKE_CURRENT_LIST_DIR}/src/led/led_pimoroni.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led_pimoroni.c
${CMAKE_CURRENT_LIST_DIR}/src/led/led_ws2812.c ${CMAKE_CURRENT_LIST_DIR}/src/led/led_ws2812.c
) )
endif() endif()
endif() endif()
## mbedTLS reports an stringop overflow for cmac.c ## mbedTLS reports an stringop overflow for cmac.c
@@ -362,7 +377,7 @@ if(NOT ENABLE_EMULATION AND NOT APPLE)
COMPILE_FLAGS "-Wno-error=stringop-overflow= -Wno-stringop-overflow" COMPILE_FLAGS "-Wno-error=stringop-overflow= -Wno-stringop-overflow"
) )
endif() endif()
set(INCLUDES ${INCLUDES} list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/src ${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/src/usb ${CMAKE_CURRENT_LIST_DIR}/src/usb
${CMAKE_CURRENT_LIST_DIR}/src/fs ${CMAKE_CURRENT_LIST_DIR}/src/fs
@@ -373,7 +388,7 @@ set(INCLUDES ${INCLUDES}
) )
if(USB_ITF_HID) if(USB_ITF_HID)
set(MBEDTLS_SOURCES ${MBEDTLS_SOURCES} list(APPEND MBEDTLS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_crt.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_crt.c
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509_create.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509_create.c
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_csr.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/x509write_csr.c
@@ -381,18 +396,18 @@ if(USB_ITF_HID)
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk_wrap.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pk_wrap.c
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/pkwrite.c
) )
endif() endif()
set(CBOR_SOURCES set(CBOR_SOURCES
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborencoder.c ${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborencoder.c
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborparser.c ${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborparser.c
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborparser_dup_string.c ${CMAKE_CURRENT_LIST_DIR}/tinycbor/src/cborparser_dup_string.c
) )
list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src
)
set(INCLUDES ${INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/tinycbor/src
)
set(LIBRARIES) set(LIBRARIES)
if(NOT SKIP_MBEDTLS_FOR_OPENSSL_EMULATION) if(NOT SKIP_MBEDTLS_FOR_OPENSSL_EMULATION)
list(APPEND LIBRARIES mbedtls) list(APPEND LIBRARIES mbedtls)
@@ -409,11 +424,11 @@ if (NOT ESP_PLATFORM)
if(USB_ITF_HID) if(USB_ITF_HID)
add_library(tinycbor STATIC ${CBOR_SOURCES}) add_library(tinycbor STATIC ${CBOR_SOURCES})
target_include_directories(tinycbor PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tinycbor/src) target_include_directories(tinycbor PUBLIC ${CMAKE_CURRENT_LIST_DIR}/tinycbor/src)
set(LIBRARIES ${LIBRARIES} tinycbor) list(APPEND LIBRARIES tinycbor)
endif() endif()
endif() endif()
if (PICO_PLATFORM) if(PICO_PLATFORM)
list(APPEND LIBRARIES list(APPEND LIBRARIES
pico_stdlib pico_stdlib
pico_multicore pico_multicore
@@ -427,7 +442,7 @@ if (PICO_PLATFORM)
) )
endif() endif()
if (ENABLE_PQC) if(ENABLE_PQC)
list(APPEND LIBRARIES list(APPEND LIBRARIES
mlkem512 mlkem512
mlkem768 mlkem768
@@ -436,12 +451,12 @@ if (ENABLE_PQC)
endif() endif()
set(IS_CYW43 0) set(IS_CYW43 0)
if (PICO_PLATFORM) if(PICO_PLATFORM)
file(READ ${PICO_SDK_PATH}/src/boards/include/boards/${PICO_BOARD}.h content) file(READ ${PICO_SDK_PATH}/src/boards/include/boards/${PICO_BOARD}.h content)
string(REGEX MATCHALL "CYW43_WL_GPIO_LED_PIN" _ ${content}) string(REGEX MATCHALL "CYW43_WL_GPIO_LED_PIN" _ ${content})
if (CMAKE_MATCH_0) if(CMAKE_MATCH_0)
message(STATUS "Found cyw43 LED:\t\t true") message(STATUS "Found cyw43 LED:\t\t true")
set(LIBRARIES ${LIBRARIES} pico_cyw43_arch_none) list(APPEND LIBRARIES pico_cyw43_arch_none)
set(IS_CYW43 1) set(IS_CYW43 1)
endif() endif()
endif() endif()
@@ -453,28 +468,28 @@ function(add_impl_library target)
endfunction() endfunction()
if(USB_ITF_HID) if(USB_ITF_HID)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/usb/hid/hid.c ${CMAKE_CURRENT_LIST_DIR}/src/usb/hid/hid.c
) )
set(INCLUDES ${INCLUDES} list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/src/usb/hid ${CMAKE_CURRENT_LIST_DIR}/src/usb/hid
) )
endif() endif()
if(USB_ITF_CCID) if(USB_ITF_CCID)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/usb/ccid/ccid.c ${CMAKE_CURRENT_LIST_DIR}/src/usb/ccid/ccid.c
) )
set(INCLUDES ${INCLUDES} list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/src/usb/ccid ${CMAKE_CURRENT_LIST_DIR}/src/usb/ccid
) )
endif() endif()
if(NOT MSVC) if(NOT MSVC)
add_definitions("-fmacro-prefix-map=${CMAKE_CURRENT_LIST_DIR}/=") add_compile_options("-fmacro-prefix-map=${CMAKE_CURRENT_LIST_DIR}/=")
endif() endif()
if(MSVC) if(MSVC)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/fs/mman.c ${CMAKE_CURRENT_LIST_DIR}/src/fs/mman.c
) )
endif() endif()
@@ -482,23 +497,23 @@ if(ENABLE_EMULATION)
if(APPLE) if(APPLE)
add_definitions("-Wno-deprecated-declarations") add_definitions("-Wno-deprecated-declarations")
endif() endif()
add_definitions(-DENABLE_EMULATION) add_compile_definitions(ENABLE_EMULATION)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation/emulation.c ${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation/emulation.c
) )
if(USE_OPENSSL_EMULATION_WRAPPER) if(USE_OPENSSL_EMULATION_WRAPPER)
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation/openssl.c ${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation/openssl.c
) )
endif() endif()
set(MBEDTLS_SOURCES ${MBEDTLS_SOURCES} list(APPEND MBEDTLS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aesni.c ${CMAKE_CURRENT_LIST_DIR}/mbedtls/library/aesni.c
) )
set(INCLUDES ${INCLUDES} list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation ${CMAKE_CURRENT_LIST_DIR}/src/usb/emulation
) )
else() else()
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb_descriptors.c ${CMAKE_CURRENT_LIST_DIR}/src/usb/usb_descriptors.c
) )
endif() endif()
@@ -509,7 +524,8 @@ if(MSVC)
"${CMAKE_C_FLAGS} -wd4820 -wd4255 -wd5045 -wd4706 -wd4061 -wd5105 -wd4141 -wd4200" "${CMAKE_C_FLAGS} -wd4820 -wd4255 -wd5045 -wd4706 -wd4061 -wd5105 -wd4141 -wd4200"
) )
add_compile_definitions(_CRT_SECURE_NO_WARNINGS add_compile_definitions(
_CRT_SECURE_NO_WARNINGS
__STDC_WANT_SECURE_LIB__=0 __STDC_WANT_SECURE_LIB__=0
_WIN32_WINNT_WIN10_TH2=0 _WIN32_WINNT_WIN10_TH2=0
_WIN32_WINNT_WIN10_RS1=0 _WIN32_WINNT_WIN10_RS1=0
@@ -518,27 +534,28 @@ if(MSVC)
_WIN32_WINNT_WIN10_RS4=0 _WIN32_WINNT_WIN10_RS4=0
_WIN32_WINNT_WIN10_RS5=0 _WIN32_WINNT_WIN10_RS5=0
_STRALIGN_USE_SECURE_CRT=0 _STRALIGN_USE_SECURE_CRT=0
NTDDI_WIN11_DT=0) NTDDI_WIN11_DT=0
)
endif() endif()
if(PICO_PLATFORM) if(PICO_PLATFORM)
pico_sdk_init() pico_sdk_init()
endif() endif()
if(PICO_RP2350) if(PICO_RP2350)
pico_set_uf2_family(${CMAKE_PROJECT_NAME} "rp2350-arm-s") pico_set_uf2_family(${CMAKE_PROJECT_NAME} "rp2350-arm-s")
pico_embed_pt_in_binary(${CMAKE_PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/config/rp2350/pt.json") pico_embed_pt_in_binary(${CMAKE_PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/config/rp2350/pt.json")
if (NOT IS_CYW43) if(NOT IS_CYW43)
pico_set_binary_type(${CMAKE_PROJECT_NAME} copy_to_ram) pico_set_binary_type(${CMAKE_PROJECT_NAME} copy_to_ram)
endif() endif()
if (SECURE_BOOT_PKEY) if(SECURE_BOOT_PKEY)
message(STATUS "Secure Boot Key ${SECURE_BOOT_PKEY}") message(STATUS "Secure Boot Key ${SECURE_BOOT_PKEY}")
pico_sign_binary(${CMAKE_PROJECT_NAME} ${SECURE_BOOT_PKEY}) pico_sign_binary(${CMAKE_PROJECT_NAME} ${SECURE_BOOT_PKEY})
pico_hash_binary(${CMAKE_PROJECT_NAME}) pico_hash_binary(${CMAKE_PROJECT_NAME})
endif() endif()
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE pico_bootrom) target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE pico_bootrom)
set(INCLUDES ${INCLUDES} list(APPEND INCLUDES
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt ${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt
) )
if(TARGET mbedtls) if(TARGET mbedtls)
@@ -547,11 +564,11 @@ if(PICO_RP2350)
) )
target_link_libraries(mbedtls PRIVATE pico_sha256) target_link_libraries(mbedtls PRIVATE pico_sha256)
endif() endif()
set(PICO_KEYS_SOURCES ${PICO_KEYS_SOURCES} list(APPEND PICO_KEYS_SOURCES
${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt/sha256_alt.c ${CMAKE_CURRENT_LIST_DIR}/config/rp2350/alt/sha256_alt.c
) )
add_definitions(-DMBEDTLS_SHA256_ALT=1) add_compile_definitions(MBEDTLS_SHA256_ALT=1)
set(LIBRARIES ${LIBRARIES} pico_sha256) list(APPEND LIBRARIES pico_sha256)
endif() endif()
set(INTERNAL_SOURCES ${PICO_KEYS_SOURCES}) set(INTERNAL_SOURCES ${PICO_KEYS_SOURCES})