From c29945b1be4797d5d3896d8a7fe4efbb080b0a10 Mon Sep 17 00:00:00 2001 From: "Matthias L. Jugel" Date: Sat, 18 Nov 2017 11:10:48 +0100 Subject: [PATCH] simplify the complicated removal of dependency sources add hex file generation --- tools/export/cmake/CMakeLists.txt.tmpl | 15 ++++++++++----- tools/export/cmake/__init__.py | 9 ++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/export/cmake/CMakeLists.txt.tmpl b/tools/export/cmake/CMakeLists.txt.tmpl index 6f0920cadb..236ace8d61 100644 --- a/tools/export/cmake/CMakeLists.txt.tmpl +++ b/tools/export/cmake/CMakeLists.txt.tmpl @@ -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_CXX_LINK_FLAGS "{{ld_flags}}") {% 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 %} ADD_DEFINITIONS( @@ -48,21 +48,26 @@ ADD_LIBRARY({{libname}} STATIC {% endfor %} # executable {{name}} -ADD_EXECUTABLE({{name}}.elf +ADD_EXECUTABLE({{name}} {% for src in sources %}{{src}} {% endfor %}) -TARGET_LINK_LIBRARIES({{name}}.elf - {% for libname in dependencies %}{{libname}} +TARGET_LINK_LIBRARIES({{name}} + {% for libname in dependencies.keys()|sort(reverse=true) %}{{libname}} {% endfor %}) {% 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 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/{{name}}.link_script.ld" ) {%- endif %} +add_custom_command(TARGET {{name}} POST_BUILD + COMMAND ${ELF2BIN} -O ihex $ $.hex + ) + + ########################################################################## # mbed-cli specific targets ########################################################################## diff --git a/tools/export/cmake/__init__.py b/tools/export/cmake/__init__.py index c6dde08e7e..f1bc47b076 100644 --- a/tools/export/cmake/__init__.py +++ b/tools/export/cmake/__init__.py @@ -73,10 +73,9 @@ class CMake(Exporter): 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 - # we flatten the list of source files from all dependencies and - # then only add file to srcs if its not in that list - # (basically srcs = allSourcefiles - flatten(depSources.values()) - srcs = [f for f in allSourceFiles if f not in [item for sublist in depSources.values() for item in sublist]] + srcs = allSourceFiles + for dep in depSources.values(): + srcs.difference_update(dep) # additional libraries libraries = [self.prepare_lib(basename(lib)) for lib in self.resources.libraries] @@ -85,7 +84,7 @@ class CMake(Exporter): ctx = { 'name': self.project_name, 'target': self.target, - 'sources': srcs, + 'sources': sorted(srcs), 'dependencies': depSources, 'libraries': libraries, 'ld_sys_libs': sys_libs,