CMake with CLion - working!

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

CMake with CLion - working!

Postby permal » Tue Oct 02, 2018 8:54 pm

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 17643 times
clion-xtensa-cmake-config-environment-variables.png
clion-xtensa-cmake-config-environment-variables.png (23.76 KiB) Viewed 17643 times
clion-xtensa-cmake-config.png
clion-xtensa-cmake-config.png (96.22 KiB) Viewed 17643 times

User avatar
hassan789
Posts: 156
Joined: Thu Jun 29, 2017 2:15 am

Re: CMake with CLion - working!

Postby hassan789 » Fri Nov 02, 2018 10:14 pm

Great work. Been looking for an alternative to eclipse

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: CMake with CLion - working!

Postby permal » Fri Nov 02, 2018 10:23 pm

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

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Re: CMake with CLion - working!

Postby meowsqueak » 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...

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: CMake with CLion - working!

Postby permal » Tue Jul 02, 2019 5:44 am

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

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Re: CMake with CLion - working!

Postby meowsqueak » Wed Jul 03, 2019 3:17 am

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

raldone01
Posts: 8
Joined: Thu Apr 18, 2019 9:37 pm

Re: CMake with CLion - working!

Postby raldone01 » Tue Jul 23, 2019 6:18 pm

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)

crmabs
Posts: 1
Joined: Tue Mar 12, 2019 2:08 pm

Re: CMake with CLion - working!

Postby crmabs » Wed Mar 02, 2022 10:14 pm

Many thanks for that!
It was absolutely frictionless.

Who is online

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