cmake: support pre-processor for linker script

This commit is contained in:
raiden00pl 2023-07-12 17:43:40 +02:00 committed by Xiang Xiao
parent 3bdba79851
commit a59f82b8d2
2 changed files with 33 additions and 7 deletions

View File

@ -250,6 +250,15 @@ else()
file(TOUCH ${CMAKE_BINARY_DIR}/drivers/platform/Kconfig)
endif()
# board common directory
if(CONFIG_ARCH_BOARD_COMMON)
file(
GLOB NUTTX_COMMON_DIR
LIST_DIRECTORIES true
"${NUTTX_DIR}/boards/${CONFIG_ARCH}/${CONFIG_ARCH_CHIP}/common")
endif()
# Custom chip ###################################################
if(CONFIG_ARCH_CHIP_CUSTOM)
@ -521,6 +530,28 @@ endif()
# Get linker script to use
get_property(ldscript GLOBAL PROPERTY LD_SCRIPT)
# Pre-compile linker script
if(DEFINED PREPROCES)
get_filename_component(LD_SCRIPT_NAME ${ldscript} NAME)
set(LD_SCRIPT_TMP "${CMAKE_BINARY_DIR}/${LD_SCRIPT_NAME}.tmp")
add_custom_command(
OUTPUT ${LD_SCRIPT_TMP}
DEPENDS ${ldscript}
COMMAND
${PREPROCES}
-I${CMAKE_BINARY_DIR}/include
-I${NUTTX_CHIP_ABS_DIR}
${ldscript} > ${LD_SCRIPT_TMP}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_custom_target(ldscript_tmp DEPENDS ${LD_SCRIPT_TMP})
add_dependencies(nuttx ldscript_tmp)
set(ldscript ${LD_SCRIPT_TMP})
endif()
# Perform link
# Add empty source file to nuttx target since cmake requires at least one file
@ -703,10 +734,3 @@ if(NOT CONFIG_BUILD_FLAT)
# TODO: could also merge elf binaries
endif()
if(CONFIG_ARCH_BOARD_COMMON)
file(
GLOB NUTTX_COMMON_DIR
LIST_DIRECTORIES true
"${NUTTX_DIR}/boards/${CONFIG_ARCH}/${CONFIG_ARCH_CHIP}/common")
endif()

View File

@ -101,3 +101,5 @@ if(CONFIG_ARCH_COVERAGE)
endif()
set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${EXTRA_LIB})
set(PREPROCES ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -E -P -x c)