Fix PSA target, fix create_distro to not recurse into static libraries

pull/15339/head
Jamie Smith 2022-05-28 23:28:28 -07:00 committed by Jay Sridharan
parent fe23ff8d5b
commit 5bddbbc980
6 changed files with 57 additions and 50 deletions

View File

@ -265,7 +265,7 @@ add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
if(NOT MBED_IS_NATIVE_BUILD)
# Create a distro for the microcontroller cmake target, ensuring its sources are only compiled once
mbed_create_distro(${MBED_TARGET_CMAKE_NAME}-obj ${MBED_TARGET_CMAKE_NAME} mbed-core-flags)
mbed_create_distro(${MBED_TARGET_CMAKE_NAME}-lib ${MBED_TARGET_CMAKE_NAME} mbed-core-flags)
# Core Mbed OS libraries
# mbed-baremetal contains baremetal sources + target sources + target compile flags.
@ -276,8 +276,8 @@ if(NOT MBED_IS_NATIVE_BUILD)
mbed_create_distro(mbed-os mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
# Now make the Mbed OS code depend on the target, ensuring everything has access to the uC's flags and objects.
target_link_libraries(mbed-baremetal PUBLIC ${MBED_TARGET_CMAKE_NAME}-obj)
target_link_libraries(mbed-os PUBLIC ${MBED_TARGET_CMAKE_NAME}-obj)
target_link_libraries(mbed-baremetal PUBLIC ${MBED_TARGET_CMAKE_NAME}-lib)
target_link_libraries(mbed-os PUBLIC ${MBED_TARGET_CMAKE_NAME}-lib)
endif()
# Ninja requires to be forced for response files

View File

@ -12,7 +12,7 @@ if("TFM" IN_LIST MBED_TARGET_LABELS)
endif()
target_include_directories(mbed-psa
INTERFACE
PUBLIC
inc
inc/psa
)
@ -22,5 +22,6 @@ target_sources(mbed-psa
src/psa_hrng.c
)
# For now, on devices with PSA, PSA functions are used by the HAL so PSA needs to be included in the core Mbed build.
target_link_libraries(mbed-core-flags INTERFACE mbed-psa)
# Make sure that mbed-psa can include headers from Mbed OS and the target
# Must be private so that we do not commit to a baremetal or OS choice
target_link_libraries(mbed-psa PRIVATE mbed-core-flags ${MBED_TARGET_CMAKE_NAME}-lib)

View File

@ -2,7 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
target_include_directories(mbed-psa
INTERFACE
PUBLIC
inc
inc/psa
mbedtls
@ -19,7 +19,7 @@ target_include_directories(mbed-psa
)
target_sources(mbed-psa
INTERFACE
PRIVATE
mbedtls/psa_crypto.c
mbedtls/psa_crypto_se.c
mbedtls/psa_crypto_driver_wrappers.c
@ -63,7 +63,7 @@ target_sources(mbed-psa
)
target_link_libraries(mbed-psa
INTERFACE
PUBLIC
mbed-mbedtls
mbed-storage-kvstore
mbed-storage-tdbstore

View File

@ -3,7 +3,7 @@
if("TFM_DUALCPU" IN_LIST MBED_TARGET_LABELS)
target_sources(mbed-psa
INTERFACE
PRIVATE
TARGET_TFM_DUALCPU/src/platform_multicore.c
TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c
TARGET_TFM_DUALCPU/src/tfm_mbed_boot.c
@ -15,7 +15,7 @@ endif()
if("TFM_V8M" IN_LIST MBED_TARGET_LABELS)
target_sources(mbed-psa
INTERFACE
PRIVATE
TARGET_TFM_V8M/src/cmsis_nvic_virtual.c
TARGET_TFM_V8M/src/tfm_mbed_boot.c
TARGET_TFM_V8M/src/tfm_psa_ns_api.c
@ -23,14 +23,14 @@ if("TFM_V8M" IN_LIST MBED_TARGET_LABELS)
endif()
target_include_directories(mbed-psa
INTERFACE
PUBLIC
include
include/psa
include/psa_manifest
)
target_sources(mbed-psa
INTERFACE
PRIVATE
src/os_wrapper_cmsis_rtos_v2.c
src/tfm_crypto_ipc_api.c
src/tfm_firmware_update_ipc_api.c

View File

@ -3,7 +3,7 @@
if("TFM_DUALCPU" IN_LIST MBED_TARGET_LABELS)
target_sources(mbed-psa
INTERFACE
PRIVATE
TARGET_TFM_DUALCPU/src/platform_multicore.c
TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c
TARGET_TFM_DUALCPU/src/tfm_mbed_boot.c
@ -15,7 +15,7 @@ endif()
if("TFM_V8M" IN_LIST MBED_TARGET_LABELS)
target_sources(mbed-psa
INTERFACE
PRIVATE
TARGET_TFM_V8M/src/cmsis_nvic_virtual.c
TARGET_TFM_V8M/src/tfm_mbed_boot.c
TARGET_TFM_V8M/src/tfm_ns_interface.c
@ -31,7 +31,7 @@ target_include_directories(mbed-psa
)
target_sources(mbed-psa
INTERFACE
PRIVATE
src/tfm_crypto_ipc_api.c
src/tfm_initial_attestation_ipc_api.c
src/tfm_its_ipc_api.c

View File

@ -44,50 +44,56 @@ function(mbed_create_distro NAME) # ARGN: modules...
#message("Distro: ${NAME}. REMAINING_MODULES: ${REMAINING_MODULES}")
list(GET REMAINING_MODULES 0 CURR_MODULE)
copy_append_property(INTERFACE_COMPILE_DEFINITIONS ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_COMPILE_OPTIONS ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME})
list(REMOVE_AT REMAINING_MODULES 0)
# Make sure that linking to the distro pulls in the compiled code from CURR_MODULE
target_link_libraries(${NAME} PRIVATE ${CURR_MODULE})
# CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries
# via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/.
# see: https://cmake.org/pipermail/cmake/2019-May/069453.html
# also: https://gitlab.kitware.com/cmake/cmake/-/issues/18090
get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE)
if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY")
target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:${CURR_MODULE}>)
# Check if this object library has any other libraries exported through its INTERFACE_SOURCES.
# If it does, we need to propagate those too.
get_property(OBJ_INTERFACE_SOURCES TARGET ${NAME} PROPERTY INTERFACE_SOURCES)
foreach(INTERFACE_SOURCE ${OBJ_INTERFACE_SOURCES})
if(INTERFACE_SOURCE MATCHES "\\$<TARGET_OBJECTS:.*>")
target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE})
if("${CURR_MODULE_TYPE}" STREQUAL "STATIC_LIBRARY")
# Don't need to do anything other than linking it
else()
copy_append_property(INTERFACE_COMPILE_DEFINITIONS ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_COMPILE_OPTIONS ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME})
copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME})
# CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries
# via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/.
# see: https://cmake.org/pipermail/cmake/2019-May/069453.html
# also: https://gitlab.kitware.com/cmake/cmake/-/issues/18090
if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY")
target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:${CURR_MODULE}>)
# Check if this object library has any other libraries exported through its INTERFACE_SOURCES.
# If it does, we need to propagate those too.
get_property(OBJ_INTERFACE_SOURCES TARGET ${NAME} PROPERTY INTERFACE_SOURCES)
foreach(INTERFACE_SOURCE ${OBJ_INTERFACE_SOURCES})
if(INTERFACE_SOURCE MATCHES "\\$<TARGET_OBJECTS:.*>")
target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE})
endif()
endforeach()
endif()
list(APPEND COMPLETED_MODULES ${CURR_MODULE})
# find sub-modules of this module
get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES)
foreach(SUBMODULE ${SUBMODULES})
if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers
# Remove LINK_ONLY genexes from target_link_libraries(... PRIVATE). We can ignore things wrapped in these
# because they will already have been handled by the target_link_libraries earlier on.
if(NOT "${SUBMODULE}" MATCHES "\\$<LINK_ONLY:.*>")
if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES)
list(APPEND REMAINING_MODULES ${SUBMODULE})
endif()
endif()
endif()
endforeach()
endif()
list(REMOVE_AT REMAINING_MODULES 0)
list(APPEND COMPLETED_MODULES ${CURR_MODULE})
# find sub-modules of this module
get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES)
foreach(SUBMODULE ${SUBMODULES})
if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers
# Remove LINK_ONLY genexes from target_link_libraries(... PRIVATE). We can ignore things wrapped in these
# because they will already have been handled by the target_link_libraries earlier on.
if(NOT "${SUBMODULE}" MATCHES "\\$<LINK_ONLY:.*>")
if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES)
list(APPEND REMAINING_MODULES ${SUBMODULE})
endif()
endif()
endif()
endforeach()
endwhile()
endfunction(mbed_create_distro)