2018-05-19 16:42:03 +00:00
# (C) Copyright 2011- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
test_big_endian ( _BIG_ENDIAN )
if ( _BIG_ENDIAN )
set ( ECCODES_BIG_ENDIAN 1 )
set ( ECCODES_LITTLE_ENDIAN 0 )
else ( )
set ( ECCODES_BIG_ENDIAN 0 )
set ( ECCODES_LITTLE_ENDIAN 1 )
endif ( )
2018-05-21 11:45:12 +00:00
set ( ECCODES_BIG_ENDIAN ${ ECCODES_BIG_ENDIAN } )
set ( ECCODES_LITTLE_ENDIAN ${ ECCODES_LITTLE_ENDIAN } )
2018-05-19 16:42:03 +00:00
if ( NOT DEFINED IEEE_BE )
check_c_source_runs (
" i n t compare ( unsigned char* a,unsigned char* b ) {
while ( *a != 0 ) if ( *(b++ ) ! = * ( a + + ) ) r e t u r n 1 ;
r e t u r n 0 ;
}
i n t main ( int argc,char** argv ) {
u n s i g n e d c h a r d c [ ] = { 0 x 3 0 , 0 x 6 1 , 0 x D E , 0 x 8 0 , 0 x 9 3 , 0 x 6 7 , 0 x C C , 0 x D 9 , 0 } ;
d o u b l e d a = 1 . 2 3 4 5 6 7 8 9 e - 7 5 ;
u n s i g n e d c h a r * c a ;
u n s i g n e d c h a r f c [ ] = { 0 x 0 5 , 0 x 8 3 , 0 x 4 8 , 0 x 2 2 , 0 } ;
f l o a t f a = 1 . 2 3 4 5 6 7 8 9 e - 3 5 ;
if ( sizeof(double ) ! = 8 ) r e t u r n 1 ;
c a = ( u n s i g n e d c h a r * ) & d a ;
if ( compare(dc,ca ) ) r e t u r n 1 ;
if ( sizeof(float ) ! = 4 ) r e t u r n 1 ;
c a = ( u n s i g n e d c h a r * ) & f a ;
if ( compare(fc,ca ) ) r e t u r n 1 ;
r e t u r n 0 ;
} " I E E E _ B E )
if ( "${IEEE_BE}" STREQUAL "" )
set ( IEEE_BE 0 CACHE INTERNAL "Test IEEE_BE" )
endif ( )
endif ( )
if ( ECCODES_BIG_ENDIAN AND NOT IEEE_BE )
2019-01-07 16:13:48 +00:00
ecbuild_critical ( "Failed to sanity check on endiness: OS should be Big-Endian but compiled code runs differently -- to ignore this pass -DIEEE_BE=1 to CMake/ecBuild" )
2018-05-19 16:42:03 +00:00
endif ( )
if ( NOT DEFINED IEEE_LE )
check_c_source_runs (
" i n t compare ( unsigned char* a,unsigned char* b ) {
while ( *a != 0 ) if ( *(b++ ) ! = * ( a + + ) ) r e t u r n 1 ;
r e t u r n 0 ;
}
i n t main ( int argc,char** argv ) {
u n s i g n e d c h a r d c [ ] = { 0 x D 9 , 0 x C C , 0 x 6 7 , 0 x 9 3 , 0 x 8 0 , 0 x D E , 0 x 6 1 , 0 x 3 0 , 0 } ;
d o u b l e d a = 1 . 2 3 4 5 6 7 8 9 e - 7 5 ;
u n s i g n e d c h a r * c a ;
u n s i g n e d c h a r f c [ ] = { 0 x 2 2 , 0 x 4 8 , 0 x 8 3 , 0 x 0 5 , 0 } ;
f l o a t f a = 1 . 2 3 4 5 6 7 8 9 e - 3 5 ;
if ( sizeof(double ) ! = 8 ) r e t u r n 1 ;
c a = ( u n s i g n e d c h a r * ) & d a ;
if ( compare(dc,ca ) ) r e t u r n 1 ;
if ( sizeof(float ) ! = 4 ) r e t u r n 1 ;
c a = ( u n s i g n e d c h a r * ) & f a ;
if ( compare(fc,ca ) ) r e t u r n 1 ;
r e t u r n 0 ;
} " I E E E _ L E )
if ( "${IEEE_LE}" STREQUAL "" )
set ( IEEE_LE 0 CACHE INTERNAL "Test IEEE_LE" )
endif ( )
endif ( )
if ( ECCODES_LITTLE_ENDIAN AND NOT IEEE_LE )
2019-01-07 16:13:48 +00:00
ecbuild_critical ( "Failed to sanity check on endiness: OS should be Little-Endian but compiled code runs differently -- to ignore this pass -DIEEE_LE=1 to CMake/ecBuild" )
2018-05-19 16:42:03 +00:00
endif ( )