CLion 2017.3 Help

CMakeLists File

Basics

CMakeLists.txt file contains a set of directives and instructions describing the project's source files and targets (executable, library or both). When you create a new project CLion generates CMakeLists.txt file automatically and places it into project directory, which is also referred to as the project root directory. Further you can open the project by simply opening the top-level CMakeLists.txt file in the project root directory.

When a project has the complex structure and includes one or more subdirectories (project root and subdirectories), you can create subdirectory CMakeList.txt files. Subdirectory CMakeLists.txtfiles describe the build, contents, and target rules for a subdirectory. Type of a target added by subdirectory CMakeLists.txtfile depends on a role of the given module and can be different (static library, DLL and many other).

Example below illustrates CMakeLists.txt file of the simple "Hello, World!" project where the target is an executable file:

In CLion, if you open a project based on a build system, other than CMake, you have very limited capabilities of working with such a project: you are not able to edit code, build and run the project, etc. In such a case you can create and save CMakeLists.txt file (as well as subdirectory files, if necessary) yourself using CLion Editor or import the project via CLion Import functionality.

Editing CMakeLists.txt

You can modify the project build description by editing CMakeLists.txt file in the Editor window. Keep in mind, that you need to reload the current project after editing. This can be done manually or automatically. Autoreload feature is disabled by default. You can check the current status of autoreload and change other CMake settings in CMake Settings Dialog