Skip to content

Commit c162a1d

Browse files
committed
Support WiFi as default network interface
This requires support for weak symbol override. Object files arcived in static library don't always participate in linking, dependent on linker and link order. To fix this, the object files which will override weak symbols are extracted and passed to linker command line separately to actively participate in linking.
1 parent e9b09e9 commit c162a1d

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

connectivity/drivers/wifi/CMakeLists.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,35 @@ macro(create_mbed_wifi_target)
1414
endif()
1515
endmacro()
1616

17+
# Collect sources which need to extract from static library to override
18+
# weak symbols. Their paths are required to relative to this directory
19+
# ,so that they match with entries in static library and their corresponding
20+
# object files there can be found and extracted.
21+
set(MBED_WIFI_OVERRIDE_SOURCES "" CACHE INTERNAL "" FORCE)
22+
23+
# Add override sources by subdirectories
24+
#
25+
# The input sources are required to relative to their subdirectories
26+
# and will get converted to relative to this directory herein.
27+
function(mbed_wifi_add_override_sources)
28+
set(override_sources ${MBED_WIFI_OVERRIDE_SOURCES})
29+
30+
foreach(override_source ${ARGN})
31+
# Convert to relative to this directory
32+
file(RELATIVE_PATH
33+
override_source_fix
34+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
35+
${CMAKE_CURRENT_LIST_DIR}/${override_source}
36+
)
37+
38+
set(override_sources
39+
${override_sources}
40+
${override_source_fix}
41+
)
42+
endforeach()
43+
44+
set(MBED_WIFI_OVERRIDE_SOURCES ${override_sources} CACHE INTERNAL "" FORCE)
45+
endfunction()
1746

1847
# The WICED subdirectory is for wifi drivers developed using Infineon WICED framework.
1948
# https://community.infineon.com/t5/Knowledge-Base-Articles/WICED-Wi-Fi-FAQ/ta-p/247356
@@ -36,3 +65,57 @@ if("COMPONENT_ESPRESSIF_ESP8266=1" IN_LIST MBED_TARGET_DEFINITIONS)
3665
add_subdirectory(COMPONENT_ESPRESSIF_ESP8266)
3766
endif()
3867

68+
# Extract override objects from static library and pass them to
69+
# link options to actively participate in linking and override weak
70+
# symbols.
71+
if(TARGET mbed-wifi AND NOT "${MBED_WIFI_OVERRIDE_SOURCES}" STREQUAL "")
72+
set(override_sources ${MBED_WIFI_OVERRIDE_SOURCES})
73+
list(TRANSFORM override_sources APPEND ${CMAKE_CXX_OUTPUT_EXTENSION} OUTPUT_VARIABLE override_objects)
74+
75+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
76+
# Override objects passed via target_link_options are finally
77+
# de-duplicated, so we can avoid multiple definition issue caused
78+
# due to cyclic target link via target_link_libraries.
79+
#
80+
# https://cmake.org/cmake/help/latest/command/target_link_options.html#option-de-duplication
81+
target_link_options(mbed-wifi
82+
INTERFACE
83+
$<LIST:TRANSFORM,${override_objects},PREPEND,${CMAKE_CURRENT_BINARY_DIR}/>
84+
)
85+
86+
# Commands for extracting override objects
87+
foreach(override_object ${override_objects})
88+
get_filename_component(override_object_dirname ${override_object} DIRECTORY)
89+
90+
# Extract object files from static library
91+
#
92+
# NOTE: The support has restrictions on input static library:
93+
# 1. No full path match modifier ('P') is specified on creating
94+
# the static library.
95+
# 2. Object file names must be different for just one-level entry
96+
# names in the static library.
97+
# https://sourceware.org/binutils/docs/binutils/ar-cmdline.html
98+
set(extract_commands
99+
${extract_commands}
100+
COMMAND
101+
${CMAKE_COMMAND} -E make_directory ${override_object_dirname}
102+
COMMAND
103+
${CMAKE_AR} x --output ${override_object_dirname} $<TARGET_FILE_NAME:mbed-wifi> ${override_object}
104+
)
105+
endforeach()
106+
107+
add_custom_command(
108+
TARGET
109+
mbed-wifi
110+
POST_BUILD
111+
${extract_commands}
112+
WORKING_DIRECTORY
113+
${CMAKE_CURRENT_BINARY_DIR}
114+
VERBATIM
115+
)
116+
endif()
117+
118+
unset(override_sources)
119+
unset(override_objects)
120+
unset(extract_commands)
121+
endif()

connectivity/drivers/wifi/COMPONENT_ESPRESSIF_ESP8266/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ target_include_directories(mbed-wifi
1212
.
1313
./ESP8266
1414
)
15+
16+
# Add sources which contain override symbols
17+
if("MBED_CONF_ESP8266_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS)
18+
mbed_wifi_add_override_sources(
19+
ESP8266Interface.cpp
20+
)
21+
endif()

connectivity/drivers/wifi/TARGET_STM/COMPONENT_EMW3080B/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ target_sources(mbed-wifi
2121
mx_wifi/core/mx_wifi_ipc.c
2222
mx_wifi/core/mx_wifi_slip.c
2323
)
24+
25+
# Add sources which contain override symbols
26+
if("MBED_CONF_EMW3080B_PROVIDE_DEFAULT=1" IN_LIST MBED_CONFIG_DEFINITIONS)
27+
mbed_wifi_add_override_sources(
28+
EMW3080BInterface.cpp
29+
)
30+
endif()

0 commit comments

Comments
 (0)