CLion Help

CMake Build System

CLion project model is based on CMake - the cross-platform automatic build system. CMake itself doesn't build a project but passes the build rules and targets listed in CMakeLists.txt file to a specific builder.

On this page:

CMakeLists.txt file

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. If you have some existing project without CmakeLists.txt and should like to build and run it in CLion, you can import this file or create and save CMakeLists.txt file yourself using CLion Editor. Example below illustrates CMakeLists.txt file of the simple "Hello World!" project where the target is an executable file:

cmake_minimum_required(VERSION 2.8.4) # 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

When a project has 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.

Target's type depends here on a role of the given module and can be different (static library, DLL and many other).

Editing CMakeLists.txt

You can change project build parameters by editing CMakeLists.txt file in the Editor window. Keep in mind, that to apply the changes, you need to reload the current project. 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

Changing Project Root Directory

When you create a project, CLion places CMakeLists.txt file in the project root directory that is root directory for source files also. In some cases, project root directory (the one, that must contain CMakeLists.txt file) can differ from source files repository root. For example, it is possible when your source files repository root and directory with the main CMakeLists.txt are not the same. For such a case CLion provides the option of changing project root directory. You can access this option in CMake Problems tab of CMake tool window or as menu command | Tools | CMake | Change Project Root.

See Also

Projects and Modules:

External Links:

Web Resources:

Last modified: 20 March 2015
comments powered by Disqus