简体   繁体   中英

CMake: How to specify target platform?

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.

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.

要为 Visual Studio 指定 64 位体系结构,请执行以下操作:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM