Hi! Is it possible to depend on a library (in library.json) conditionally? I am working on an ESP32 library that uses the ESP-IDF esp_websocket_client library. That library is included in ESP-IDF 4.y, but in ESP-IDF 5 it was split into a separate IDF component. I would like the build to succeed both on the legacy Espressif32 Arduino framework (with ESP-IDF 4.4.z) and pioarduino (with ESP-IDF 5.y.z). Library.json dependencies allow specifying the platform or a framework but it would seem providing a platform version is not supported.
I wonder would there be any build-time workarounds that would let me define the exact library to include? Unfortunately, the header file names and directories are identical in both cases.
EDIT: The new esp_websocket_client version doesn’t work with ESP-IDF 4.4, so just depending on it unconditionally doesn’t work.
Thanks. I am already using those macros. (For others, to use them, use #include <esp_idf_version.h>, or for ESP_ARDUINO_VERSION*, #include <esp_arduino_version.h>.)
The macros don’t solve my problem, however. Both in ESP-IDF 4.4 and ESP-IDF 5.x, the include is #include <esp_websocket_client.h>, but in the former, you don’t need an external library while in the latter, I need to use the following in library.json:
I didn’t find a way to differentiate between the origins at build time. I could of course solve the issue in the leaf project platformio.ini, but that requires active actions from the library users, and I would prefer making the change transparent if at all possible.
Ah - that line should actually be removed altogether. That pioarduino value was a leftover of one desperate experiment.
For now, I worked around the issue by removing the dependency from the library library.json. There’s a multi-environment platformio.ini that I’ll add to the project template. This approach won’t break anything for existing users but getting the pioarduino or “Arduino as ESP-IDF component” builds to work will be straightforward.