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.txt
files describe the build, contents, and target rules for a subdirectory. Type of a target added by subdirectory CMakeLists.txt
file depends on a role of the given module and can be different (static library, DLL and many other).
CMakeLists.txt
file of the simple "Hello, World!" project where the target is an executable file: cmake_minimum_required(VERSION 3.6) # CMake version check
project(simple_example) # Create project "simple_example"
set(CMAKE_CXX_STANDARD 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
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