CMake 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 can experience an incorrect behavior of such features like syntax highlighting, refactoring, code navigation etc. for such a file until you specify that file as a project one explicitly. To do that use one of the following approaches:
When the source files that don't belong to any target are located within the project root, you should add them to a target. Use
add_library ()CMake commands depending on the target type. Let's consider it for our example.
The above screenshot reflects condition when
add executable ()contains only the
main.cpp Header1.h Header2.hfiles and knows nothing about
add.cpp. Here, you should add the non-project sources to the list of source files, as follows:
add_executable (TestProject main.cpp Header1.h Header2.cpp add.cpp)
When a directory that contains the non-project library sources is located within the project root, you can mark this directory as a library: in the Project tool window, right click the desired directory and select from the context menu.
For the library files located outside the project root, specify the header search paths so that the IDE can index the respective directories and provide code completion and navigation facilities on
For more details, refer to our Quick CMake Tutorial.
Upon any of these actions, the system will prompt you to reload CMake project if automatic reload is not enabled.