CMake: How to specify target platform?

Viewed 21423

How to specify target platform for CMake? For instance x86, x64, amd64. I've tried set TARGET_CPU=x64 but not sure does it works or not.

4 Answers

To specify 64 bit architecture for Visual Studio do:

cmake -A x64 .

To specify it in the CMakeLists.txt use:

set(CMAKE_GENERATOR_PLATFORM x64)

and

set(CMAKE_GENERATOR_PLATFORM win32)

before calling the project() command

A little update for Cmake 3.17 and Visual Studio 2019.

In this case, even if you specify genertator with -G, you have to use -A option with either Win32 or Win64.

Related