dd17ab682b9d018320ead98293753768aa22ea9c
[alexxy/gromacs.git] / cmake / Platform / BlueGeneQ-base.cmake
1
2 #=============================================================================
3 # Copyright 2010 Kitware, Inc.
4 # Copyright 2010 Todd Gamblin <tgamblin@llnl.gov>
5 # Copyright 2012 Julien Bigot <julien.bigot@cea.fr>
6 #
7 # Distributed under the OSI-approved BSD License (the "License");
8 # see accompanying file Copyright.txt for details.
9 #
10 # This software is distributed WITHOUT ANY WARRANTY; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 # See the License for more information.
13 #=============================================================================
14 # (To distribute this file outside of CMake, substitute the full
15 #  License text for the above reference.)
16
17 #
18 # BlueGeneQ base platform file.
19 #
20 # NOTE: Do not set your platform to "BlueGeneQ-base".  This file is included
21 # by the real platform files.  Use one of these two platforms instead:
22 #
23 #     BlueGeneQ-dynamic  For dynamically linked builds
24 #     BlueGeneQ-static   For statically linked builds
25 #
26 # This platform file tries its best to adhere to the behavior of the MPI
27 # compiler wrappers included with the latest BG/Q drivers.
28 #
29
30
31 #
32 # For BG/Q builds, we're cross compiling, but we don't want to re-root things
33 # (e.g. with CMAKE_FIND_ROOT_PATH) because users may have libraries anywhere on
34 # the shared filesystems, and this may lie outside the root.  Instead, we set the
35 # system directories so that the various system BG/Q CNK library locations are
36 # searched first.  This is not the clearest thing in the world, given IBM's driver
37 # layout, but this should cover all the standard ones.
38 #
39 set(CMAKE_SYSTEM_LIBRARY_PATH
40   /bgsys/drivers/ppcfloor/comm/xl/lib                       # default comm layer (used by mpi compiler wrappers)
41   /bgsys/drivers/ppcfloor/spi/lib/                          # other low-level stuff
42   /bgsys/drivers/ppcfloor/gnu-linux/powerpc64-bgq-linux/lib # CNK Linux image -- standard runtime libs, pthread, etc.
43 )
44
45 #
46 # This adds directories that find commands should specifically ignore for cross compiles.
47 # Most of these directories are the includeand lib directories for the frontend on BG/Q systems.
48 # Not ignoring these can cause things like FindX11 to find a frontend PPC version mistakenly.
49 # We use this on BG instead of re-rooting because backend libraries are typically strewn about
50 # the filesystem, and we can't re-root ALL backend libraries to a single place.
51 #
52 set(CMAKE_SYSTEM_IGNORE_PATH
53   /lib             /lib64             /include
54   /usr/lib         /usr/lib64         /usr/include
55   /usr/local/lib   /usr/local/lib64   /usr/local/include
56   /usr/X11/lib     /usr/X11/lib64     /usr/X11/include
57   /usr/lib/X11     /usr/lib64/X11     /usr/include/X11
58   /usr/X11R6/lib   /usr/X11R6/lib64   /usr/X11R6/include
59   /usr/X11R7/lib   /usr/X11R7/lib64   /usr/X11R7/include
60 )
61
62 #
63 # Indicate that this is a unix-like system
64 #
65 set(UNIX 1)
66
67 #
68 # Library prefixes, suffixes, extra libs.
69 #
70 set(CMAKE_LINK_LIBRARY_SUFFIX "")
71 set(CMAKE_STATIC_LIBRARY_PREFIX "lib")     # lib
72 set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")      # .a
73
74 set(CMAKE_SHARED_LIBRARY_PREFIX "lib")     # lib
75 set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")     # .so
76 set(CMAKE_EXECUTABLE_SUFFIX "")            # .exe
77 set(CMAKE_DL_LIBS "dl")
78
79 #
80 # This macro needs to be called for dynamic library support.  Unfortunately on BG/Q,
81 # We can't support both static and dynamic links in the same platform file.  The
82 # dynamic link platform file needs to call this explicitly to set up dynamic linking.
83 #
84 macro(__BlueGeneQ_set_dynamic_flags compiler_id lang)
85   if (${compiler_id} STREQUAL XL)
86     # Flags for XL compilers if we explicitly detected XL
87     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-qpic")
88     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-qmkshrobj -qnostaticlink")
89     set(BG/Q_${lang}_DYNAMIC_EXE_FLAGS                "-qnostaticlink -qnostaticlink=libgcc")
90   else()
91     # Assume flags for GNU compilers (if the ID is GNU *or* anything else).
92     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-fPIC")
93     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-shared")
94     set(BG/Q_${lang}_DYNAMIC_EXE_FLAGS                "-dynamic")
95   endif()
96
97   # Both toolchains use the GNU linker on BG/Q, so these options are shared.
98   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG      "-Wl,-rpath,")
99   set(CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG   "-Wl,-rpath-link,")
100   set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG       "-Wl,-soname,")
101   set(CMAKE_EXE_EXPORTS_${lang}_FLAG                 "-Wl,--export-dynamic")
102   set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS        "")  # +s, flag for exe link to use shared lib
103   set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP  ":") # : or empty
104
105   set(BG/Q_${lang}_DEFAULT_EXE_FLAGS
106     "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
107   set(CMAKE_${lang}_LINK_EXECUTABLE
108     "<CMAKE_${lang}_COMPILER> ${BG/Q_${lang}_DYNAMIC_EXE_FLAGS} ${BG/Q_${lang}_DEFAULT_EXE_FLAGS}")
109 endmacro()
110
111 #
112 # This macro needs to be called for static builds.  Right now it just adds -Wl,-relax
113 # to the link line.
114 #
115 macro(__BlueGeneQ_set_static_flags compiler_id lang)
116   set(BG/Q_${lang}_DEFAULT_EXE_FLAGS
117     "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
118   set(CMAKE_${lang}_LINK_EXECUTABLE
119     "<CMAKE_${lang}_COMPILER> ${BG/Q_${lang}_DEFAULT_EXE_FLAGS}")
120 endmacro()