# How to distinguish WIndows Architecture

**URL:** https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104
**Category:** Usage
**Created:** [February 23, 2022, 6:09pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104 "2022-02-23T18:09:02Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![fabiop](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/8e7dd6/32.png) [@fabiop](https://discourse.cmake.org/u/fabiop)
#### Post date: [February 23, 2022, 6:09pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104/1 "2022-02-23T18:09:02Z")

</div>

Hi all,  
Is there any CMake variable for distinguish, on Windows, if we are building for 32 bits Architecture or 64 bits Architecture?  
Thanks in advance for any help

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [February 23, 2022, 6:15pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104/2 "2022-02-23T18:15:13Z")

</div>

Have a look at [CMAKE\_SIZEOF\_VOID\_P](https://cmake.org/cmake/help/latest/variable/CMAKE_SIZEOF_VOID_P.html) variable.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [February 24, 2022, 9:35pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104/3 "2022-02-24T21:35:40Z")

</div>

```auto
if (CMAKE_SIZE_OF_VOID_P EQUAL 4)
    message(STATUS "32 bit")
endif()

if (CMAKE_SIZE_OF_VOID_P EQUAL 8)
    message(STATUS "64 bit")
endif()

```

---

<div class="post-metadata">

### Author: ![fabiop](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/8e7dd6/32.png) [@fabiop](https://discourse.cmake.org/u/fabiop)
#### Post date: [March 2, 2022, 1:46pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104/4 "2022-03-02T13:46:44Z")

</div>

Ok, but if I am on a 64 bits Host machine, but I build with -A 32 bits flag, the sizeof of the word is 4 bytes or 8 bytes? I think it will be the latter…

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [March 2, 2022, 1:59pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104/5 "2022-03-02T13:59:54Z")

</div>

The variable `CMAKE_SIZE_OF_VOID_P` describes your build environment, not the host on which you are running… So it will be 4 bytes.

---

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [March 2, 2022, 3:20pm UTC](https://discourse.cmake.org/t/how-to-distinguish-windows-architecture/5104/6 "2022-03-02T15:20:02Z")

</div>

On Windows you basically have 4 different compilers (for x86/AMD64):

```auto
# C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC

# Host 64 -> Target 64
x64 Native Tools Command Prompt for VS 2022
# Host 64 -> Target 32
x64_x86 Cross Tools Command Prompt for VS 2022

# Host 32 -> Target 64
x86_x64 Cross Tools Command Prompt for VS 2022
# Host 32 -> Target 32
x86 Native Tools Command Prompt for VS 2022

```

I never recommend using the last 2 for larger applications since big projects tend to use more than 4 GB of RAM.

Anyway CMake lets you pick both your host tools and your target platform. They are different things.

From the CMake docs:

```auto
The CMAKE_GENERATOR_PLATFORM variable may be set, perhaps via the cmake(1) -A option, to specify a target platform name (architecture). For example:

- cmake -G "Visual Studio 17 2022" -A Win32
- cmake -G "Visual Studio 17 2022" -A x64
- cmake -G "Visual Studio 17 2022" -A ARM
- cmake -G "Visual Studio 17 2022" -A ARM64

```

If you want to choose different host tools here are the [docs](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html#toolset-selection). However, VS2019 and newer use 64-bit tools by default.
