Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake -G Ninja on Windows specify x64

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 .. 
like image 531
xren Avatar asked Jul 07 '15 07:07

xren


2 Answers

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:

enter image description here


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 ... 
like image 76
Florian Avatar answered Sep 24 '22 06:09

Florian


When I tried to run cmake on command line in Windows, trying to use Ninja and targetting the Visual Studio 14.0 compiler (2015), it kept picking up on other installed compilers (in my case gcc) instead.

The following command line worked:

cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="cl.exe" -DCMAKE_CXX_COMPILER="cl.exe" -DMSVC_TOOLSET_VERSION=140 .. 
like image 28
techmancer75 Avatar answered Sep 23 '22 06:09

techmancer75