diff --git a/connectivity/drivers/wifi/CMakeLists.txt b/connectivity/drivers/wifi/CMakeLists.txt
index 7def3aa1b7f..3aad8050176 100644
--- a/connectivity/drivers/wifi/CMakeLists.txt
+++ b/connectivity/drivers/wifi/CMakeLists.txt
@@ -14,6 +14,35 @@ macro(create_mbed_wifi_target)
endif()
endmacro()
+# Collect sources which need to extract from static library to override
+# weak symbols. Their paths are required to relative to this directory
+# ,so that they match with entries in static library and their corresponding
+# object files there can be found and extracted.
+set(MBED_WIFI_OVERRIDE_SOURCES "" CACHE INTERNAL "" FORCE)
+
+# Add override sources by subdirectories
+#
+# The input sources are required to relative to their subdirectories
+# and will get converted to relative to this directory herein.
+function(mbed_wifi_add_override_sources)
+ set(override_sources ${MBED_WIFI_OVERRIDE_SOURCES})
+
+ foreach(override_source ${ARGN})
+ # Convert to relative to this directory
+ file(RELATIVE_PATH
+ override_source_fix
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
+ ${CMAKE_CURRENT_LIST_DIR}/${override_source}
+ )
+
+ set(override_sources
+ ${override_sources}
+ ${override_source_fix}
+ )
+ endforeach()
+
+ set(MBED_WIFI_OVERRIDE_SOURCES ${override_sources} CACHE INTERNAL "" FORCE)
+endfunction()
# The WICED subdirectory is for wifi drivers developed using Infineon WICED framework.
# https://community.infineon.com/t5/Knowledge-Base-Articles/WICED-Wi-Fi-FAQ/ta-p/247356
@@ -39,3 +68,57 @@ if("COMPONENT_ESPRESSIF_ESP8266=1" IN_LIST MBED_TARGET_DEFINITIONS)
add_subdirectory(COMPONENT_ESPRESSIF_ESP8266)
endif()
+# Extract override objects from static library and pass them to
+# link options to actively participate in linking and override weak
+# symbols.
+if(TARGET mbed-wifi AND NOT "${MBED_WIFI_OVERRIDE_SOURCES}" STREQUAL "")
+ set(override_sources ${MBED_WIFI_OVERRIDE_SOURCES})
+ list(TRANSFORM override_sources APPEND ${CMAKE_CXX_OUTPUT_EXTENSION} OUTPUT_VARIABLE override_objects)
+
+ if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
+ # Override objects passed via target_link_options are finally
+ # de-duplicated, so we can avoid multiple definition issue caused
+ # due to cyclic target link via target_link_libraries.
+ #
+ # https://cmake.org/cmake/help/latest/command/target_link_options.html#option-de-duplication
+ target_link_options(mbed-wifi
+ INTERFACE
+ $
+ )
+
+ # Commands for extracting override objects
+ foreach(override_object ${override_objects})
+ get_filename_component(override_object_dirname ${override_object} DIRECTORY)
+
+ # Extract object files from static library
+ #
+ # NOTE: The support has restrictions on input static library:
+ # 1. No full path match modifier ('P') is specified on creating
+ # the static library.
+ # 2. Object file names must be different for just one-level entry
+ # names in the static library.
+ # https://sourceware.org/binutils/docs/binutils/ar-cmdline.html
+ set(extract_commands
+ ${extract_commands}
+ COMMAND
+ ${CMAKE_COMMAND} -E make_directory ${override_object_dirname}
+ COMMAND
+ ${CMAKE_AR} x --output ${override_object_dirname} $ ${override_object}
+ )
+ endforeach()
+
+ add_custom_command(
+ TARGET
+ mbed-wifi
+ POST_BUILD
+ ${extract_commands}
+ WORKING_DIRECTORY
+ ${CMAKE_CURRENT_BINARY_DIR}
+ VERBATIM
+ )
+ endif()
+
+ unset(override_sources)
+ unset(override_objects)
+ unset(extract_commands)
+endif()
diff --git a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt
index 682139f0e84..c17940232dc 100644
--- a/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt
+++ b/connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt
@@ -12,3 +12,10 @@ target_include_directories(mbed-wifi
.
./ESP8266
)
+
+# Add sources which contain override symbols
+if("MBED_CONF_ESP8266_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS)
+ mbed_wifi_add_override_sources(
+ ESP8266Interface.cpp
+ )
+endif()
diff --git a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt
index a91dc52b119..ae4a1bb1d09 100644
--- a/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt
+++ b/connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt
@@ -21,3 +21,10 @@ target_sources(mbed-wifi
mx_wifi/core/mx_wifi_ipc.c
mx_wifi/core/mx_wifi_slip.c
)
+
+# Add sources which contain override symbols
+if("MBED_CONF_EMW3080B_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS)
+ mbed_wifi_add_override_sources(
+ EMW3080BInterface.cpp
+ )
+endif()