How to add existing C++ source files to the simple "Hello World" project?
Answered
I followed the simple one-sentence instruction here to create a simple CLion project from scratch. It works and I can debug it. Now I wanna replace it with my existing C++ sources, that is, adding tens of existing C++ source files into the scratch project and replacing the main.cpp with my own. But after copying my source files into the project directory and search the GUI of CLion and google, I just can't figure out how to do that. So, are CLion users supposed to edit CMakeLists.txt file manually to accomplish this very basic work? How can I add existing source files into the simple scratch project in CLion using only mouse clicks and menus which is a common operation in NetBeans and Eclipse?
Please sign in to leave a comment.
Currently, editing the CMakeLists.txt file is the only option to do it. There is the filename auto-completion in the CMakeLists.txt to help with this action.
Please note that when you create new file in CLion (using the Project tool window), it automatically suggests you to add this file into one of the existing CMake target. We plan to implement an ability to add files created outside CLion into CMake targets automatically in the future. Feel free to follow or upvote the corresponding ticket in our tracker.
By the way, CLion is able to create a CMake project from the existing sources. To give it a try press File | Import Project… or select an Import option on the Welcome wizard. You can find out more information about this feature in the article of our web help. So while you can auto-import existing sources and include directories, any external or non-trivial dependencies wouldn't be resolved and used while indexing (you should set it manually).
Any progress?
Any progress?
I think this is the question I want to ask JetBrains. I don't have interest in adding source file using Makefile. Do it like Visual Studio. Any progress?
If you're interested in updates, please follow the related issue mentioned in my previous answer: https://youtrack.jetbrains.com/issue/CPP-1749.
Now late August 2025 and there still seems to be same problem. No right click option “add existing source file to project”. I wonder how Clion is supposed to work. Is there some secret native mode which enables it to start working as expected? If not it looks like Clion has no development at all going on. Is not the whole idea of IDE's that you don't need manually do such simple and most fundamental things like adding a file to project?
As CMakeLists.txt supports files included from anywhere in file system, any GUI-interface is supposed to support the same thing. To being able to reuse code is the whole point of such tool. If Clion is not truely developed then it should transparently and openly told and it should only have the free version. It would be best to mention that this is not our main product, but just an experimental one.
After five years, there is no “add existing source code to project” functionality that tells me that development has been stalled for five years. It’s okay if Clion is of no use to me, but it takes time and energy to find workarounds before you finally realize that there is no way.
Clion still has the educational function about how Cmake works.