PlatformIO Community

Esp32 conditionnal src folder

Hello,

I’m converting a esp32 esp-idf code that uses cmake to use platformio.
This project supports multiple esp boards, and each board uses its own board folder.
In my current cmakeList.txt, we use the following code:
add_subdirectory(boards/${BOARD}) and we use cmake -DBOARD=esp32devkit for example.

What I’ve done so far:
Use “build_flags = -D”, but the flag is not passed to cmake…

I Tried to use src_filter, but it does not work as I’m using esp-idf and I get a warning.

Any way of doing it properly?

Thank you!

Please open an issue about this in Issues · platformio/platform-espressif32 · GitHub.

ok, thank you for your answer. will do :slight_smile:

1 Like

Hi @fariouche ! The build_flags option is meant to pass compiler flags and it seems you’re trying to pass an extra flag to CMake itself. I believe the board_build.cmake_extra_args is what you need. It’s not documented, but should help you out. Something like this:

[env:esp32dev]
platform = espressif32
framework = espidf
board = esp32dev
board_build.cmake_extra_args = -DBOARD_NAME=esp32dev
1 Like

Thank you this works!
One more question: what is the best solution for my problem?

  • Hack my cmake files to make it work? (I have other problems now, but most likely because I must not call some esp idf cmake functions…)
  • Or let platformio generate the cmake files (seems better) but then I miss something in platformio to select folders to build :slight_smile:

what is the best solution for my problem?

I’d go with proper CMake files. This way you can always keep your project backward compatible with the IDF build system.

:+1: thanks! This helps a lot