@@ -16,6 +16,35 @@ target_link_libraries(mbed-wifi
1616)
1717
1818
19+ # Collect sources which need to extract from static library to override
20+ # weak symbols. Their paths are required to relative to this directory
21+ # ,so that they match with entries in static library and their corresponding
22+ # object files there can be found and extracted.
23+ set (MBED_WIFI_OVERRIDE_SOURCES "" CACHE INTERNAL "" FORCE)
24+
25+ # Add override sources by subdirectories
26+ #
27+ # The input sources are required to relative to their subdirectories
28+ # and will get converted to relative to this directory herein.
29+ function (mbed_wifi_add_override_sources)
30+ set (override_sources ${MBED_WIFI_OVERRIDE_SOURCES} )
31+
32+ foreach (override_source ${ARGN} )
33+ # Convert to relative to this directory
34+ file (RELATIVE_PATH
35+ override_source_fix
36+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
37+ ${CMAKE_CURRENT_LIST_DIR} /${override_source}
38+ )
39+
40+ set (override_sources
41+ ${override_sources}
42+ ${override_source_fix}
43+ )
44+ endforeach ()
45+
46+ set (MBED_WIFI_OVERRIDE_SOURCES ${override_sources} CACHE INTERNAL "" FORCE)
47+ endfunction ()
1948
2049# The WICED subdirectory is for wifi drivers developed using Infineon WICED framework.
2150# https://community.infineon.com/t5/Knowledge-Base-Articles/WICED-Wi-Fi-FAQ/ta-p/247356
@@ -35,3 +64,57 @@ if("COMPONENT_ESPRESSIF_ESP8266=1" IN_LIST MBED_TARGET_DEFINITIONS)
3564 add_subdirectory (COMPONENT_ESPRESSIF_ESP8266)
3665endif ()
3766
67+ # Extract override objects from static library and pass them to
68+ # link options to actively participate in linking and override weak
69+ # symbols.
70+ if (TARGET mbed-wifi AND NOT "${MBED_WIFI_OVERRIDE_SOURCES} " STREQUAL "" )
71+ set (override_sources ${MBED_WIFI_OVERRIDE_SOURCES} )
72+ list (TRANSFORM override_sources APPEND ${CMAKE_CXX_OUTPUT_EXTENSION} OUTPUT_VARIABLE override_objects)
73+
74+ if (${MBED_TOOLCHAIN} STREQUAL "GCC_ARM" )
75+ # Override objects passed via target_link_options are finally
76+ # de-duplicated, so we can avoid multiple definition issue caused
77+ # due to cyclic target link via target_link_libraries.
78+ #
79+ # https://cmake.org/cmake/help/latest/command/target_link_options.html#option-de-duplication
80+ target_link_options (mbed-wifi
81+ INTERFACE
82+ $<LIST:TRANSFORM,${override_objects} ,PREPEND,${CMAKE_CURRENT_BINARY_DIR} />
83+ )
84+
85+ # Commands for extracting override objects
86+ foreach (override_object ${override_objects} )
87+ get_filename_component (override_object_dirname ${override_object} DIRECTORY )
88+
89+ # Extract object files from static library
90+ #
91+ # NOTE: The support has restrictions on input static library:
92+ # 1. No full path match modifier ('P') is specified on creating
93+ # the static library.
94+ # 2. Object file names must be different for just one-level entry
95+ # names in the static library.
96+ # https://sourceware.org/binutils/docs/binutils/ar-cmdline.html
97+ set (extract_commands
98+ ${extract_commands}
99+ COMMAND
100+ ${CMAKE_COMMAND} -E make_directory ${override_object_dirname}
101+ COMMAND
102+ ${CMAKE_AR} x --output ${override_object_dirname} $<TARGET_FILE_NAME:mbed-wifi> ${override_object}
103+ )
104+ endforeach ()
105+
106+ add_custom_command (
107+ TARGET
108+ mbed-wifi
109+ POST_BUILD
110+ ${extract_commands}
111+ WORKING_DIRECTORY
112+ ${CMAKE_CURRENT_BINARY_DIR}
113+ VERBATIM
114+ )
115+ endif ()
116+
117+ unset (override_sources)
118+ unset (override_objects)
119+ unset (extract_commands)
120+ endif ()
0 commit comments