test for IDF version >= 3.3 with macro

phatpaul
Posts: 66
Joined: Fri Aug 24, 2018 1:14 pm

test for IDF version >= 3.3 with macro

Postby phatpaul » Wed Jan 08, 2020 10:01 pm

I would like to add a feature to a library that depends on IDF version 3.3 or greater, but would fail to compile with earlier.
I need it to compile either way, just not including the new feature if not available.

I see that IDF version 4 added this capability: https://docs.espressif.com/projects/esp ... -version-h

Code: Select all

#include "esp_idf_version.h"

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
    // enable functionality present in IDF v4.0
#endif
But that check fails to compile on 3.3 and 3.1! So what good is it?

I can get IDF_VER macro in (seems generated in makefile) but it is a long string. "v3.3.1-53-gc5e37c707-dirty"
Can I reasonably use that to determine compatibility?

ESP_Angus
Posts: 2183
Joined: Sun May 08, 2016 4:11 am

Re: test for IDF version >= 3.3 with macro

Postby ESP_Angus » Thu Jan 09, 2020 3:05 am

Hi paul,

You're right that the idf_version.h header file is only available in ESP-IDF v4.0 and newer. (You can use the gcc extension has_include() to test if this header exists as a way of knowing if you're using an earlier ESP-IDF version, but this doesn't help if you support v3.3.)

If your component only supports 3.3 or newer then you can add a file to component_dir/Makefile.projbuild (same directory that contains component.mk), like this:

Code: Select all

$(if $(filter-out v3.3% v4.%,$(IDF_VER)), $(error "This component only supports ESP-IDF v3.3.x or v4.x, not $(IDF_VER)"))
This will error the build if the version doesn't match one of the patterns shown.

If you also support CMake, a similar check can be done in the component CMakeLists.txt file. (CMake has version comparison functionality like VERSION_GREATER).

phatpaul
Posts: 66
Joined: Fri Aug 24, 2018 1:14 pm

Re: test for IDF version >= 3.3 with macro

Postby phatpaul » Thu Jan 16, 2020 4:14 pm

OK, it makes sense to use the makefile for this. I'm grateful for your expert guidance.
Thank you Angus.
-Paul

Who is online

Users browsing this forum: Google [Bot] and 40 guests