2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012,2013, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
35 # - Define macro to determine floating point format properties
37 # GMX_TEST_FLOAT_FORMAT(FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)
39 # The thee variables are set to true when:
40 # FP_IEEE754 Floating-point numbers are stored in IEEE754 format
41 # FP_BIG_ENDIAN_BYTE The order of bytes in each FP word (4 bytes) is big endian
42 # FP_BIG_ENDIAN_WORD The order of FP words in double precision dwords (2 words) is big endian
44 # On *most* platforms the two last tests will be the same as the integer endian,
45 # big e.g. ARM processors have different byte/word order for floating-point storage,
46 # so we figured it is a good idea to test both before relying on the format.
48 MACRO(GMX_TEST_FLOAT_FORMAT FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)
49 IF(NOT DEFINED HAVE_${FP_IEEE754})
50 MESSAGE(STATUS "Checking floating point format")
52 TRY_COMPILE(HAVE_${FP_IEEE754} "${CMAKE_BINARY_DIR}"
53 "${CMAKE_SOURCE_DIR}/cmake/TestFloatFormat.c"
54 COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin")
56 if(HAVE_${FP_IEEE754})
58 # dont match first/last letter because of string rounding errors :-)
59 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
60 GMX_IEEE754_BB_BW LIMIT_COUNT 1 REGEX "ROMACS")
61 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
62 GMX_IEEE754_BB_LW LIMIT_COUNT 1 REGEX "CSXGRO")
63 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
64 GMX_IEEE754_LB_BW LIMIT_COUNT 1 REGEX "ORGXSC")
65 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
66 GMX_IEEE754_LB_LW REGEX "SCAMOR")
67 FILE(STRINGS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin"
68 GMX_IEEE754 REGEX "GROMACS|CSXGRO|ORGXSC|SCAMOR")
70 # OS X Universal binaries will contain both strings, set it to the host
71 IF(GMX_IEEE754_BB_BW AND GMX_IEEE754_LB_LW)
72 IF(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
73 SET(GMX_IEEE754_BB_BW TRUE)
74 SET(GMX_IEEE754_LB_LW FALSE)
75 ELSE(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
76 SET(GMX_IEEE754_BB_BW FALSE)
77 SET(GMX_IEEE754_LB_LW TRUE)
78 ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES powerpc)
79 MESSAGE(STATUS "GMX_TEST_IEEE754_FORMAT found different results, consider setting CMAKE_OSX_ARCHITECTURES or CMAKE_TRY_COMPILE_OSX_ARCHITECTURES to one or no architecture !")
80 ENDIF(GMX_IEEE754_BB_BW AND GMX_IEEE754_LB_LW)
83 SET(${FP_IEEE754} 1 CACHE INTERNAL "Result of test for IEEE754 FP format" FORCE)
86 IF(GMX_IEEE754_BB_BW OR GMX_IEEE754_BB_LW)
87 SET(${FP_BIG_ENDIAN_BYTE} 1 CACHE INTERNAL "Result of test for big endian FP byte order" FORCE)
88 ENDIF(GMX_IEEE754_BB_BW OR GMX_IEEE754_BB_LW)
90 IF(GMX_IEEE754_BB_BW OR GMX_IEEE754_LB_BW)
91 SET(${FP_BIG_ENDIAN_WORD} 1 CACHE INTERNAL "Result of test for big endian FP word order" FORCE)
92 ENDIF(GMX_IEEE754_BB_BW OR GMX_IEEE754_LB_BW)
94 endif(HAVE_${FP_IEEE754})
96 # just some informational output for the user
98 MESSAGE(STATUS "Checking floating point format - IEEE754 (BE byte, BE word)")
99 elseif(GMX_IEEE754_BB_LW)
100 MESSAGE(STATUS "Checking floating point format - IEEE754 (BE byte, LE word)")
101 elseif(GMX_IEEE754_LB_BW)
102 MESSAGE(STATUS "Checking floating point format - IEEE754 (LE byte, BE word)")
103 elseif(GMX_IEEE754_LB_LW)
104 MESSAGE(STATUS "Checking floating point format - IEEE754 (LE byte, LE word)")
105 else(GMX_IEEE754_LB_LW)
106 MESSAGE(STATUS "Checking floating point format - unknown")
107 endif(GMX_IEEE754_BB_BW)
108 ENDIF(NOT DEFINED HAVE_${FP_IEEE754})
109 ENDMACRO(GMX_TEST_FLOAT_FORMAT FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)