# Determinate os platform

**URL:** <https://discourse.cmake.org/t/determinate-os-platform/7218>\
**Category:** Code\
**Created:** [January 9, 2023, 1:04pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218 "2023-01-09T13:04:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samega7Cattac](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samega7cattac/32/3064_2.png) [@Samega7Cattac](https://discourse.cmake.org/u/Samega7Cattac)\
**Post date:** [January 9, 2023, 1:04pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218/1 "2023-01-09T13:04:34Z")

</div>

hi,  
I’m trying to determinate the os platform that is being used so I can create a definition and pass it to my code.  
From what I checked from old mails (~2011).  
It is possible by checking the size of void like so:

if(CMAKE\_SIZEOF\_VOID\_P EQUAL 8)  
# is 64 bit  
elseif(CMAKE\_SIZEOF\_VOID\_P EQUAL 4)  
# is 32 bit  
endif()

This is still the way or it was introduced a new way since then?

---

<div class="post-metadata">

**Author:** ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)\
**Post date:** [January 9, 2023, 1:07pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218/2 "2023-01-09T13:07:50Z")

</div>

Since CMake 3.10 or so there is a simpler way to check that  
see: [https://cmake.org/cmake/help/latest/command/cmake\_host\_system\_information.html](https://cmake.org/cmake/help/latest/command/cmake_host_system_information.html)

I assume that your are not cross-compiling.  
If this is the case read indication here: [https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html](https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html)

---

<div class="post-metadata">

**Author:** ![Samega7Cattac](https://discourse.cmake.org/user_avatar/discourse.cmake.org/samega7cattac/32/3064_2.png) [@Samega7Cattac](https://discourse.cmake.org/u/Samega7Cattac)\
**Post date:** [January 9, 2023, 2:05pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218/3 "2023-01-09T14:05:45Z")

</div>

Yes I’m cross compiling too, but I needed cmake to get that info for me since it’s manipulable later on.  
If I can query the “is\_64bit” in WIndows and Linux then it’s ok and I also need to count with arm too.

---

<div class="post-metadata">

**Author:** ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)\
**Post date:** [January 9, 2023, 2:24pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218/4 "2023-01-09T14:24:21Z")

</div>

is\_64bit will work for the host but not for the target. That said I did not cross-compile with CMake for a loooong time. May be other more active cross-compiler can give more valuable information about that.

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [January 11, 2023, 1:07pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218/5 "2023-01-11T13:07:27Z")

</div>

Even without actual cross-compiling, will this work when generating a `Win32` Visual Studio solution when running on 64-bit Windows?

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [January 11, 2023, 5:18pm UTC](https://discourse.cmake.org/t/determinate-os-platform/7218/6 "2023-01-11T17:18:11Z")

</div>

Every method that ist differs between 32 and 64 bit will e.g. fail for amd64. While all of this is also considered cross-compiling, it is sometimes easier to achieve than having to write a toolchain file. And it should only be used for selecting e.g library files for linking, not for setting defines for code.

Looking at host bit size has limited value.
