How to add existing C++ source files to the simple "Hello World" project?


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?


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?

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:


Please sign in to leave a comment.