CMake: How to specify target platform?

To specify it in the CMakeLists.txt use:

set(CMAKE_GENERATOR_PLATFORM x64)

and

set(CMAKE_GENERATOR_PLATFORM win32)

before calling the project() command


To specify 64 bit architecture for Visual Studio do:

cmake -A x64 .

When calling the cmake command you can define a generator for instance Visual Studio 14 2015 Win64 which results in the target platform x64

cmake -G"Visual Studio 14 2015 Win64" -H%SOURCE_ROOT_DIR% -BC:\build\vs2015\x64\MyProject

If you like to build for x86 on Windows with VS2015 - you would go this way:

cmake -G"Visual Studio 14 2015" -H%SOURCE_ROOT_DIR% -BC:\build\vs2015\x64\MyProject

ARM:

cmake -G"Visual Studio 14 2015 ARM" -H%SOURCE_ROOT_DIR% -BC:\build\vs2015\x64\MyProject

Depending on your problem maybe a CMake toolchain file can help you.

Tags:

C++

Cmake