- download cmake for windows and install it. https://cmake.org/download/
- download visual studio installer from https://visualstudio.microsoft.com/downloads/
- run installer and choose
Build Tools for c++
- go make yourself a drink
The rest of all this is done from the shell and any editor
- make a junk directory somewhere and put these files into it
main.cpp
#include <iostream>
int main(int argc, char **argv)
{
std::cout << "hello world!\n";
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(hello)
add_executable(hello main.cpp)
vscmd.bat
%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\VsDevCmd.bat"
- run
vscmd.bat
this sets up the visual studio tools paths and god knows what all. Don't read the batch file that gets called from this batch file, you'll go blind. Just make sure the path to it is correct
- type
mkdir build
this is where we are going to put the build files so we don't pollute our sources
- type
cd build
go there
- type
cmake -G"NMake MakeFiles" ..
this tells cmake to generate the files that the tools need to actually build stuff. The two dots (..) tell cmake to look for the CMakeLists.txt file one directory up Now you see a whole bunch of stuff that cmake generated, one of which is a file called Makefile. This is what we need.
- type
make
this is running a VS tool called make that reads the files that cmake generated and finally builds the thing You should see hello.exe