Search code examples
cmakeclionjetbrains-ide

How to switch existing Makefile project to CMake in CLion


I can't figure out how to switch a Makefile project to CMake.

If I open a project from VCS for example, the project might have a Makefile in it already, and CLion will detect this. But there seems to be no way to switch the configuration to CMake afterwards?

I delete the Makefile and add a CMakelists.txt, then I edit the debug configuration... but it asks for a 'target', with no options but 'all targets' which doesn't work. Clicking the 'build' options also still tries to build using a Makefile.

The only workaround I found so far, is to reload the folder as a new project (after deleting the .idea folder) and let CLion correctly detect the CMakelists.txt, but there must be a better way.


Solution

  • Delete the makefile, then navigate to the source directory and delete the .idea folder (a hidden folder), then select invalidate caches in the file tab and restart the IDE. After restarting the IDE, you should be able to reload the CMake project.

    Please note that I was unable to find a straightforward method to accomplish this.