[CMake] How to use Ninja on Windows with MSVC?

Michael Ellery mellery451 at gmail.com
Wed May 22 11:44:01 EDT 2019



> On May 22, 2019, at 6:58 AM, Robert Dailey <rcdailey.lists at gmail.com> wrote:
> 
> From the command line, I want to generate Ninja build scripts that
> utilize a specific version of MSVC compiler. Basically I'd like the
> combination of `-G"Visual Studio 15 2017"` with regards to its ability
> to find the C and C++ compiler on the system via registry/environment
> variables, and `-G"Ninja"` with regards to it being the build driver
> for that compiler.
> 
> Is this even possible?
>

In addition to the other suggestions about using a MSVC command prompt (which work just fine for manual builds), Here’s what I’ve done when needing to automate the build using powershell:


Invoke-BatchFile "${env:ProgramFiles(x86)}\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x86_amd64
Get-ChildItem env:* | Sort-Object name


…which invokes the vcvarsall batch and imports all of the environment vars that were set by that invocation. vcvarsall is provided exactly for the purpose of setting your env for building and it supports a few different arch arguments to select the right toolchain.

HTH,
Mike




More information about the CMake mailing list