DEV Community

Cover image for Build C++ project using CMake on Windows
Srecko Kostic
Srecko Kostic

Posted on • Originally published at srele96.Medium

Build C++ project using CMake on Windows

Building a basic project structure using CMake and CMakeLists.txt on windows. A short and concise set of steps I did to build and run the C++ project structure.

Description

Using base structure:

building-with-cmake/
building-with-cmake/.gitignore
building-with-cmake/README.md

building-with-cmake/CMakeLists.txt
building-with-cmake/source
building-with-cmake/source/CMakeLists.txt
building-with-cmake/source/main.cpp
Enter fullscreen mode Exit fullscreen mode

Learn to build a project using CMake. At least a small one, like this one.

Goals

Build and run the code.

Build steps

I created this sample on windows machine. I think that is relevant information.

When first opening the directory

Run the steps in the following order:

@REM this is a comment

@REM create directory
mkdir build

@REM go to directory
cd build

@REM setup the project
cmake ..

@REM build the program
cmake --build .

@REM run the program
Debug\building-with-cmake
Enter fullscreen mode Exit fullscreen mode

After we create the build directory

Run the following:

@REM build the program, probably after code change
cmake --build .

@REM run the program
Debug\building-with-cmake
Enter fullscreen mode Exit fullscreen mode

Alternatively, we may have to run one more step. Probably if we
change CMakeLists. I am not sure about that.

@REM setup the project
cmake ..

@REM build the program
cmake --build .

@REM run the program
Debug\building-with-cmake
Enter fullscreen mode Exit fullscreen mode

Top comments (0)