CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID is currently computed in Modules/CMakePlatformId.h.in during compiler identification for MSVC-like compilers and maybe a couple others. This works only for compilers where the choice of compiler tool determines the target architecture and no compiler flags can change it. It is needed very early for MSVC in order to know the proper -machine: linker argument for later try_compile checks and such.
It may be useful to provide information about the target architecture everywhere. For other compilers it could be detected in Modules/CMakeCompilerABI.h, which is built using the full set of flags that will be used for project code. We already detect sizeof(void*) there.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
I just put up a WIP merge request, which appears to implement the suggested approach given here.
I'm not sure what a good source of architecture macros and names is. I used mostly https://sourceforge.net/p/predef/wiki/Architectures/ for the macros, and used the same names as Modules/CMakePlatformId.h.in.
I also haven't checked any platforms except x64 on Windows under mingw64 (MSYS2), and the unit test only checks that something is defined, not whether it's the right name.
I'm open to feedback, and have no specific plans to iterate beyond this point, without access to a lot of random hardware or cross-compilers.
I think we can stablize it by force CMAKE_C_COMPILER_ARCHITECTURE_ID to be an valid value,
that's is CMAKE_C_COMPILER_ARCHITECTURE_ID should be oneOf
[
'X86',
'x64',
'TMS320C6x',
'PPC64',
and son on
]
So the user would not mis - define it.
And also user can proved
CMAKE_C_COMPILER_EXTRA_ARCHITECTURES to define other
possible architectures to validate the CMAKE_C_COMPILER_ARCHITECTURE_ID for extension.
Is this the preferred, if under-documented, way to detect architecture for the compiled binaries on MSVC? It appears that CMAKE_SYSTEM_PROCESSOR is somewhat useless with MSVC: the ARM64 toolchain reports AMD64.
Or, can we consider that a bug, since I would be using CMAKE_SYSTEM_PROCESSOR on all other platforms?
See #15170 about CMAKE_SYSTEM_PROCESSOR on Windows. Basically the problem is we don't know the target architecture until at least one language is enabled so we can detect what its compiler does, but by then CMAKE_SYSTEM_PROCESSOR is already determined.
CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID is language-specific and so does not have that problem, but it is only reliably defined with MSVC right now. For MSVC, it is the preferred way.
If CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID (guessing you meant with the _ID suffix?) is the preferred way to detect the architecture with MSVC, can that be documented? The documentation right now says it is "[a]n internal variable subject to change", but that it is needed "[f]or some compilers".
And then CMAKE_SYSTEM_PROCESSOR's documentation just says it's usable "[i]n many cases", cites MSVC as a case where it doesn't work, but says nothing about what to use instead.
I work on a project (BoringSSL) that needs architecture-specific code, and all these quirks make CMake very difficult to use for us. I eventually figured out what was going on by trawling the bug tracker, but ideally that'd just be in the documentation. Perhaps, in advance of CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID being made consistently available, the documentation could at least specify its relationship with MSVC? Then CMake users will at least know they need to special-case MSVC and how to do it.