CMake
CMake
CMake is the most common build system for C++. Instead of using the compiler directly, CMake controls the compilation process through platform independent configuration files.
Install CMake
CMake can be downloaded from cmake.org or from a package manager:
1 |
|
1 |
|
Configuration files
There should be a file named CMakeLists.txt
in the root directory of your project. A starting point is:
1 2 3 4 5 6 7 |
|
Building with CMake
Create a build directory:
1 |
|
Navigate to the build directory and run CMake:
1 2 |
|
This will configure the project and generate a native build system scripts.
Then call that build system to actually compile/link the project:
1 |
|
The executable file must have been generated. Note how CMake abstracts the differences between compilers and platforms.
Configure compiler
Set the variable CMAKE_CXX_COMPILER
from the command line to let CMake know what compiler to use:
1 |
|
If you want this to be your default compiler, you can set the CXX
environment variable:
1 |
|
If you want to use this compiler in a single project, always run CMake with these options:
1 |
|
Or tell your IDE to pass these options to CMake: