simplify the complicated removal of dependency sources

add hex file generation
pull/5476/head
Matthias L. Jugel 2017-11-18 11:10:48 +01:00
parent 6f667e5ca2
commit c29945b1be
2 changed files with 14 additions and 10 deletions

View File

@ -30,7 +30,7 @@ SET(CMAKE_CXX_FLAGS "{{cxx_flags}} -include mbed_config.h")
SET(CMAKE_ASM_FLAGS "{{asm_flags}} -include mbed_config.h") SET(CMAKE_ASM_FLAGS "{{asm_flags}} -include mbed_config.h")
SET(CMAKE_CXX_LINK_FLAGS "{{ld_flags}}") SET(CMAKE_CXX_LINK_FLAGS "{{ld_flags}}")
{% if pp -%} {% if pp -%}
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_INK_FLAGS} {{link_script_option}} ${CMAKE_BINARY_DIR}/{{name}}.link_script.ld ${LD_SYS_LIBS}") SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${LD_SYS_LIBS} {{link_script_option}} ${CMAKE_BINARY_DIR}/{{name}}.link_script.ld")
{%- endif %} {%- endif %}
ADD_DEFINITIONS( ADD_DEFINITIONS(
@ -48,21 +48,26 @@ ADD_LIBRARY({{libname}} STATIC
{% endfor %} {% endfor %}
# executable {{name}} # executable {{name}}
ADD_EXECUTABLE({{name}}.elf ADD_EXECUTABLE({{name}}
{% for src in sources %}{{src}} {% for src in sources %}{{src}}
{% endfor %}) {% endfor %})
TARGET_LINK_LIBRARIES({{name}}.elf TARGET_LINK_LIBRARIES({{name}}
{% for libname in dependencies %}{{libname}} {% for libname in dependencies.keys()|sort(reverse=true) %}{{libname}}
{% endfor %}) {% endfor %})
{% if pp -%} {% if pp -%}
add_custom_command(TARGET {{name}}.elf PRE_LINK add_custom_command(TARGET {{name}} PRE_LINK
COMMAND "{{pp}}" {{pp_flags}} {{linker_script}} -o ${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld COMMAND "{{pp}}" {{pp_flags}} {{linker_script}} -o ${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld" BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld"
) )
{%- endif %} {%- endif %}
add_custom_command(TARGET {{name}} POST_BUILD
COMMAND ${ELF2BIN} -O ihex $<TARGET_FILE:{{name}}> $<TARGET_FILE:{{name}}>.hex
)
########################################################################## ##########################################################################
# mbed-cli specific targets # mbed-cli specific targets
########################################################################## ##########################################################################

View File

@ -73,10 +73,9 @@ class CMake(Exporter):
depSources = {k: v for k, v in depSources.items() if len(v) != 0} depSources = {k: v for k, v in depSources.items() if len(v) != 0}
# remove all source files that ended up being part of one of the dependencies # remove all source files that ended up being part of one of the dependencies
# we flatten the list of source files from all dependencies and srcs = allSourceFiles
# then only add file to srcs if its not in that list for dep in depSources.values():
# (basically srcs = allSourcefiles - flatten(depSources.values()) srcs.difference_update(dep)
srcs = [f for f in allSourceFiles if f not in [item for sublist in depSources.values() for item in sublist]]
# additional libraries # additional libraries
libraries = [self.prepare_lib(basename(lib)) for lib in self.resources.libraries] libraries = [self.prepare_lib(basename(lib)) for lib in self.resources.libraries]
@ -85,7 +84,7 @@ class CMake(Exporter):
ctx = { ctx = {
'name': self.project_name, 'name': self.project_name,
'target': self.target, 'target': self.target,
'sources': srcs, 'sources': sorted(srcs),
'dependencies': depSources, 'dependencies': depSources,
'libraries': libraries, 'libraries': libraries,
'ld_sys_libs': sys_libs, 'ld_sys_libs': sys_libs,