]> granicus.if.org Git - esp-idf/commitdiff
generic cmake: Always use gc-sections when linking IDF libraries
authorAngus Gratton <angus@espressif.com>
Mon, 3 Dec 2018 23:47:00 +0000 (10:47 +1100)
committerAngus Gratton <gus@projectgus.com>
Mon, 3 Dec 2018 23:47:00 +0000 (10:47 +1100)
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
tools/cmake/project.cmake

index 5cf0f18ddd312224f0906c5c30e852f942af9b60..65d696a2f4ae799a68a5132092d5e3f8192cd408 100644 (file)
@@ -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()
index 04459a1e83bab5a039efb9cc4635cda0d0d11b99..679023e4896577300cc0e01272d44ad509de4f2a 100644 (file)
@@ -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