[SOLVED] IDF ver 4.4 & 5 compatibility in CMakeFiles

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

[SOLVED] IDF ver 4.4 & 5 compatibility in CMakeFiles

Postby fasani » Thu Aug 25, 2022 7:33 pm

Dear developers,
Can someone point me to an smart way to keep a CMakeFiles compatible for those who want to build also a project in ESP-IDF v5. But of course keeping backwards compatibility to 4.4 at least. I searched for CMakeFiles and IDF_VERSION but didn't found anything related. Please forgive me if it was asked before :)

IDEA (I know pre-processor directives won't work but just to illustrate it)

Code: Select all

idf_component_register(SRCS ${app_sources}
                       INCLUDE_DIRS "include"
                       REQUIRES esp_timer
#if IDF_VERSION > 5.0
                       driver esp_adc
#else
                       esp_adc_cal
#endif
)
So I could for example use the new esp_adc but still keep the old esp_adc_cal. Is there any smart way to tell CMake, hey if Framework version is major than X, then include this component, or if not then add this other component.

Without this keeping Firmware's that might be compiled in either IDF 4.4 or 5 will be a real pain to maintain.
Last edited by fasani on Fri Aug 26, 2022 5:29 am, edited 1 time in total.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: IDF ver 4.4 & 5 compatibility in CMakeFiles

Postby gtjoseph » Thu Aug 25, 2022 9:27 pm

This works for me...

Code: Select all

if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0")
    # do something
else()
    # do something else
endif()

User avatar
fasani
Posts: 197
Joined: Wed Jan 30, 2019 12:00 pm
Location: Barcelona
Contact:

Re: IDF ver 4.4 & 5 compatibility in CMakeFiles

Postby fasani » Fri Aug 26, 2022 5:28 am

Awesome!
I will use this.

Thanks a lot.
epdiy collaborator | http://fasani.de Fan of Espressif MCUs and electronic design

Who is online

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