How to use Ninja on Windows with MSVC?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use Ninja on Windows with MSVC?

Robert Dailey-2
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?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

CMake mailing list
You can run `CMake -GNinja <path to source folder>` in a visual studio command line prompt where It could find the right C/C++ compiler via the environment. Normally you can find the command line prompt in the windows menu.

On Wed, May 22, 2019 at 9:58 AM Robert Dailey <[hidden email]> 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?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


--
Best regards
Haocheng

Haocheng LIU
Kitware, Inc.
R&D Engineer
1712 Route 9, Suite 300
Clifton Park, NY 12065-8662
Phone: <a href="tel:(518)%20881-4421" value="+15188814443" style="color:rgb(17,85,204);font-size:12.8px" target="_blank">518-881-4421

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

Marc CHEVRIER
In reply to this post by Robert Dailey-2
The easiest way is to launch a CMD with the correct development environment (see for example https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs).

Le 22 mai 2019 à 15:58 +0200, Robert Dailey <[hidden email]>, a écrit :
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?
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

Michael Jackson
In reply to this post by Robert Dailey-2
Do this all the time both for our CDash nightlies and when I am developing on Windows. The essential pieces of the puzzle are the following:

1: Ninja needs to be on your path
2: The compilers need to be on your path.

1 can be solved in a few different ways. The brute force is to edit the system path variable and place the folder containing Ninja into the system path. I do NOT recommend doing this. Repeat. DON'T DO IT. You can edit your "User" PATH environment variable and add to the PATH. This is the more recommended way but a bit tedious to get into that dialog box to adjust. We will come back to this..

For 2, use the "Visual Studio Command Prompt" which has all the paths to the compilers setup for you. Now the question becomes, how to combine 1 and 2. My own solution (which is far from optimal, but works) is that I setup my own "short cut" to a command prompt that launches my own custom .bat file that sits on my desktop. In that .bat file is basically a copy of the vcvarsall.bat file and then I add to that my own specific PATH values for things like Qt, hdf5, cmake, ninja that on located on my system. I keep both the shortcut and the .bat file on my desktop so all I need to do is double click to get a correctly configured command prompt for my dev environment. If a version of something changes I just edit the .bat file and I am ready to go. You can then also do "cmake-gui.exe ." from inside a build folder to have CMake-Gui launch with all the correctly identified compilers.

I am happy to share the .bat file if you are interested. I have it updated for VS2017 at the moment but have been doing it this way since VS2013.

--
Michael Jackson | Owner, President
      BlueQuartz Software
[e] [hidden email]
[w] www.bluequartz.net <http://www.bluequartz.net>

On 5/22/19, 9:58 AM, "CMake on behalf of Robert Dailey" <[hidden email] on behalf of [hidden email]> 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?
    --
   


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

Juan E. Sanchez


On Wed, May 22, 2019 at 10:27 AM Michael Jackson <[hidden email]> wrote:
Do this all the time both for our CDash nightlies and when I am developing on Windows. The essential pieces of the puzzle are the following:

1: Ninja needs to be on your path
2: The compilers need to be on your path.

1 can be solved in a few different ways. The brute force is to edit the system path variable and place the folder containing Ninja into the system path. I do NOT recommend doing this. Repeat. DON'T DO IT. You can edit your "User" PATH environment variable and add to the PATH. This is the more recommended way but a bit tedious to get into that dialog box to adjust. We will come back to this..

For 2, use the "Visual Studio Command Prompt" which has all the paths to the compilers setup for you. Now the question becomes, how to combine 1 and 2. My own solution (which is far from optimal, but works) is that I setup my own "short cut" to a command prompt that launches my own custom .bat file that sits on my desktop. In that .bat file is basically a copy of the vcvarsall.bat file and then I add to that my own specific PATH values for things like Qt, hdf5, cmake, ninja that on located on my system. I keep both the shortcut and the .bat file on my desktop so all I need to do is double click to get a correctly configured command prompt for my dev environment. If a version of something changes I just edit the .bat file and I am ready to go. You can then also do "cmake-gui.exe ." from inside a build folder to have CMake-Gui launch with all the correctly identified compilers.

For this option, you can use the batch command, "call", to read in the environment of another ".bat" script, so that you do not have to make copies of the vcvarsall.bat files.  As long as you are not using "setlocal" in a script, then the environment variables will propagate up to the caller.

 For example your script can have (for VS 2015) :
call "%VS140COMNTOOLS%VsVars32.bat"  

and the add lines setting additional PATH values.

Regards,

Juan

 

I am happy to share the .bat file if you are interested. I have it updated for VS2017 at the moment but have been doing it this way since VS2013.

--
Michael Jackson | Owner, President
      BlueQuartz Software
[e] [hidden email]
[w] www.bluequartz.net <http://www.bluequartz.net>

On 5/22/19, 9:58 AM, "CMake on behalf of Robert Dailey" <[hidden email] on behalf of [hidden email]> 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?
    --



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

Michael Ellery
In reply to this post by Robert Dailey-2


> On May 22, 2019, at 6:58 AM, Robert Dailey <[hidden email]> 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


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

Robert Dailey-2
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 <[hidden email]> wrote:

>
>
>
> > On May 22, 2019, at 6:58 AM, Robert Dailey <[hidden email]> 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
>
>
--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: How to use Ninja on Windows with MSVC?

Michael Jackson
In reply to this post by Juan E. Sanchez

Cool tip. Didn’t know that. I should compact my script a bit. I do that for the Intel Fortran compiler that we use but didn’t think of it for the vcvarsall.bat file.

 

--

Mike Jackson

 

From: Juan Sanchez <[hidden email]>
Date: Wednesday, May 22, 2019 at 11:41 AM
To: Michael Jackson <[hidden email]>
Cc: Robert Dailey <[hidden email]>, CMake <[hidden email]>
Subject: Re: [CMake] How to use Ninja on Windows with MSVC?

 

 

 

On Wed, May 22, 2019 at 10:27 AM Michael Jackson <[hidden email]> wrote:

Do this all the time both for our CDash nightlies and when I am developing on Windows. The essential pieces of the puzzle are the following:

1: Ninja needs to be on your path
2: The compilers need to be on your path.

1 can be solved in a few different ways. The brute force is to edit the system path variable and place the folder containing Ninja into the system path. I do NOT recommend doing this. Repeat. DON'T DO IT. You can edit your "User" PATH environment variable and add to the PATH. This is the more recommended way but a bit tedious to get into that dialog box to adjust. We will come back to this..

For 2, use the "Visual Studio Command Prompt" which has all the paths to the compilers setup for you. Now the question becomes, how to combine 1 and 2. My own solution (which is far from optimal, but works) is that I setup my own "short cut" to a command prompt that launches my own custom .bat file that sits on my desktop. In that .bat file is basically a copy of the vcvarsall.bat file and then I add to that my own specific PATH values for things like Qt, hdf5, cmake, ninja that on located on my system. I keep both the shortcut and the .bat file on my desktop so all I need to do is double click to get a correctly configured command prompt for my dev environment. If a version of something changes I just edit the .bat file and I am ready to go. You can then also do "cmake-gui.exe ." from inside a build folder to have CMake-Gui launch with all the correctly identified compilers.

 

For this option, you can use the batch command, "call", to read in the environment of another ".bat" script, so that you do not have to make copies of the vcvarsall.bat files.  As long as you are not using "setlocal" in a script, then the environment variables will propagate up to the caller.

 

 For example your script can have (for VS 2015) :

call "%VS140COMNTOOLS%VsVars32.bat"  

 

and the add lines setting additional PATH values.

 

Regards,

 

Juan

 

 


I am happy to share the .bat file if you are interested. I have it updated for VS2017 at the moment but have been doing it this way since VS2013.

--
Michael Jackson | Owner, President
      BlueQuartz Software
[e] [hidden email]
[w] www.bluequartz.net <http://www.bluequartz.net>

On 5/22/19, 9:58 AM, "CMake on behalf of Robert Dailey" <[hidden email] on behalf of [hidden email]> 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?
    --



--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake