Clion how to add files to a project

一世执手 提交于 2019-12-12 08:33:45

问题


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


回答1:


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.




回答2:


No other option. You have to edit the CMakeLists.txt. CLion is completely cmake based IDE. Even if you need to link external libraries, you need to edit the above-mentioned file. It doesn't work like in GUI based code-blocks for example.




回答3:


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



来源:https://stackoverflow.com/questions/33627826/clion-how-to-add-files-to-a-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!