Add initial support for python bindings
[alexxy/gromacs.git] / cmake / gmxTestFloatFormat.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2009,2014, by the GROMACS development team, led by
5 # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 # and including many others, as listed in the AUTHORS file in the
7 # top-level source directory and at http://www.gromacs.org.
8 #
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.
13 #
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.
18 #
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.
23 #
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.
31 #
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.
34
35 # - Define macro to determine floating point format properties
36 #
37 #  GMX_TEST_FLOAT_FORMAT(FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)
38 #
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
43 #
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.
47
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")
51
52         TRY_COMPILE(HAVE_${FP_IEEE754} "${CMAKE_BINARY_DIR}"    
53                     "${CMAKE_SOURCE_DIR}/cmake/TestFloatFormat.cpp"
54                     COPY_FILE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/TestFloatFormat.bin")  
55
56         if(HAVE_${FP_IEEE754})
57
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")
69
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()
76                     SET(GMX_IEEE754_BB_BW FALSE)
77                     SET(GMX_IEEE754_LB_LW TRUE)
78                 ENDIF()
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()
81
82             IF(GMX_IEEE754)
83                 SET(${FP_IEEE754} 1 CACHE INTERNAL "Result of test for IEEE754 FP format" FORCE)
84             ENDIF()
85
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()
89
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()
93
94         endif()
95
96         # just some informational output for the user
97         if(GMX_IEEE754_BB_BW)
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()
106             MESSAGE(STATUS "Checking floating point format - unknown")
107             MESSAGE(WARNING "Cannot detect your floating-point format. It is extremely unlikely to be anything else than IEEE754, but if we do not know the endian we need to rely on your OS providing the math functions erfd() and erfcd() rather than using our built-in ones.")
108         endif()
109     ENDIF()
110 ENDMACRO(GMX_TEST_FLOAT_FORMAT FP_IEEE754 FP_BIG_ENDIAN_BYTE FP_BIG_ENDIAN_WORD)
111
112
113