One good tutorial about CMake is here. You can also take the official document as a reference.

## What is CMake?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists.txt file is automatically generated under the project root.

So when you want to get CMake running you are required to handle some basic CMakeList syntax, which I’ll show below.

## An example CMakeList.txt provided by JetBrains

cmake_minimum_required(VERSION 3.13)  # CMake version check
project(simple_example)               # Create project "simple_example"
set(CMAKE_CXX_STANDARD 14)            # Enable c++14 standard

# Add main.cpp file of project root directory as source file
set(SOURCE_FILES main.cpp)

# Add executable target with source files listed in SOURCE_FILES variable

### Compile

• Run cmake .in your project directory, and get your Makefile.
• Run make, and CMake will compile automatically.
• In Linux Terminal you can run command ./yourfile to run your project.

Categories:

Updated: