Skip to content

Commit e50592d

Browse files
committed
add optional component dependencies after Kconfig options are known
Until this commit, Kconfig options (e.g. CONFIG_TINYUSB_ENABLED) were used in conditions preceding idf_component_register to determine which components need to be added to `arduino` component requirements. However the Kconfig options aren't known at the early expansion stage, when the component CMakeLists.txt files are expanded the first time and requirements are evaluated. So all the conditions evaluated as if the options were not set. This commit changes the logic to only add these components as dependencies when the Kconfig options are known. Dependencies become "weak", which means that if one of the components isn't included into the build for some reason, it is not added as a dependency. This may happen, for example, if the component is not present in the `components` directory or is excluded by setting `COMPONENTS` variable in the project CMakeLists.txt file. This also ensures that if the component is not present, it will not be added as a dependency, and this will allow the build to proceed. Follow-up to #5391. Closes #5319.
1 parent 8573aab commit e50592d

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

Diff for: CMakeLists.txt

+27-18
Original file line numberDiff line numberDiff line change
@@ -163,26 +163,16 @@ set(priv_includes cores/esp32/libb64)
163163
set(requires spi_flash mbedtls mdns esp_adc_cal wifi_provisioning nghttp)
164164
set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support openssl bt esp_ipc)
165165

166-
if(IDF_TARGET MATCHES "esp32s2|esp32s3" AND CONFIG_TINYUSB_ENABLED)
167-
list(APPEND priv_requires arduino_tinyusb)
168-
endif()
169-
if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_ArduinoOTA)
170-
list(APPEND priv_requires esp_https_ota)
171-
endif()
172-
if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_LITTLEFS)
173-
if(CONFIG_LITTLEFS_PAGE_SIZE)
174-
list(APPEND priv_requires esp_littlefs)
175-
endif()
176-
endif()
177-
178166
idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires})
179167

180-
if(IDF_TARGET STREQUAL "esp32")
181-
target_compile_options(${COMPONENT_TARGET} PUBLIC -DARDUINO=10812 -DARDUINO_ESP32_DEV -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="ESP32_DEV" -DARDUINO_VARIANT="esp32" -DESP32)
182-
endif()
183-
if(IDF_TARGET STREQUAL "esp32s2")
184-
target_compile_options(${COMPONENT_TARGET} PUBLIC -DARDUINO=10812 -DARDUINO_ESP32S2_DEV -DARDUINO_ARCH_ESP32 -DARDUINO_BOARD="ESP32S2_DEV" -DARDUINO_VARIANT="esp32s2" -DESP32)
185-
endif()
168+
string(TOUPPER ${CONFIG_IDF_TARGET} idf_target_caps)
169+
target_compile_options(${COMPONENT_TARGET} PUBLIC
170+
-DARDUINO=10812
171+
-DARDUINO_${idf_target_caps}_DEV
172+
-DARDUINO_ARCH_ESP32
173+
-DARDUINO_BOARD="${idf_target_caps}_DEV"
174+
-DARDUINO_VARIANT="${CONFIG_IDF_TARGET}"
175+
-DESP32)
186176

187177
if(CONFIG_AUTOSTART_ARDUINO)
188178
# in autostart mode, arduino-esp32 contains app_main() function and needs to
@@ -195,3 +185,22 @@ if(CONFIG_AUTOSTART_ARDUINO)
195185
# (As they are C++ symbol, we need to add the C++ mangled names.)
196186
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u _Z5setupv -u _Z4loopv")
197187
endif()
188+
189+
# This function adds a dependency on the given component if the component is included into the build.
190+
function(maybe_add_component component_name)
191+
idf_build_get_property(components BUILD_COMPONENTS)
192+
if (${component_name} IN_LIST components)
193+
idf_component_get_property(lib_name ${component_name} COMPONENT_LIB)
194+
target_link_libraries(${COMPONENT_LIB} PUBLIC ${lib_name})
195+
endif()
196+
endfunction()
197+
198+
if(IDF_TARGET MATCHES "esp32s2|esp32s3" AND CONFIG_TINYUSB_ENABLED)
199+
maybe_add_component(arduino_tinyusb)
200+
endif()
201+
if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_ArduinoOTA)
202+
maybe_add_component(esp_https_ota)
203+
endif()
204+
if(NOT CONFIG_ARDUINO_SELECTIVE_COMPILATION OR CONFIG_ARDUINO_SELECTIVE_LITTLEFS)
205+
maybe_add_component(esp_littlefs)
206+
endif()

0 commit comments

Comments
 (0)