2 # This file is part of the GROMACS molecular simulation package.
4 # Copyright (c) 2012, 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 # - Finds OpenMP support
36 # Copied from cmake 2.8.7 prior versions were assuming C++
37 # compiler is enabled. Can be removed when 2.8.7 becomes
38 # required or C++ becomes required.
40 # This module can be used to detect OpenMP support in a compiler.
41 # If the compiler supports OpenMP, the flags required to compile with
42 # openmp support are set.
44 # The following variables are set:
45 # OpenMP_C_FLAGS - flags to add to the C compiler for OpenMP support
46 # OpenMP_CXX_FLAGS - flags to add to the CXX compiler for OpenMP support
47 # OPENMP_FOUND - true if openmp is detected
49 # Supported compilers can be found at http://openmp.org/wp/openmp-compilers/
51 #=============================================================================
52 # Copyright 2009 Kitware, Inc.
53 # Copyright 2008-2009 André Rigland Brodtkorb <Andre.Brodtkorb@ifi.uio.no>
54 # Copyright 2012 Rolf Eike Beer <eike@sf-mail.de>
56 # Distributed under the OSI-approved BSD License (the "License");
57 # see accompanying file Copyright.txt for details.
59 # This software is distributed WITHOUT ANY WARRANTY; without even the
60 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
61 # See the License for more information.
62 #=============================================================================
63 # (To distribute this file outside of CMake, substitute the full
64 # License text for the above reference.)
66 set(_OPENMP_REQUIRED_VARS)
68 function(_OPENMP_FLAG_CANDIDATES LANG)
69 set(OpenMP_FLAG_CANDIDATES
72 #Microsoft Visual Studio
78 #Empty, if compiler automatically accepts openmp
86 #Portland Group, MIPSpro
90 set(OMP_FLAG_GNU "-fopenmp")
91 set(OMP_FLAG_HP "+Oopenmp")
93 set(OMP_FLAG_Intel "-Qopenmp")
95 set(OMP_FLAG_Intel "-openmp")
97 set(OMP_FLAG_MIPSpro "-mp")
98 set(OMP_FLAG_MSVC "/openmp")
99 set(OMP_FLAG_PathScale "-openmp")
100 set(OMP_FLAG_PGI "-mp")
101 set(OMP_FLAG_SunPro "-xopenmp")
102 set(OMP_FLAG_XL "-qsmp")
104 # Move the flag that matches the compiler to the head of the list,
105 # this is faster and doesn't clutter the output that much. If that
106 # flag doesn't work we will still try all.
107 if(OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID})
108 list(REMOVE_ITEM OpenMP_FLAG_CANDIDATES "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}")
109 list(INSERT OpenMP_FLAG_CANDIDATES 0 "${OMP_FLAG_${CMAKE_${LANG}_COMPILER_ID}}")
112 set(OpenMP_${LANG}_FLAG_CANDIDATES "${OpenMP_FLAG_CANDIDATES}" PARENT_SCOPE)
113 endfunction(_OPENMP_FLAG_CANDIDATES)
115 # sample openmp source code to test
116 set(OpenMP_C_TEST_SOURCE
129 if(CMAKE_C_COMPILER_LOADED)
130 # if these are set then do not try to find them again,
131 # by avoiding any try_compiles for the flags
133 unset(OpenMP_C_FLAG_CANDIDATES)
135 _OPENMP_FLAG_CANDIDATES("C")
136 include(CheckCSourceCompiles)
139 foreach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
140 set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
141 set(CMAKE_REQUIRED_FLAGS "${FLAG}")
142 unset(OpenMP_FLAG_DETECTED CACHE)
143 message(STATUS "Try OpenMP C flag = [${FLAG}]")
144 check_c_source_compiles("${OpenMP_C_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
145 set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
146 if(OpenMP_FLAG_DETECTED)
147 set(OpenMP_C_FLAGS_INTERNAL "${FLAG}")
149 endif(OpenMP_FLAG_DETECTED)
150 endforeach(FLAG ${OpenMP_C_FLAG_CANDIDATES})
152 set(OpenMP_C_FLAGS "${OpenMP_C_FLAGS_INTERNAL}"
153 CACHE STRING "C compiler flags for OpenMP parallization")
155 list(APPEND _OPENMP_REQUIRED_VARS OpenMP_C_FLAGS)
156 unset(OpenMP_C_FLAG_CANDIDATES)
160 if(CMAKE_CXX_COMPILER_LOADED)
161 # if these are set then do not try to find them again,
162 # by avoiding any try_compiles for the flags
164 unset(OpenMP_CXX_FLAG_CANDIDATES)
166 _OPENMP_FLAG_CANDIDATES("CXX")
167 include(CheckCXXSourceCompiles)
169 # use the same source for CXX as C for now
170 set(OpenMP_CXX_TEST_SOURCE ${OpenMP_C_TEST_SOURCE})
173 foreach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
174 set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
175 set(CMAKE_REQUIRED_FLAGS "${FLAG}")
176 unset(OpenMP_FLAG_DETECTED CACHE)
177 message(STATUS "Try OpenMP CXX flag = [${FLAG}]")
178 check_cxx_source_compiles("${OpenMP_CXX_TEST_SOURCE}" OpenMP_FLAG_DETECTED)
179 set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
180 if(OpenMP_FLAG_DETECTED)
181 set(OpenMP_CXX_FLAGS_INTERNAL "${FLAG}")
183 endif(OpenMP_FLAG_DETECTED)
184 endforeach(FLAG ${OpenMP_CXX_FLAG_CANDIDATES})
186 set(OpenMP_CXX_FLAGS "${OpenMP_CXX_FLAGS_INTERNAL}"
187 CACHE STRING "C++ compiler flags for OpenMP parallization")
189 list(APPEND _OPENMP_REQUIRED_VARS OpenMP_CXX_FLAGS)
190 unset(OpenMP_CXX_FLAG_CANDIDATES)
191 unset(OpenMP_CXX_TEST_SOURCE)
194 if(_OPENMP_REQUIRED_VARS)
195 include(FindPackageHandleStandardArgs)
197 find_package_handle_standard_args(OpenMP
198 REQUIRED_VARS ${_OPENMP_REQUIRED_VARS})
200 mark_as_advanced(${_OPENMP_REQUIRED_VARS})
202 unset(_OPENMP_REQUIRED_VARS)
204 message(SEND_ERROR "FindOpenMP requires C or CXX language to be enabled")