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

Robert Dailey rcdailey.lists at gmail.com
Wed May 22 13:34:38 EDT 2019


Thanks everyone. I fully understand about compilers being on PATH or
setting the CMAKE_<LANG>_COMPILER variables. However, what is really
important is the system introspection done by CMake to find the IDEs
when you select the visual studio generators. I was hoping that logic
could be shared. This would save a lot of work in setting up
environment and/or hunting down vcvars batch files.

On Wed, May 22, 2019 at 10:44 AM Michael Ellery <mellery451 at gmail.com> wrote:
>
>
>
> > 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