Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: How to specify target platform?

Tags:

c++

cmake

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.

like image 561
Viktor Avatar asked Jul 20 '17 23:07

Viktor


People also ask

What is a target in CMake?

A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.

How do I choose a CMake generator?

Use its -G option to specify the generator for a new build tree. The cmake-gui(1) offers interactive selection of a generator when creating a new build tree.

How does CMake know which compiler to use?

CMake needs a way to determine which compiler to use to invoke the linker. This is determined by the LANGUAGE property of source files of the target , and in the case of static libraries, the LANGUAGE of the dependent libraries.

What does Add_subdirectory do in CMake?

Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.


2 Answers

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.

like image 156
Vertexwahn Avatar answered Oct 12 '22 02:10

Vertexwahn


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.

like image 35
Feldmarshall Avatar answered Oct 12 '22 02:10

Feldmarshall