CMake -G Ninja on Windows specify x64

37,078

Solution 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:

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
...

Solution 2

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 ..
Share:
37,078
xren
Author by

xren

I am xren.

Updated on March 04, 2021

Comments

  • xren
    xren about 3 years

    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 ..
    
  • Antwane
    Antwane almost 9 years
    Or simply run CMake command from a "Microsoft Visual Stduio Command Prompt (x64)". A shortcut to this prompt is located in Start Menu
  • kuga
    kuga about 5 years
    Note that /DWIN32 is still set in the Cache file. This comes from Windows-MSVC.cmake
  • harish
    harish about 4 years
    In my machine this gavem cl.exe is not a full path and was not found in the PATH. Guess need to give full paths then
  • Geng  Jiawen
    Geng Jiawen about 2 years
    Is there a way in powershell to do this ?