Assume we are in the repository with a CMakeLists.txt. Here are the steps to use it.
Create a build directory and move into it:
Configure cmake, telling it where your source directory is:
CMake will generate the build files using the default generator for your platform. On Linux (including WSL) and macOS, the default is a Makefile.
Use Make just like you would with a written Makefile:
If you have any custom targets, such as run
, you can use that:
The CMake-generated Makefile automatically includes a clean
target:
The Makefile should rerun CMake if needed. But if it doesn't, or you want to change your CMake configuration, you can rerun cmake:
The .
refers to the current (build) directory.
If you want to create a Debug build:
or a release build: