Skip to content

CSharp: fix (unused) compiler arch detection, and default /platform flag choice

Fix #23573, and at least some part of #17521 (which mentions the same symptoms).

There is an ongoing discussion under #23513 related to these issues (but with a wider scope). The (minor) fixes proposed here should not interfere with the solutions discussed there, but might rather be a part of those.

CMakeCSharpCompilerId: Original (misspelled) code did report "INFO:arch[unknown]" for anything but x64; irrelevant only as long as that result was not actually used. Fix this: the next one who wants to find out what goes wrong should not waste time with these lines.

CMakeCSharpInformation: Unless replaced by something totally different (as discussed under #23513), this file forces some /platform:... flag into the initial CMAKE_CSharp_FLAGS cache value. (Possibly confusing because this is undocumented, and an unexperienced user might not even be aware of the "advanced" cache variable).
The platform choice done there is broken (as already mentioned in #23573) because relying on CMAKE_SIZEOF_VOID_P does not make too much sense with C# (the variable is undefined unless provided by another language enabled prior to C#).
Fix by rewriting based on CMAKE_VS_PLATFORM_NAME. Doing so does change (undocumented) behaviour – but brings it closer to the suggestions from #23513, and to the principle of least surprise.

Merge request reports