PCSX2/pcsx2 — pull request #411 by micove (2014-12-25 03:29:16+00:00)
Title: Improve Cross Compilation.

Cross compilation is kind of wonky currently since the architecture of the HOST is used to dictate what happens. It should actually not care about the host architecture at all and more about if the tool chain used is configured for a TARGET architecture we support. If the user wants to do a arm -> i386, or sparc64 -> i386 and they have the means to do it then let them. Those cases are unlikely but demonstrate that the current cmake code does not scale really well and weird stuff happens it one tries to cross compile i386 -> amd64 .

The first thing we need is a method to get the TARGET architecture accurately.To accomplish this we need to use something besides CMAKE_HOST_SYSTEM_PROCESSOR and CMAKE_SYSTEM_PROCESSOR since they are incredibly broken and unreliable. A simple try_run with the compiler used does the trick. It include support for apple so it should help pull request #297 if they concentrate on the 32bit first since they implemented POSIX AIO.

The rest is simple using the provided CMAKE_TOOLCHAIN_FILE or --cross-multilib the distros that use multilib cross compilation can add the option and it should work as before. Since CMAKE_TOOLCHAIN_FILE sets the TARGET architecture therefore unlike before now cmake knows that we are building for i386 and none of the hacks to force /usr/lib32 or /usr/i386-linux-gnu should be needed.

By default native compilations are done and since we want to block native amd64 the same block as before is done while dropping the old deprecated option.

I tested:
- native amd64 build and it gets blocked by FATAL_ERROR as desired.
- native i386 and it works
- cross build amd64 -> i386 and it works
- cross build i386 -> i386 and it works.
- native arm and it gets blocked by FATAL_ERROR as desired.

Note: If distros are lazy they can always set --cross-multilib and it should build fine for both amd64 and i386.

As usual commit messages are quite verbose and I feel like I'm rambling now.

References:
http://www.vtk.org/Wiki/CMake_Cross_Compiling
http://www.cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html

As an addendum:
Debian/Ubuntu may need a bump of the required cmake version. I tested this with 3.0.2 and I know almost all version since 2.8.5 had fixes for multiarch. It could be done at the package level (control file) since it's distro specific. I will build the package on precise (2.8.7) and utopic (2.8.12.2) to see how it goes.