Beautify cmake files.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2026-03-07 13:30:47 +01:00
parent d8ccf9bd28
commit ab3ddf4e23
2 changed files with 165 additions and 122 deletions

View File

@@ -1,19 +1,19 @@
# #
# This file is part of the Pico FIDO distribution (https://github.com/polhenarejos/pico-fido). # This file is part of the Pico FIDO distribution (https://github.com/polhenarejos/pico-fido).
# 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.13) cmake_minimum_required(VERSION 3.13)
@@ -21,51 +21,64 @@ set(USB_VID 0x2E8A)
set(USB_PID 0x10FE) set(USB_PID 0x10FE)
if(ESP_PLATFORM) if(ESP_PLATFORM)
set(DENABLE_POWER_ON_RESET 0) if(NOT DEFINED ENABLE_POWER_ON_RESET)
set(EXTRA_COMPONENT_DIRS pico-keys-sdk/config/esp32/components src/fido) set(ENABLE_POWER_ON_RESET 0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) endif()
if(NOT DEFINED ENABLE_PQC)
set(ENABLE_PQC 0)
endif()
set(EXTRA_COMPONENT_DIRS
src/fido
pico-keys-sdk/config/esp32/components/pico-keys-sdk
pico-keys-sdk/config/esp32/components/tinycbor
)
if(ENABLE_PQC)
list(APPEND EXTRA_COMPONENT_DIRS
pico-keys-sdk/config/esp32/components/mlkem512
pico-keys-sdk/config/esp32/components/mlkem768
pico-keys-sdk/config/esp32/components/mlkem1024
)
endif()
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
else() else()
if(NOT ENABLE_EMULATION)
set(PICO_USE_FASTEST_SUPPORTED_CLOCK 1)
include(pico_sdk_import.cmake)
endif()
if(ENABLE_EMULATION) project(pico_fido C CXX ASM)
else()
set(PICO_USE_FASTEST_SUPPORTED_CLOCK 1) set(CMAKE_C_STANDARD 11)
include(pico_sdk_import.cmake) set(CMAKE_CXX_STANDARD 17)
add_executable(pico_fido)
endif() endif()
project(pico_fido C CXX ASM) include(pico-keys-sdk/cmake/options.cmake)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
add_executable(pico_fido)
endif()
option(ENABLE_POWER_ON_RESET "Enable/disable power cycle on reset" ON) option(ENABLE_POWER_ON_RESET "Enable/disable power cycle on reset" ON)
if(ENABLE_POWER_ON_RESET) configure_bool_option(
add_definitions(-DENABLE_POWER_ON_RESET=1) ENABLE_POWER_ON_RESET
message(STATUS "Power cycle on reset: \t enabled") ENABLE_POWER_ON_RESET
else() "Power cycle on reset: \t enabled"
add_definitions(-DENABLE_POWER_ON_RESET=0) "Power cycle on reset: \t disabled"
message(STATUS "Power cycle on reset: \t disabled") )
endif(ENABLE_POWER_ON_RESET)
option(ENABLE_OATH_APP "Enable/disable OATH application" ON) option(ENABLE_OATH_APP "Enable/disable OATH application" ON)
if(ENABLE_OATH_APP) configure_bool_option(
add_definitions(-DENABLE_OATH_APP=1) ENABLE_OATH_APP
message(STATUS "OATH Application: \t\t enabled") ENABLE_OATH_APP
else() "OATH Application: \t\t enabled"
add_definitions(-DENABLE_OATH_APP=0) "OATH Application: \t\t disabled"
message(STATUS "OATH Application: \t\t disabled") )
endif(ENABLE_OATH_APP)
option(ENABLE_OTP_APP "Enable/disable OTP application" ON) option(ENABLE_OTP_APP "Enable/disable OTP application" ON)
if(ENABLE_OTP_APP) configure_bool_option(
add_definitions(-DENABLE_OTP_APP=1) ENABLE_OTP_APP
message(STATUS "OTP Application: \t\t enabled") ENABLE_OTP_APP
else() "OTP Application: \t\t enabled"
add_definitions(-DENABLE_OTP_APP=0) "OTP Application: \t\t disabled"
message(STATUS "OTP Application: \t\t disabled") )
endif(ENABLE_OTP_APP)
if(ENABLE_OTP_APP OR ENABLE_OATH_APP) if(ENABLE_OTP_APP OR ENABLE_OATH_APP)
set(USB_ITF_CCID 1) set(USB_ITF_CCID 1)
@@ -81,92 +94,122 @@ 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/fido/fido.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/fido.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/files.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/files.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/kek.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/kek.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cmd_register.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cmd_register.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cmd_authenticate.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cmd_authenticate.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cmd_version.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cmd_version.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_reset.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_reset.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_get_info.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_get_info.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_make_credential.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_make_credential.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/known_apps.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/known_apps.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_client_pin.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_client_pin.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/credential.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/credential.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_get_assertion.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_get_assertion.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_selection.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_selection.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_cred_mgmt.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_cred_mgmt.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_config.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_config.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_vendor.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_vendor.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_large_blobs.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/cbor_large_blobs.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/management.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/management.c
${CMAKE_CURRENT_LIST_DIR}/src/fido/defs.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/defs.c
) )
if (${ENABLE_OATH_APP})
set(SOURCES ${SOURCES} if(ENABLE_OATH_APP)
list(APPEND SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/fido/oath.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/oath.c
) )
endif() endif()
if (${ENABLE_OTP_APP})
set(SOURCES ${SOURCES} if(ENABLE_OTP_APP)
list(APPEND SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/fido/otp.c ${CMAKE_CURRENT_LIST_DIR}/src/fido/otp.c
) )
endif() endif()
SET_VERSION(ver_major ver_minor "${CMAKE_CURRENT_LIST_DIR}/src/fido/version.h" 3) SET_VERSION(ver_major ver_minor "${CMAKE_CURRENT_LIST_DIR}/src/fido/version.h" 3)
if(ESP_PLATFORM) if(ESP_PLATFORM)
project(pico_fido) project(pico_fido)
endif() endif()
set(INCLUDES ${INCLUDES} set(INCLUDES ${INCLUDES}
${CMAKE_CURRENT_LIST_DIR}/src/fido ${CMAKE_CURRENT_LIST_DIR}/src/fido
) )
if(NOT ESP_PLATFORM) if(NOT ESP_PLATFORM)
target_sources(pico_fido PUBLIC ${SOURCES}) target_sources(pico_fido PUBLIC ${SOURCES})
target_include_directories(pico_fido PUBLIC ${INCLUDES}) target_include_directories(pico_fido PUBLIC ${INCLUDES})
target_compile_options(pico_fido PUBLIC set(COMMON_COMPILE_OPTIONS
-Wall -Wall
)
if (NOT MSVC)
target_compile_options(pico_fido PUBLIC
-Werror
) )
target_compile_options(pico_fido PRIVATE ${COMMON_COMPILE_OPTIONS})
string(FIND ${CMAKE_C_COMPILER} ":" COMPILER_COLON)
if (${COMPILER_COLON} GREATER_EQUAL 0)
target_compile_options(pico_fido PUBLIC
-Wno-error=use-after-free
)
endif()
endif(NOT MSVC)
if(ENABLE_EMULATION)
if(NOT MSVC) if(NOT MSVC)
target_compile_options(pico_fido PUBLIC set(NON_MSVC_COMPILE_OPTIONS
-fdata-sections -Werror
-ffunction-sections )
target_compile_options(pico_fido PRIVATE ${NON_MSVC_COMPILE_OPTIONS})
string(FIND ${CMAKE_C_COMPILER} ":" COMPILER_COLON)
if(${COMPILER_COLON} GREATER_EQUAL 0)
target_compile_options(pico_fido PRIVATE
-Wno-error=use-after-free
) )
endif(NOT MSVC)
if(APPLE)
target_link_options(pico_fido PUBLIC
-Wl,-dead_strip
)
if(DEBUG_APDU)
target_compile_options(pico_fido PUBLIC
-fsanitize=address -g -O1 -fno-omit-frame-pointer)
target_link_options(pico_fido PUBLIC
-fsanitize=address -g -O1 -fno-omit-frame-pointer)
endif() endif()
else() endif()
target_link_options(pico_fido PUBLIC
-Wl,--gc-sections if(ENABLE_EMULATION)
if(NOT MSVC)
set(EMULATION_NON_MSVC_COMPILE_OPTIONS
-fdata-sections
-ffunction-sections
) )
endif (APPLE) target_compile_options(pico_fido PRIVATE ${EMULATION_NON_MSVC_COMPILE_OPTIONS})
target_link_libraries(pico_fido PRIVATE pico_keys_sdk mbedtls pthread m) endif()
else()
target_link_libraries(pico_fido PRIVATE pico_keys_sdk pico_stdlib pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id pico_aon_timer tinyusb_device tinyusb_board) if(APPLE)
pico_add_extra_outputs(${CMAKE_PROJECT_NAME}) set(EMULATION_APPLE_LINK_OPTIONS
endif() -Wl,-dead_strip
)
target_link_options(pico_fido PRIVATE ${EMULATION_APPLE_LINK_OPTIONS})
if(DEBUG_APDU)
set(DEBUG_APDU_SANITIZER_OPTIONS
-fsanitize=address
-g
-O1
-fno-omit-frame-pointer
)
target_compile_options(pico_fido PRIVATE ${DEBUG_APDU_SANITIZER_OPTIONS})
target_link_options(pico_fido PRIVATE ${DEBUG_APDU_SANITIZER_OPTIONS})
endif()
else()
set(EMULATION_NON_APPLE_LINK_OPTIONS
-Wl,--gc-sections
)
target_link_options(pico_fido PRIVATE ${EMULATION_NON_APPLE_LINK_OPTIONS})
endif()
target_link_libraries(pico_fido PRIVATE pico_keys_sdk mbedtls pthread m)
else()
target_link_libraries(
pico_fido
PRIVATE
pico_keys_sdk
pico_stdlib
pico_multicore
hardware_flash
hardware_sync
hardware_adc
pico_unique_id
pico_aon_timer
tinyusb_device
tinyusb_board
)
pico_add_extra_outputs(${CMAKE_PROJECT_NAME})
endif()
endif() endif()