2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2013,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.
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 # Helper routine to find flag (from a list) to compile a specific C source.
36 # VARIABLE This will be set when we have found a flag that works
37 # DESCRIPTION Text string describing what flag we are trying to find
38 # SOURCE Source code to test
39 # The compiler is chosen based on the extension of this file
40 # FLAGSVAR Variable (string) to which we should add the correct flag
41 # Args 5 through N Multiple strings with acceleration flags to test
42 FUNCTION(GMX_FIND_CFLAG_FOR_SOURCE VARIABLE DESCRIPTION SOURCE CFLAGSVAR)
43 IF(NOT DEFINED ${VARIABLE})
44 # Insert a blank element last in the list (try without any flags too)
45 # This must come last, since some compilers (Intel) might try to emulate
46 # emulate AVX instructions with SSE4.1 otherwise.
47 foreach(_testflag ${ARGN} "")
48 message(STATUS "Try ${DESCRIPTION} = [${_testflag}]")
49 set(CMAKE_REQUIRED_FLAGS "${${CFLAGSVAR}} ${_testflag}")
50 # make a valid variable name from the flag string: replace all non-alphanumerical chars
51 string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_VARIABLE "C_FLAG_${_testflag}")
52 check_c_source_compiles("${SOURCE}" ${COMPILE_VARIABLE})
53 if(${${COMPILE_VARIABLE}})
54 set(${VARIABLE}_FLAG "${_testflag}" CACHE INTERNAL "${DESCRIPTION}")
55 set(${VARIABLE} 1 CACHE INTERNAL "Result of test for ${DESCRIPTION}" FORCE)
57 else(${${COMPILE_VARIABLE}})
58 set(${VARIABLE} 0 CACHE INTERNAL "Result of test for ${DESCRIPTION}" FORCE)
59 endif(${${COMPILE_VARIABLE}})
61 ENDIF(NOT DEFINED ${VARIABLE})
63 SET (${CFLAGSVAR} "${${CFLAGSVAR}} ${${VARIABLE}_FLAG}" PARENT_SCOPE)
65 ENDFUNCTION(GMX_FIND_CFLAG_FOR_SOURCE VARIABLE DESCRIPTION SOURCE CFLAGSVAR)
68 # Helper routine to find flag (from list) to compile a specific C++ source.
69 # VARIABLE This will be set when we have found a flag that works
70 # DESCRIPTION Text string describing what flag we are trying to find
71 # SOURCE Source code to test
72 # The compiler is chosen based on the extension of this file
73 # FLAGSVAR Variable (string) to which we should add the correct flag
74 # Args 5 through N Multiple strings with acceleration flags to test
75 FUNCTION(GMX_FIND_CXXFLAG_FOR_SOURCE VARIABLE DESCRIPTION SOURCE CXXFLAGSVAR)
76 IF(NOT DEFINED ${VARIABLE})
77 # Insert a blank element last in the list (try without any flags too)
78 # This must come last, since some compilers (Intel) might try to
79 # emulate AVX instructions with SSE4.1 otherwise.
80 foreach(_testflag ${ARGN} "")
81 message(STATUS "Try ${DESCRIPTION} = [${_testflag}]")
82 set(CMAKE_REQUIRED_FLAGS "${${CXXFLAGSVAR}} ${_testflag}")
83 # make a valid variable name from the flag string: replace all non-alphanumerical chars
84 string(REGEX REPLACE "[^a-zA-Z0-9]+" "_" COMPILE_VARIABLE "CXX_FLAG_${_testflag}")
85 check_cxx_source_compiles("${SOURCE}" ${COMPILE_VARIABLE})
86 if(${${COMPILE_VARIABLE}})
87 set(${VARIABLE}_FLAG "${_testflag}" CACHE INTERNAL "${DESCRIPTION}")
88 set(${VARIABLE} 1 CACHE INTERNAL "Result of test for ${DESCRIPTION}" FORCE)
90 else(${${COMPILE_VARIABLE}})
91 set(${VARIABLE} 0 CACHE INTERNAL "Result of test for ${DESCRIPTION}" FORCE)
92 endif(${${COMPILE_VARIABLE}})
94 ENDIF(NOT DEFINED ${VARIABLE})
96 SET (${CXXFLAGSVAR} "${${CXXFLAGSVAR}} ${${VARIABLE}_FLAG}" PARENT_SCOPE)
98 ENDFUNCTION(GMX_FIND_CXXFLAG_FOR_SOURCE VARIABLE DESCRIPTION SOURCE CXXFLAGSVAR)