Make CMAKE_CROSSCOMPILING a reliable indicator of cross-compilation
CMAKE_CROSSCOMPILING
is a notoriously misleading variable. Quite reasonably, people expect it to mean what its name says, but these days it is frequently wrong. On Apple platforms, it is essentially useless. I'd like to propose that we address this and once more make it give a value of true if we are in fact cross-compiling, regardless of the platform.
It may be tricky to protect such a change with a policy, since the variable is set once at the top level (first project()
call) so other parts of the build won't have a say in what policy setting they expect. This matters more for hierarchical projects using FetchContent
or git submodules, for instance. Conversely, projects that would be affected by such a change would likely already not be relying on this variable alone anyway due to the way it lies to you.
I've lost count of the number of times I've seen projects misusing this variable, mostly out of not realising its caveats or how it derives its value.