[CMake] Finding out the Endianness of a system at CMake config time

Stephan Tolksdorf andorxor at gmx.de
Thu Nov 23 04:27:52 EST 2006


Sean McBride wrote:
> 
> Remember that using TRY_COMPILE/TRY_RUN or any method that runs code on
> the build machine breaks cross-compilation. 
(...)
> 
> Since a compiler knows what CPU it is compiling for (by definition), I
> think a better solution, in general, is to query the compiler. 

See Boost's detail/endian.hpp for a rather complete endianess detection 
at compile time. Note that some CPUs are switchable between and Little 
and Big Endian, so one has to look at the combination of the (target) OS 
and CPU to determine endianess:

http://boost.cvs.sourceforge.net/boost/boost/boost/detail/endian.hpp

Regards,
   Stephan


More information about the CMake mailing list