I am trying to add existing source files to my Clion project, but after adding (Copy and pasting) them to the project, these files were not added to the CMakeLists file. Also, the folder is semitransparent (gray colored).
How can I automatically add new files to the CMakeList ?
In the Project tool window, right-click a file or folder, then select Deployment | Upload to from the context menu, and choose the target deployment server or server group from the list. If the default server or server group is appointed, you can also select Upload to <default deployment server or server group>.
To invoke Go to Header/Source, press F10 or call Navigate | Header/Source from the main menu.
To include headers in CMake targets, use the command target_include_directories(...) . Depending on the purpose of the included directories, you will need to define the scope specifier – either PUBLIC , PRIVATE or INTERFACE .
Lets say we have a project with only a main.cpp and we wanto to add foo.cpp: The original CMakeList.txt is the following:
cmake_minimum_required(VERSION 3.6)
project(ClionProject)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(ClionProject ${SOURCE_FILES})
Now we have to add foo.cpp
cmake_minimum_required(VERSION 3.6)
project(ClionProject)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp foo.cpp)
add_executable(ClionProject ${SOURCE_FILES})
So we changesd the line set(SOURCE_FILES main.cpp foo.cpp)
to add the .cpp
We can also add .h files in there.
BEWARE! ALL THE FILES SHOULD BE ON THE CMakeList.txt folder! if not, remember to add the path in there.
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 add_executable(ClionProject ${SOURCE_FILES} ${SOURCES})
In this example: ClionProject is actually the name of the project. SOURCES_FILES and SOURCES can be changed yo 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With