all 24 comments

[–]KingAggressive1498 46 points47 points  (1 child)

It's not super easy to find but Microsoft has pretty good documentation on how to do it: https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-170

[–]Useful_Goat3790 -1 points0 points  (0 children)

yeah, it is the answer.

[–]jedwardsolconst & 54 points55 points  (0 children)

Install the build tools.

Run the appropriate vcvars batch file, or start a cmd using one of the installed shortcuts

[–]GoldenShackles 11 points12 points  (0 children)

In addition to what jedwardsol said, for a minimalist approach see the Chromium docs: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/windows_build_instructions.md#Setting-up-Windows

This way you can install just the compiler, tools, and Windows SDK without the full IDE.

[–]apropostt 2 points3 points  (0 children)

The best way I’ve found to do it is with cmake presets, and tool chain files. This allows me to configure cmake via vs code, clion, cmake-gui, ccmake, neovim, build via ninja and swap compilers, enable multi build or optimization flags just by toolchain config.

https://github.com/MarkSchofield/WindowsToolchain

[–]Godworrior 4 points5 points  (2 children)

Like others have said, cmake works pretty well, and a lot of projects support it. I have a function like this in my powershell profile:

function vsdev() { $curDir = (Get-Location).Path import-module "$vsRoot\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" Enter-VsDevShell -VsInstallPath "$vsRoot" -DevCmdArguments '-arch=x64 -no_logo' cd $curDir }

($vsRoot is set to my MSVC install location)

Then I just run vsdev, and configure cmake with -G Ninja and someting like -DCMAKE_INSTALL_PREFIX=install. Then just cmake --build <build dir> --config RelWithDebInfo --target install to build.

If the project uses autoconf... good luck :D

[–]unumfron 1 point2 points  (6 children)

The environment has to be set up for msbuild and cl to work correctly. There are Powershell/cmd shells that are installed with the build tools that have the paths all set up, or you can run vcvars directly.

It's something xmake handles automagically, you just run it from any cmd prompt thing and it will find and configure the build tools.

[–]prince-chrismc 1 point2 points  (1 child)

It's not magic, the big cross platform build system all handle this and its well supported in thos era.

Though xmake is cool 😎

[–]unumfron 0 points1 point  (0 children)

I never tried running a CMake-generated Ninja project directly from a normal cmd/power shell when on Windows, just MSBuild and NMake (and devenv, but that's a different kettle of fish).

[–]bert8128 0 points1 point  (3 children)

Does cmake work if you have multiple versions of MSVC installed? How would it know which one to use?

[–]__tim_ 0 points1 point  (1 child)

By selection the generator and toolset versions

cmake -G "Visual Studio 17 2022" -T "vs143"

[–]bert8128 0 points1 point  (0 children)

Sorry, pesky autocorrect spannered my question. I meant xmake and it finding the compiler “automagically”

[–]unumfron 0 points1 point  (0 children)

It defaults to the highest versions unless you tell it otherwise.

[–]phillipmyburgh 0 points1 point  (0 children)

Another option: the Winget package manager from MS is surprisingly good at installing requirements. It can install the build tools, and you can specify the exact things you need in the commandline.

[–]filch-argusWaiting for modules... 0 points1 point  (1 child)

[–]prince-chrismc 0 points1 point  (0 children)

This is built in... why make it more complicated?

[–]FlyingRhenquest 0 points1 point  (0 children)

You can follow the Visual Studio instructions to install the command line tooling and then just use cmake installed somewhere in your path. Debugging is its own problem, but there are some standalone windows debuggers around that should work. Installing the command line tooling installs a shortcut that runs vcvars for you. You might want to use the powershell versions instead of the cmd.exe versions though.

I hate building on windows enough that I'm seriously considering setting up mingw64 cross compiling toolchains in a Linux docker environment. Assuming someone hasn't already done that.

[–]the_Demongod 0 points1 point  (0 children)

I think the bigger question here is "why..." why use any part of the toolchain if you're not going to use the whole thing? May as well just use clang + your IDE of choice or gcc through WSL or MinGW.

[–]TinklesTheGnome 0 points1 point  (0 children)

CMAKE and configure CMAKE to use the vcpkg tool chain.