How CMake decides to generate Makefile of vcproj files


Ubuntu
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.10) #CMake version
project(MyProject)      #project-name
add_executable(MyExecutable main.cpp)   #(exe_name generate_from_main.cpp)
      
CMake detects system environment. It detects compilers, libraries, and dependencies, then writes the detected information to CMakeCache.txt and generates Makefile(Ubuntu) or vcproj file(Windows) accordingly.

Makefile or vcproj or Other

We can generate vcproj, Makefile from using using Generator Preference

$ mkdir build
$ cd build

// Generate Makefile
$ cmake ..
CMakeCache.txt  CMakeFiles  Makefile  cmake_install.cmake

// Generate Visual Studio 2019 vcproj file (Run cmake on Windows)
$ cmake .. -G "Visual Studio 16 2019"

// Generate Ninja
$ cmake .. -G "Ninja"