Page 1 of 1

CMake with CLion - working!

Posted: Tue Oct 02, 2018 8:54 pm
by permal
Now that we have the new CMake support I decided to try to get it to work with CLion, my C++ IDE of choice. After some initial head-scratching I can now compile entire projects from within CLion. Code completation is also working. Awesome.

There is one key point to get it working:
  • When CLion launches CMake, environment variables from for example ~./bashrc are NOT propagated to the CMake process. As such your ${IDF_PATH}, ${PYTHON} and ${PATH} are blank causing things to break.
Also, when initially setting things up, the menu option Tools->CMake->Reset Cache and reload project is your friend when CMake complains about xtensa-esp32-elf-cc not being able to compile a simple C program.

I've not yet tried to debug via CLion and I doubt that is possible, but JetBrains have stated that they're going to put resources into embedded programming with CLion so we might eventually get that too. See this ticket, go up vote and put a note about ESP32-development. :)

The screenshots below shows how I set up CMake and Toochain. I had to delete the default one, otherwise CLion didn't want to use the one I specified for xtensa; not sure if that is a bug or me missing something.
clion-xtensa-toolchain.png
clion-xtensa-toolchain.png (83.15 KiB) Viewed 15627 times
clion-xtensa-cmake-config-environment-variables.png
clion-xtensa-cmake-config-environment-variables.png (23.76 KiB) Viewed 15627 times
clion-xtensa-cmake-config.png
clion-xtensa-cmake-config.png (96.22 KiB) Viewed 15627 times

Re: CMake with CLion - working!

Posted: Fri Nov 02, 2018 10:14 pm
by hassan789
Great work. Been looking for an alternative to eclipse

Re: CMake with CLion - working!

Posted: Fri Nov 02, 2018 10:23 pm
by permal
hassan789 wrote:Great work. Been looking for an alternative to eclipse
Please see this post. It has turned out that this is not reliable: viewtopic.php?f=13&t=7535&p=33004#p33004

Re: CMake with CLion - working!

Posted: Mon Jul 01, 2019 11:30 pm
by meowsqueak
What's the current status of this? I'm keen to test out the state-of-the-art and help if i can...

Re: CMake with CLion - working!

Posted: Tue Jul 02, 2019 5:44 am
by permal
meowsqueak wrote:
Mon Jul 01, 2019 11:30 pm
What's the current status of this? I'm keen to test out the state-of-the-art and help if i can...
It's shaky at best. I don't know why, but sometimes CLion simply loses the xtensa toolchain so it is no longer selectable. I'm currently compiling using command line instead.

Also, in adition to the above, you have to specify these cmake options:

-DESP_PLATFORM=1 -DCMAKE_TOOLCHAIN_FILE=/path_to_idf/tools/cmake/toolchain-esp32.cmake -DTARGET=esp32

Re: CMake with CLion - working!

Posted: Wed Jul 03, 2019 3:17 am
by meowsqueak
Thanks for the reply. I'm also having some trouble with it, although I'm only trying to build IDF examples and my own projects at the moment. I've written a bit about my troubles here: viewtopic.php?f=13&t=11280

Re: CMake with CLion - working!

Posted: Tue Jul 23, 2019 6:18 pm
by raldone01
I don't know if it helps but I created a [template project for clion](https://gitlab.feather.ink/raldone01/es ... t-template) which works for windows without setting environment variables. (ESP-IDF v4)

Re: CMake with CLion - working!

Posted: Wed Mar 02, 2022 10:14 pm
by crmabs
Many thanks for that!
It was absolutely frictionless.