Fixes and updates to BlueGene/Q support
[alexxy/gromacs.git] / cmake / Platform / BlueGeneQ-base.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
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.
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 #=============================================================================
36 # CMake - Cross Platform Makefile Generator
37 # Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
38 # Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
39 # Copyright 2012 Julien Bigot <julien.bigot@cea.fr>
40 # All rights reserved.
41 #
42 # Redistribution and use in source and binary forms, with or without
43 # modification, are permitted provided that the following conditions
44 # are met:
45 #
46 # * Redistributions of source code must retain the above copyright
47 #   notice, this list of conditions and the following disclaimer.
48 #
49 # * Redistributions in binary form must reproduce the above copyright
50 #   notice, this list of conditions and the following disclaimer in the
51 #   documentation and/or other materials provided with the distribution.
52 #
53 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
54 #   nor the names of their contributors may be used to endorse or promote
55 #   products derived from this software without specific prior written
56 #   permission.
57 #
58 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
59 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
60 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
61 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
62 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
63 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 #=============================================================================
70
71 #
72 # BlueGeneQ base platform file.
73 #
74 # NOTE: Do not set your platform to "BlueGeneQ-base".  This file is included
75 # by the real platform files.  Use one of these two platforms instead:
76 #
77 #     BlueGeneQ-dynamic  For dynamically linked builds
78 #     BlueGeneQ-static   For statically linked builds
79 #
80 # This platform file tries its best to adhere to the behavior of the MPI
81 # compiler wrappers included with the latest BG/Q drivers.
82 #
83
84
85 #
86 # For BG/Q builds, we're cross compiling, but we don't want to re-root things
87 # (e.g. with CMAKE_FIND_ROOT_PATH) because users may have libraries anywhere on
88 # the shared filesystems, and this may lie outside the root.  Instead, we set the
89 # system directories so that the various system BG/Q CNK library locations are
90 # searched first.  This is not the clearest thing in the world, given IBM's driver
91 # layout, but this should cover all the standard ones.
92 #
93 set(CMAKE_SYSTEM_LIBRARY_PATH
94   /bgsys/drivers/ppcfloor/comm/xl/lib                       # default comm layer (used by mpi compiler wrappers)
95   /bgsys/drivers/ppcfloor/spi/lib/                          # other low-level stuff
96   /bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/lib # CNK Linux image -- standard runtime libs, pthread, etc.
97 )
98
99 #
100 # This adds directories that find commands should specifically ignore for cross compiles.
101 # Most of these directories are the includeand lib directories for the frontend on BG/Q systems.
102 # Not ignoring these can cause things like FindX11 to find a frontend PPC version mistakenly.
103 # We use this on BG instead of re-rooting because backend libraries are typically strewn about
104 # the filesystem, and we can't re-root ALL backend libraries to a single place.
105 #
106 set(CMAKE_SYSTEM_IGNORE_PATH
107   /lib             /lib64             /include
108   /usr/lib         /usr/lib64         /usr/include
109   /usr/local/lib   /usr/local/lib64   /usr/local/include
110   /usr/X11/lib     /usr/X11/lib64     /usr/X11/include
111   /usr/lib/X11     /usr/lib64/X11     /usr/include/X11
112   /usr/X11R6/lib   /usr/X11R6/lib64   /usr/X11R6/include
113   /usr/X11R7/lib   /usr/X11R7/lib64   /usr/X11R7/include
114 )
115
116 #
117 # Indicate that this is a unix-like system
118 #
119 set(UNIX 1)
120
121 #
122 # Library prefixes, suffixes, extra libs.
123 #
124 set(CMAKE_LINK_LIBRARY_SUFFIX "")
125 set(CMAKE_STATIC_LIBRARY_PREFIX "lib")     # lib
126 set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")      # .a
127
128 set(CMAKE_SHARED_LIBRARY_PREFIX "lib")     # lib
129 set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")     # .so
130 set(CMAKE_EXECUTABLE_SUFFIX "")            # .exe
131 set(CMAKE_DL_LIBS "dl")
132
133 #
134 # This macro needs to be called for dynamic library support.  Unfortunately on BG/Q,
135 # We can't support both static and dynamic links in the same platform file.  The
136 # dynamic link platform file needs to call this explicitly to set up dynamic linking.
137 #
138 macro(__BlueGeneQ_set_dynamic_flags compiler_id lang)
139   if (${compiler_id} STREQUAL XL)
140     # Flags for XL compilers if we explicitly detected XL
141     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-qpic")
142     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-qmkshrobj -qnostaticlink")
143     set(BG/Q_${lang}_DYNAMIC_EXE_FLAGS                "-qnostaticlink -qnostaticlink=libgcc")
144   else()
145     # Assume flags for GNU compilers (if the ID is GNU *or* anything else).
146     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-fPIC")
147     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-shared")
148     set(BG/Q_${lang}_DYNAMIC_EXE_FLAGS                "-dynamic")
149   endif()
150
151   # Both toolchains use the GNU linker on BG/Q, so these options are shared.
152   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG      "-Wl,-rpath,")
153   set(CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG   "-Wl,-rpath-link,")
154   set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG       "-Wl,-soname,")
155   set(CMAKE_EXE_EXPORTS_${lang}_FLAG                 "-Wl,--export-dynamic")
156   set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS        "")  # +s, flag for exe link to use shared lib
157   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP  ":") # : or empty
158
159   set(BG/Q_${lang}_DEFAULT_EXE_FLAGS
160     "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
161   set(CMAKE_${lang}_LINK_EXECUTABLE
162     "<CMAKE_${lang}_COMPILER> ${BG/Q_${lang}_DYNAMIC_EXE_FLAGS} ${BG/Q_${lang}_DEFAULT_EXE_FLAGS}")
163 endmacro()
164
165 #
166 # This macro needs to be called for static builds.  Right now it just adds -Wl,-relax
167 # to the link line.
168 #
169 macro(__BlueGeneQ_set_static_flags compiler_id lang)
170   set(BG/Q_${lang}_DEFAULT_EXE_FLAGS
171     "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
172   set(CMAKE_${lang}_LINK_EXECUTABLE
173     "<CMAKE_${lang}_COMPILER> ${BG/Q_${lang}_DEFAULT_EXE_FLAGS}")
174
175   if(CMAKE_BUILD_TYPE MATCHES "Deb" AND ${compiler_id} STREQUAL "XL")
176       # Work around an unknown compiler bug triggered in
177       # compute_globals(). Using -O0 disables -qhot and this seems
178       # to break the normal OpenMP flag -qsmp unless qualified with
179       # noauto.
180       set(OpenMP_C_FLAGS "-qsmp=noauto" CACHE STRING "Compiler flag for OpenMP parallelization")
181       set(OpenMP_CXX_FLAGS "-qsmp=noauto" CACHE STRING "Compiler flag for OpenMP parallelization")
182   endif()
183
184 endmacro()