Determinate os platform

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?

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

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

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.

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.

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

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.