CLion has the ability to support nested CMakeLists.txt files, as per CMakeLists.txt | CLion Documentation. I want to use this feature (or similar) so I can combine the code for a PlatformIO firmware project and a related desktop GUI tool in the same CLion project. The PlatformIO firmware and the GUI tool share some common code, and ideally I’d like to seamlessly work on the firmware, GUI, and common code all at once.
I tried putting the firmware code, GUI code and shared code in three subdirectories, with a parent CMakeLists.txt file containing the following:
This doesn’t work however, because when I try to create a PlatformIO run configuration I get an error saying this isn’t a PlatformIO project. Presumably the PlatformIO plugin is only looking in the root directory for platformio.ini?
I also tried leaving platformio.ini in the root directory and using a CMakeListsUser.txt file containing:
This gets closer, but the gui build fails, I think because it has picked up the wrong toolchain from PlatformIO’s CMakeListsPrivate.txt file.
Am I just doing something stupid, or this a genuine problem? Is there any workaround or solution to this?
OK I’ve figured out a partial and messy workaround. If I go with the second approach (leaving platformio.ini in the CLion project’s root directory) and put
add_subdirectory(gui) in CMakeListsUser.txt, and create a new CMake profile in the CLion settings, I can then manually override the various variables that the PlatformIO CMakeListsPrivate.txt file create.
To get rid of PlatformIO’s toolchain, my GUI CMakeLists.txt file starts with the following:
Further down I do something similar to the following, to avoid clashing with PlatformIO’s SRC_LIST:
set(CMAKE_CXX_STANDARD_LIBRARIES "-lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32")
I’m not sure why I have to specify the standard libraries to link against as that isn’t normally required.
One big remaining problem is the GUI source files show lots of errors, because CLion isn’t picking up the correct environment or the libraries listed above for my GUI code. That makes coding/debugging very challenging.
I think it would be much nicer and cleaner to be able to treat the PlatformIO build as a child of the main project. Does anyone know if that is possible and would work well? If so, how?
Recently the new CLion was released with PlatformIO plugin completely rewritten.
No more CMakeLists.txt inside.
I believe a solution for you is to have platformio.ini in the project root and CMakeLists.txt somewhere in
gui subfolder, pointing at common code.
A blog post about new version: