Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clion how to add files to a project

Tags:

cmake

clion

This seems really basic. How can i add files to a project without having to manually edit the CMakeLists.txt.

For example source files in another directory

like image 386
jkj yuio Avatar asked Nov 10 '15 10:11

jkj yuio


People also ask

How do you use files in CLion?

Press Ctrl+Alt+S to open the IDE settings and select Editor | File Types. Click Associate File Types with CLion and select the file extensions you want to open with the IDE. Click OK and close the dialog.

Where does CLion store project files?

Project root directory Any project in CLion should be encapsulated within the project directory, referred to as the project root. It contains all the project files and subdirectories, including configuration, data, source, and other files related to the project.


2 Answers

CLion parses the CMakeLists.txt and uses it to generate a project view, but I believe the only way to add files to the project is to edit the CMakeLists.txt to include those files. I expect that eventually this will change similar to the way IntelliJ integrates with a pom.xml file in a Java project, but for now you edit the CMakeLists.txt.

like image 175
legalize Avatar answered Sep 20 '22 19:09

legalize


There is also a way to make CLion to add any cpp and h files (I don't know why don't they do it by default) and is to add this line:

file(GLOB SOURCES
    *.h
    *.cpp
)

and also edit the line of:

add_executable(ClionProject ${SOURCE_FILES} ${SOURCES})

In this example: ClionProject is actually the name of the project. SOURCES_FILES and SOURCES can be whatever you want.

Another good idea is to go to File -> Settings -> Build, Execution, Deployment -> CMake and tick on "Automatic reload CMake project on editing"

Here is a good starting tutorial: https://www.jetbrains.com/help/clion/2016.3/quick-cmake-tutorial.html

like image 33
Agustin Barrachina Avatar answered Sep 17 '22 19:09

Agustin Barrachina