This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
According to it's description CMAKE_SYSTEM_PROCESSOR should have value of "The name of the CPU CMake is building for". On Windows x64 hosts it always has value of AMD64 no matter which architecture you are building for: x86/x64 or arm. I have a strong opinion that this behavior should be fixed cause otherwise this var is completely useless on windows. And yes I know there is a CMAKE_CL_64 var for determining what arch we are building for. But it looks like a x64-only dirty hack not a generic solution
Edited
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Not a full solution, but if CMAKE_GENERATOR_PLATFORM is set, can that at least be used to provide the correct value for CMAKE_SYSTEM_PROCESSOR on Windows?
Repeating a comment I made in Mantis for easy reference:
A challenge here is that CMAKE_SYSTEM_PROCESSOR is supposed to be set as part of the CMakeSystem.cmake, configured from CMakeSystem.cmake.in but that configuration occurs very early, even before we have tried to enable any languages or detect any compilers. For Makefile and Ninja generators this is straightforward. When not cross-compiling the host processor can be detected immediately. When cross-compiling it is the responsibility of the CMAKE_TOOLCHAIN_FILE to set CMAKE_SYSTEM_PROCESSOR for the target.
The problem for VS generators is that the target architecture is not determined in time to configure CMakeSystem.cmake because they "cross" compile without explicitly saying so.
@craig.scott yes, I think we should be able to compute the CMAKE_SYSTEM_PROCESSOR when CMAKE_GENERATOR is "Visual Studio ...". We can check for CMAKE_GENERATOR_PLATFORM and also fall back to trying to parse the Win64 from the end of the CMAKE_GENERATOR name. The logic should be added in CMakeDetermineSystem.cmake where we default to the host info.
Sorry, the "mentioned in issue" just above was an error on my part, it is not related to this one (seems gitlab remembers references even after you edit the comment).
Currently looking for guidance on ways to work around this difficulty, it's pretty rough to do in a general way. Any chance this will become an upstream priority?
After compiler probing, CMake does set CMAKE_CXX_COMPILER_ARCHITECTURE_ID (documented, but specifically mentioned as internal and subject to change) , and the undocumented MSVC_<lang>_ARCHITECTURE_ID and MSVC_CXX_ARCHITECTURE_FAMILY. And these do handle the ADM/ARM64/SHx architectures as well as just x86/x64. But this isn't detected in time to get into CMAKE_SYSTEM_PROCESSOR like they really should.
We can check for CMAKE_GENERATOR_PLATFORM and also fall back to trying to parse the Win64 from the end of the CMAKE_GENERATOR name
I can see how to implement that, but not how it solves anything when using a Ninja/JOM/NMake generator... Right now CMakeDetermine{C,CXX}Compiler picks MSVC, the decision really comes down to which set of compilers is in %PATH% (i.e. what vcvarsall invocation was used). So CMAKE_SYSTEM_PROCESSOR just really isn't known until picks a compiler to call and then works out which arch that's producing. Or I suppose you could go the other way, and have compiler-id detection error out if it turns out the cl chosen doesn't match CMAKE_SYSTEM_PROCESSOR (thus forcing users to set it via -ACMAKE_GENERATOR_PLATFORM even for generators where that doesn't actually do anything, just to keep things consistent.
And if doing that, maybe also change cmake-gui to offer a "with MSVC" radio button with the same arch dropdowns it shows for the msbuild generators, and use vswhere/vcvarsall around its invocation of CMake to actually get the requested arch.
An more robust workaround would be to use the existing compiler detection instead of hardcoding paths (e.g. I think your workaround would be broken with Visual Studio build tools)
That line is only for builds targeting WinCE. Also, in general MSVC_C_ARCHITECTURE_ID has not been computed at the time that line runs. I'm not sure it's correct, and may work only when the toolchain file sets MSVC_C_ARCHITECTURE_ID, which isn't typical usage.
#15170 (comment 226468) outlines a fundamental problem: we don't know the target platform of the toolchain at the time CMAKE_SYSTEM_PROCESSOR is supposed to be determined. We don't even know what compiler is to be used yet.
Add more heuristics to choosing CMAKE_SYSTEM_PROCESSOR. For VS generators we probably know what they are targeting pretty early. For command-line generators we expect the environment to be prepared for cl already, so we may be able to look for a hint in the environment.
Document this limitation of CMAKE_SYSTEM_PROCESSOR more explicitly. (EDIT: !5744 (merged) does this)
Yeap, I've seen that, but it's also werid, why need bind to C/CXX/ASM/RUST and so on,
Why we doesn't have things like
CMAKE_COMPILER_ARCHITECTURE_ID
That's weird, do we have the posiblity that
CMAKE_C_COMPILER_ARCHITECTURE_ID
CMAKE_CXX_COMPILER_ARCHITECTURE_ID
CMAKE_ASM_COMPILER_ARCHITECTURE_ID
CMAKE_RUST_COMPILER_ARCHITECTURE_ID
have different value?
So I think is is not a good alternative to CMAKE_SYSTEM_PROCESSOR
We do have CMAKE_SIZEOF_VOID_P, which is defined by taking our internal CMAKE_<LANG>_SIZEOF_DATA_PTR value computed from each toolchain, and just assuming they are all the same. It's defined once one language is enabled.
I think a CMAKE_COMPILER_ARCHITECTURE_ID or similar variable could be provided as soon as any CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID is available, but that would make sense only once the latter is defined for all compilers.
Maybe we need document that, so what's the proper value to replace CMAKE_SYSTEM_PROCESSOR, and what's the intension of CMAKE_SYSTEM_PROCESSOR?
CMake expose for CMAKE_SYSTEM_PROCESSOR for reason, right? If doesn't have any meaning, why expose that.
CMAKE_SYSTEM_PROCESSOR is well-defined on pretty much all platforms besides Windows, and is valid when defined by a toolchain file for cross-compiling.
Yeap, this issue is intent fixing CMAKE_SYSTEM_PROCESSOR on Windows. Make it usable, otherwise CMake user
always need consider Windows sperately when targeting windows.