-->

CMake -G Ninja on Windows specify x64

2019-02-08 19:06发布

问题:

I am using CMake on Windows with Ninja generator

cmake -G Ninja ..

This uses the default Windows x86 toolchain. How to specify x64 using the Ninja generator?

PS: I know how to generate x64 with Visual Studio

cmake -G "Visual Studio 12 2013 Win64 ..

回答1:

You have to set the compiler environment accordingly before calling Ninja generation. If you have Visual Studio 2013 installed at the standard installation path you call:

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x64
cmake.exe -G "Ninja" ..

Edit: Thanks for the hint from @Antwane: "Or simply run CMake command from a Microsoft Visual Studio Command Prompt (x64). A shortcut to this prompt is located in Start Menu".

The naming varies over the Visual Studio versions:


When I then look into the generated CMakeCache.txt file I see:

...
//CXX compiler
CMAKE_CXX_COMPILER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/cl.exe
...
//Flags used by the linker.
CMAKE_EXE_LINKER_FLAGS:STRING= /machine:x64
...
//Path to a program.
CMAKE_LINKER:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/amd64/link.exe
...