Write your CMakeLists.txt such as

Make a directory to store the compiled files, such as build using mkdir build. cd build, then execute

CMake will generate all the file need within the current directory, i.e., build.

With the generated Makefile, we make to compile the program.