Skip to content

Commit

Permalink
feat: add linker config to model file
Browse files Browse the repository at this point in the history
  • Loading branch information
xxthunder committed Apr 30, 2024
1 parent 614b5a1 commit eb06294
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 27 deletions.
50 changes: 50 additions & 0 deletions KConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
menu "SPL Core"
menu "Linking"
config LINKER_OUTPUT_FILE
string "LINKER_OUTPUT_FILE"
default "link_out.elf"
help
The main output file generated by the linker (e.g. main.exe or main.elf).

config LINKER_BYPRODUCTS_CONFIG
bool "LINKER_BYPRODUCTS_CONFIG"
default n
help
Enable to configure other byproduct files generated by the linker

config LINKER_BYPRODUCTS_EXTENSIONS
string "LINKER_BYPRODUCTS_EXTENSIONS"
depends on !LINKER_BYPRODUCTS_CONFIG
default "hex,map,mdf"
help
The extensions of other byproducts generated by the linker (comma separated list, e.g., "hex,map,mdf")

config LINKER_BYPRODUCT_HEX
string "LINKER_BYPRODUCT_HEX"
depends on LINKER_BYPRODUCTS_CONFIG
default "link_out.hex"
help
The hex file generated by the linker

config LINKER_BYPRODUCT_MAP
string "LINKER_BYPRODUCT_MAP"
depends on LINKER_BYPRODUCTS_CONFIG
default "link_out.map"
help
The map file generated by the linker

config LINKER_BYPRODUCT_MDF
string "LINKER_BYPRODUCT_MDF"
depends on LINKER_BYPRODUCTS_CONFIG
default "link_out.mdf"
help
The mdf file generated by the linker

config LINKER_BYPRODUCT_OTHERS
string "LINKER_BYPRODUCT_OTHERS"
depends on LINKER_BYPRODUCTS_CONFIG
default ""
help
Other byproduct files generated by the linker (comma separated list, e.g., "link_out.xml")
endmenu
endmenu
21 changes: 20 additions & 1 deletion cmake/spl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,33 @@ if(BUILD_KIT STREQUAL prod)
# combine basename and byproduct extension
string(REPLACE "," ";" LINKER_BYPRODUCTS "${LINKER_BYPRODUCTS_EXTENSIONS}")
list(TRANSFORM LINKER_BYPRODUCTS PREPEND ${LINK_FILE_BASENAME}.)
endif(LINKER_BYPRODUCTS_EXTENSIONS)

if(LINKER_BYPRODUCT_HEX)
list(APPEND LINKER_BYPRODUCTS ${LINKER_BYPRODUCT_HEX})
endif(LINKER_BYPRODUCT_HEX)

if(LINKER_BYPRODUCT_MAP)
list(APPEND LINKER_BYPRODUCTS ${LINKER_BYPRODUCT_MAP})
endif(LINKER_BYPRODUCT_MAP)

if(LINKER_BYPRODUCT_MDF)
list(APPEND LINKER_BYPRODUCTS ${LINKER_BYPRODUCT_MDF})
endif(LINKER_BYPRODUCT_MDF)

if(LINKER_BYPRODUCT_OTHERS)
string(REPLACE "," ";" LINKER_BYPRODUCTS_TMP "${LINKER_BYPRODUCT_OTHERS}")
list(APPEND LINKER_BYPRODUCTS ${LINKER_BYPRODUCTS_TMP})
endif(LINKER_BYPRODUCT_OTHERS)

if(LINKER_BYPRODUCTS)
add_custom_target(
linker_byproducts ALL
COMMAND ${CMAKE_COMMAND} -E true
DEPENDS ${LINKER_OUTPUT_FILE}
BYPRODUCTS ${LINKER_BYPRODUCTS}
)
endif(LINKER_BYPRODUCTS_EXTENSIONS)
endif(LINKER_BYPRODUCTS)
endif(LINKER_OUTPUT_FILE)
elseif(BUILD_KIT STREQUAL test)
_spl_get_google_test()
Expand Down
62 changes: 36 additions & 26 deletions tests/cmake/spl.cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
include(../spl_test.cmake)

# mocks
spl_test_create_mock(add_executable)
spl_test_create_mock(target_compile_options)
spl_test_create_mock(set_target_properties)

# given
cmake_minimum_required(VERSION 3.22.0)
project(test C ASM)

set(VARIANT mytestvariant)
set(BUILD_KIT prod)
set(LINKER_OUTPUT_FILE main.exe)

# when
include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/spl.cmake)

# expect
if(NOT LINK_TARGET_NAME STREQUAL "link")
message(FATAL_ERROR "Failing Test case: LINK_TARGET_NAME = ${LINK_TARGET_NAME}.")
endif()

spl_test_expect_is_called(add_executable 1)
spl_test_expect_is_called(target_compile_options 1)
spl_test_expect_is_called(set_target_properties 1)
include(../spl_test.cmake)

# mocks
spl_test_create_mock(add_executable)
spl_test_create_mock(target_compile_options)
spl_test_create_mock(set_target_properties)

# given
cmake_minimum_required(VERSION 3.22.0)
project(test C ASM)

set(VARIANT mytestvariant)
set(BUILD_KIT prod)
set(LINKER_OUTPUT_FILE main.exe)
set(LINKER_BYPRODUCTS_EXTENSIONS "hex")
set(LINKER_BYPRODUCT_HEX bibi.hex tina.map amadeus.mdf)

# when
include(${CMAKE_CURRENT_LIST_DIR}/../../../cmake/spl.cmake)

# expect
if(NOT LINK_TARGET_NAME STREQUAL "link")
message(FATAL_ERROR "Failing Test case: LINK_TARGET_NAME = ${LINK_TARGET_NAME}.")
endif()

if(NOT LINK_FILE_BASENAME STREQUAL "main")
message(FATAL_ERROR "Failing Test case: LINK_FILE_BASENAME = ${LINK_FILE_BASENAME}.")
endif()

if(NOT LINKER_BYPRODUCTS STREQUAL "main.hex;bibi.hex;tina.map;amadeus.mdf")
message(FATAL_ERROR "Failing Test case: LINKER_BYPRODUCTS = ${LINKER_BYPRODUCTS}.")
endif()

spl_test_expect_is_called(add_executable 1)
spl_test_expect_is_called(target_compile_options 1)
spl_test_expect_is_called(set_target_properties 1)

0 comments on commit eb06294

Please sign in to comment.