How to Run CMake from Windows Command Line: Step-by-Step Guide

Learn how to run CMake from the Windows command line with simple commands for configuring and building your project.

0 views

To run CMake from the Windows command line, first ensure CMake is installed and its directory is added to your system's PATH. Open the Command Prompt and navigate to your project's directory using the `cd` command. To configure your project, type `cmake -S . -B build` where `-S` specifies the source directory and `-B` the build directory. To build the project, use `cmake --build build`, where `build` is the build directory name. This straightforward process initializes and builds your CMake project directly from the command line.

FAQs & Answers

  1. How do I add CMake to the Windows PATH? To add CMake to the Windows PATH, go to System Properties > Environment Variables, find the PATH variable, and append the CMake installation directory to it.
  2. What is the difference between the -S and -B options in CMake? The -S option specifies the source directory containing your project files, while the -B option specifies the build directory where CMake will generate build files.
  3. Can I build a CMake project directly from the command line on Windows? Yes, you can use the command 'cmake --build build' to build your CMake project from the Windows command line.