ESP-IDF Configuration Issue

Hello, after long search and days of trial and error I still have the problem that CMake seems to have difficulties finding the file. I tried to port a project from Arduino to ESP-IDF for Licensing reasons, however, after that didn’t work I used a fresh project which has the same problem. Following context:

Project Structure:

include
lib
src
- CMakeLists.txt
- main.c
test
CMakeLists.txt
CMakeListsPrivate.txt
platformio.ini
sdkconfig.esp32dev

Contents:
src/CMakeLists.txt:

FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)

idf_component_register(SRCS ${app_sources})

src/main.c

void app_main() {}

CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)

project("untitled1" C CXX)

include(CMakeListsPrivate.txt)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeListsUser.txt)
include(CMakeListsUser.txt)
endif()

add_custom_target(
    Production ALL
    COMMAND platformio -c clion run "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_custom_target(
    Debug ALL
    COMMAND platformio -c clion debug "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

add_executable(Z_DUMMY_TARGET ${SRC_LIST})

CMakeLists.txt is default and pretty long so not posting that here

platformio.ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf

platform_packages =
    platformio/tool-cmake@^3.21.3

sdkconfig.esp32dev is default and unchanged too, basically the only thing I changed in the project was pulling up the tool-cmake version to 3.21.3 to enable the compiler running C 17.

The CMake fails with the following error message

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.1.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50001.0 (5.0.1) 
 - tool-cmake @ 3.21.3 
 - tool-esptoolpy @ 1.40500.0 (4.5.0) 
 - tool-ninja @ 1.7.1 
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) 
 - toolchain-xtensa-esp32 @ 11.2.0+2022r1
Reading CMake configuration...
Warning: Could not find "sdkconfig.json" file

Error: Couldn't find the main target of the project!
 [FAILED] Took 0.79 seconds 
gmake[3]: *** [CMakeFiles/Production.dir/build.make:70: CMakeFiles/Production] Fehler 1
gmake[2]: *** [CMakeFiles/Makefile2:87: CMakeFiles/Production.dir/all] Fehler 2
gmake[1]: *** [CMakeFiles/Makefile2:94: CMakeFiles/Production.dir/rule] Fehler 2
gmake: *** [Makefile:124: Production] Fehler 2

CLion + ESP-IDF is not possible with PlatformIO. Each one of these needs the CMakeLists.txt to be of a specific content, but can only be one of them. Your above one so that CLion can call into PlatformIO. But then also needing to be for ESP-IDF like here.

See

https://docs.platformio.org/en/latest/integration/ide/clion.html#clion-with-esp-idf

So that being said, the only option is to remove PlatformIO from the toolchain and just set up an ESP-IDF toolchain in CLion to automate programming?

Either PlatformIO and a different IDE, or native ESP-IDF project in CLion.

Thanks, I’ll have a look at that, I haven’t toyed around with native ESP-IDF yet but I’ll have a look, CLion is basically the way to go for me since I’m super used to JetBrains IDEs

Recently the new CLion was released with PlatformIO plugin completely rewritten.
ESP32 should be working now.

A blog post:

CLion documentation: