CLion 2016.1 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.

cl_cmakeListsFiles
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:

cmake_minimum_required(VERSION 3.2.2) # CMake version check project(simple_example) # Create project "simple_example" set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Enable c++11 standard set(SOURCE_FILES main.cpp) # Add main.cpp file of project root directory as source file add_executable(simple_example ${SOURCE_FILES}) # Add executable target with source files listed in SOURCE_FILES variable
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

See Also

Languages, Frameworks and Technologies:

Projects and Modules:

Concepts:

Last modified: 20 July 2016