From 89826e8f47ba22092cc0282fe24862626a73c18f Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 4 Dec 2018 10:47:00 +1100 Subject: [PATCH] generic cmake: Always use gc-sections when linking IDF libraries Required for some IDF binary libraries Reported on forum: https://esp32.com/viewtopic.php?f=13&t=7535&p=34863#p34852 TW27733 --- tools/cmake/idf_functions.cmake | 5 ++++- tools/cmake/project.cmake | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/cmake/idf_functions.cmake b/tools/cmake/idf_functions.cmake index 5cf0f18dd..65d696a2f 100644 --- a/tools/cmake/idf_functions.cmake +++ b/tools/cmake/idf_functions.cmake @@ -246,6 +246,9 @@ function(idf_link_components target components) endforeach() if(libraries) + # gc-sections is necessary for linking some IDF binary libraries + # (and without it, IDF apps are much larger than they should be) + target_link_libraries(${target} "-Wl,--gc-sections") target_link_libraries(${target} "-Wl,--start-group") target_link_libraries(${target} ${libraries}) message(STATUS "Component libraries: ${IDF_COMPONENT_LIBRARIES}") @@ -258,4 +261,4 @@ endfunction() function(idf_import_components var idf_path build_path) add_subdirectory(${idf_path} ${build_path}) set(${var} ${BUILD_COMPONENTS} PARENT_SCOPE) -endfunction() \ No newline at end of file +endfunction() diff --git a/tools/cmake/project.cmake b/tools/cmake/project.cmake index 04459a1e8..679023e48 100644 --- a/tools/cmake/project.cmake +++ b/tools/cmake/project.cmake @@ -102,8 +102,7 @@ macro(project name) set(mapfile "${CMAKE_PROJECT_NAME}.map") - target_link_libraries(${IDF_PROJECT_EXECUTABLE} "-Wl,--gc-sections \ - -Wl,--cref -Wl,--Map=${mapfile}") + target_link_libraries(${IDF_PROJECT_EXECUTABLE} "-Wl,--cref -Wl,--Map=${mapfile}") set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES