Skip to content

Commit c29945b

Browse files
committed
simplify the complicated removal of dependency sources
add hex file generation
1 parent 6f667e5 commit c29945b

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

tools/export/cmake/CMakeLists.txt.tmpl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ SET(CMAKE_CXX_FLAGS "{{cxx_flags}} -include mbed_config.h")
3030
SET(CMAKE_ASM_FLAGS "{{asm_flags}} -include mbed_config.h")
3131
SET(CMAKE_CXX_LINK_FLAGS "{{ld_flags}}")
3232
{% if pp -%}
33-
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_INK_FLAGS} {{link_script_option}} ${CMAKE_BINARY_DIR}/{{name}}.link_script.ld ${LD_SYS_LIBS}")
33+
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${LD_SYS_LIBS} {{link_script_option}} ${CMAKE_BINARY_DIR}/{{name}}.link_script.ld")
3434
{%- endif %}
3535

3636
ADD_DEFINITIONS(
@@ -48,21 +48,26 @@ ADD_LIBRARY({{libname}} STATIC
4848
{% endfor %}
4949

5050
# executable {{name}}
51-
ADD_EXECUTABLE({{name}}.elf
51+
ADD_EXECUTABLE({{name}}
5252
{% for src in sources %}{{src}}
5353
{% endfor %})
54-
TARGET_LINK_LIBRARIES({{name}}.elf
55-
{% for libname in dependencies %}{{libname}}
54+
TARGET_LINK_LIBRARIES({{name}}
55+
{% for libname in dependencies.keys()|sort(reverse=true) %}{{libname}}
5656
{% endfor %})
5757

5858
{% if pp -%}
59-
add_custom_command(TARGET {{name}}.elf PRE_LINK
59+
add_custom_command(TARGET {{name}} PRE_LINK
6060
COMMAND "{{pp}}" {{pp_flags}} {{linker_script}} -o ${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld
6161
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6262
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld"
6363
)
6464
{%- endif %}
6565

66+
add_custom_command(TARGET {{name}} POST_BUILD
67+
COMMAND ${ELF2BIN} -O ihex $<TARGET_FILE:{{name}}> $<TARGET_FILE:{{name}}>.hex
68+
)
69+
70+
6671
##########################################################################
6772
# mbed-cli specific targets
6873
##########################################################################

tools/export/cmake/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ def generate(self):
7373
depSources = {k: v for k, v in depSources.items() if len(v) != 0}
7474

7575
# remove all source files that ended up being part of one of the dependencies
76-
# we flatten the list of source files from all dependencies and
77-
# then only add file to srcs if its not in that list
78-
# (basically srcs = allSourcefiles - flatten(depSources.values())
79-
srcs = [f for f in allSourceFiles if f not in [item for sublist in depSources.values() for item in sublist]]
76+
srcs = allSourceFiles
77+
for dep in depSources.values():
78+
srcs.difference_update(dep)
8079

8180
# additional libraries
8281
libraries = [self.prepare_lib(basename(lib)) for lib in self.resources.libraries]
@@ -85,7 +84,7 @@ def generate(self):
8584
ctx = {
8685
'name': self.project_name,
8786
'target': self.target,
88-
'sources': srcs,
87+
'sources': sorted(srcs),
8988
'dependencies': depSources,
9089
'libraries': libraries,
9190
'ld_sys_libs': sys_libs,

0 commit comments

Comments
 (0)