chore: Use CMake way for linker options (#4396)

Co-authored-by: Richard Li <richard.li@ces.hk>
This commit is contained in:
Raphael Coeffic
2023-12-14 09:12:31 +10:00
committed by GitHub
co-authored by Richard Li
parent f10e5e879f
commit 42e245b1da
8 changed files with 76 additions and 43 deletions
+36 -28
View File
@@ -500,33 +500,14 @@ set(COMMON_FLAGS "${COMMON_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS} -Wimplicit")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -fno-rtti")
# these are in addition to CMAKE_CXX_FLAGS
set(LINKER_DIR ${RADIO_SRC_DIR}/boards/generic_stm32/linker)
set(CMAKE_EXE_LINKER_FLAGS "-lm -T${LINKER_DIR}/firmware.ld -L${LINKER_DIR} -L${LINKER_DIR}/${TARGET_LINKER_DIR}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=firmware.map,--cref,--no-warn-mismatch,--gc-sections")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TARGET_LINKER_PARAMS}")
if(SEMIHOSTING)
add_definitions(-DSEMIHOSTING)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=rdimon.specs")
endif()
# Use newlib nano, which saves a few kilobytes.
if(NOT NANO STREQUAL NO)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nano.specs")
if(LUA)
# Lua needs %g and %f
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -u _printf_float -u _scanf_float")
endif()
if(SDRAM)
# Target with SDRAM do not need a custom allocator for now
# as the custom allocator has alignement issues
message("Target has SDRAM, do not use BIN_ALLOCATOR")
else()
# Nano's malloc does work well with lua, use our own
add_definitions(-DUSE_BIN_ALLOCATOR)
set(SRC ${SRC} bin_allocator.cpp)
endif()
if(SDRAM)
# Target with SDRAM do not need a custom allocator for now
# as the custom allocator has alignement issues
message("Target has SDRAM, do not use BIN_ALLOCATOR")
else()
# Nano's malloc does work well with lua, use our own
add_definitions(-DUSE_BIN_ALLOCATOR)
set(SRC ${SRC} bin_allocator.cpp)
endif()
# Bootloader
@@ -543,13 +524,40 @@ link_libraries(firmware -lstdc++)
add_dependencies(firmware ${RADIO_DEPENDENCIES})
set_target_properties(firmware PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_options(firmware PRIVATE
-lm -T${LINKER_DIR}/firmware.ld
-Wl,-Map=firmware.map,--cref,--no-warn-mismatch,--gc-sections
--specs=nano.specs
)
if (DEFINED TARGET_FLASH_SIZE)
message("TARGET_FLASH_SIZE = ${TARGET_FLASH_SIZE}")
# message("TARGET_FLASH_SIZE = ${TARGET_FLASH_SIZE}")
target_link_options(firmware PRIVATE
-Wl,--defsym=__flash_size=${TARGET_FLASH_SIZE}
)
endif()
if (DEFINED TARGET_SDRAM_START)
# message("TARGET_SDRAM_START = ${TARGET_SDRAM_START}")
target_link_options(firmware PRIVATE
-Wl,--defsym=__sdram_start=${TARGET_SDRAM_START}
)
endif()
if (DEFINED TARGET_SDRAM_SIZE)
# message("TARGET_SDRAM_SIZE = ${TARGET_SDRAM_SIZE}")
target_link_options(firmware PRIVATE
-Wl,--defsym=__sdram_size=${TARGET_SDRAM_SIZE}
)
endif()
if (LUA)
# Lua needs %g and %f
target_link_options(firmware PRIVATE
"SHELL:-u _printf_float" "SHELL:-u _scanf_float"
)
endif()
if(ACCESS_DENIED)
add_subdirectory(thirdparty/AccessDenied)
include_directories(thirdparty/AccessDenied)