ghs: fix the gnu-elf.ld handle error at pre-process

In Green Hills, if the name of the file to be preprocessed ends with ".ld",
this file must be renamed to ".ld.i". Otherwise, the following error will be reported:

ccarm: Error: -o out/build/cmake_out/mann_dcu_evb_ghs_ap/gnu-elf.ld has wrong suffix for -P option (expect .i)

Currently, based on the documentation and actual operations, only files
ending with "*.ld" can trigger this preprocessing error. There are no such
issues in other cases.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
guoshichao 2025-03-26 15:48:51 +08:00 committed by Xiang Xiao
parent 1d8eab937f
commit cda60ceab3

View file

@ -219,12 +219,31 @@ function(nuttx_generate_preprocess_target)
ARGN
${ARGN})
# in greenhills, for file to pre-process, if the file name is ends with
# "*.ld", will report error, and we need to change the target file name to
# "*.ld.i" or "*.ld.tmp", this is a special corner case, and the official
# greenhills reference manual do not have explanation about why the only
# "*.ld" should handle
set(EXPECT_TARGET_FILE_NAME ${TARGET_FILE})
string(REGEX MATCH ".*\.ld$" ends_with_ld ${TARGET_FILE})
if(ends_with_ld STREQUAL ${TARGET_FILE})
set(EXPECT_TARGET_FILE_NAME "${TARGET_FILE}.i")
endif()
add_custom_command(
OUTPUT ${TARGET_FILE}
OUTPUT ${EXPECT_TARGET_FILE_NAME}
COMMAND ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include -filetype.cpp
${SOURCE_FILE} -o ${TARGET_FILE}
${SOURCE_FILE} -o ${EXPECT_TARGET_FILE_NAME}
DEPENDS ${SOURCE_FILE} ${DEPENDS})
if(NOT ${EXPECT_TARGET_FILE_NAME} STREQUAL ${TARGET_FILE})
add_custom_command(
OUTPUT ${TARGET_FILE}
COMMAND ${CMAKE_COMMAND} -E copy ${EXPECT_TARGET_FILE_NAME} ${TARGET_FILE}
DEPENDS ${EXPECT_TARGET_FILE_NAME})
endif()
endfunction()
# override nuttx_find_toolchain_lib