Manage Project Files
When you include header or source files located under the project root into any project file, CLion treats them as project files as well. You do not need to list such includes in CMakeLists.txt directly to get full code insight and refactoring functionality for them. Note that standard or third-party libraries located outside of the project root are not affected.
When a source or header file is not included in any of the project files or CMake targets, and is not located under the source or library roots, CLion notifies you about it:
You need to specify that file as a project one explicitly. Use one of the following approaches:
When the source files that don't belong to any target are located under the project root, add them to a target using
add_library()command depending on the target type.
For example, the above screenshot illustrates the situation when
add executable()contains only the
main.cpp Header1.h Header2.hfiles and knows nothing about add.cpp. In this case, add.cpp can be added to the list of sources as follows:add_executable (TestProject main.cpp Header1.h Header2.cpp add.cpp)
If the directory that contains non-project sources is located under the project root, you can mark it as library: in the Project tool window, right-click the directory and select from the context menu.
For library files located outside the project root, specify the header search paths so that CLion can index the required directories and provide code completion and navigation facilities on
For more details, refer to our Quick CMake Tutorial.
Upon any of these actions, CLion will prompt you to reload CMake project if automatic reload is not enabled.