Debian Codegraph @

doc/developers/porting.html

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "https://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <title>Porting deal.II</title>
6 <link href="../screen.css" rel="StyleSheet" media="screen">
7 <meta name="copyright" content="Copyright (C) 2000 - 2023 by the deal.II Authors">
8 <meta name="keywords" content="deal.II porting">
9 </head>
10
11 <body>
12
13
14 <h1>Porting <acronym>deal.II</acronym> to new systems</h1>
15
16 <p>
17 <acronym>deal.II</acronym> uses very few
18 <a href="https://www.opengroup.org/austin/">POSIX</a> specific system
19 features and is otherwise fairly ISO (2011) C++ Standard compliant.
20
21 Consequently, there is a good chance that <acronym>deal.II</acronym>
22 will run on a reasonably well behaved system besides the ones listed
23 in the <a href="../readme.html" target="body">ReadMe</a>. Nevertheless,
24 there are cases where some adjustments are necessary.
25 </p>
26
27 <h2>Unknown compiler</h2>
28
29 <p>
30 Currently, the <acronym>deal.II</acronym> CMake build system
31 recognizes
32 <a href="https://gcc.gnu.org/">gcc</a>,
33 <a href="https://clang.llvm.org/">clang</a>, as well as
34 <a href="https://software.intel.com/en-us/intel-compilers">icc</a>, and
35 sets up reasonable default compiler flags.
36 <ul>
37 <li>
38 To start porting to an unknown compiler, specify all
39 necessary compiler flags by hand via
40 <pre>
41 DEAL_II_CXX_FLAGS - used during all builds
42 DEAL_II_CXX_FLAGS_DEBUG - additional flags for the debug library
43 DEAL_II_CXX_FLAGS_RELEASE - additional flags for the release library
44 </pre>
45 After that try to compile the library with minimal external
46 dependencies (<code>-DDEAL_II_ALLOW_AUTODETECTION=OFF</code>, for
47 further information see the <a href="../users/cmake_dealii.html">deal.II CMake
48 documentation</a>).
49 <li>
50 For adding permanent support for the unknown compiler to the
51 build system, have a look at
52 <pre>
53 cmake/setup_compiler_flags.cmake
54 cmake/setup_compiler_flags_gnu.cmake
55 cmake/setup_compiler_flags_icc.cmake
56 </pre>
57 Patches are highly welcome! See <a href="https://www.dealii.org/participate.html">here</a>
58 for information on how to get in contact with us.
59 <li>
60 You might want to have a look at
61 <pre>
62 cmake/checks/check_01_for_compiler_features.cmake
63 cmake/checks/check_01_for_cxx_features.cmake
64 cmake/checks/check_03_for_compiler_bugs.cmake
65 include/deal.II/base/config.h.in
66 </pre>
67 to see how compiler specific checks are done.
68 </ul>
69 </p>
70
71 <h2>Porting to a new platform</h2>
72
73 <p>
74 <acronym>deal.II</acronym> should support almost all reasonably
75 <a href="https://www.opengroup.org/austin/">POSIX</a> compliant
76 platforms out of the box. Nevertheless, the following bits of
77 information might help:
78 <ul>
79 <li>
80 The build system of <acronym>deal.II</acronym> uses <a
81 href="https://www.cmake.org/" target="_top">CMake</a>. So,
82 in order to port <acronym>deal.II</acronym> to a new platform,
83 it is obviously necessary that <a href="https://www.cmake.org/"
84 target="_top">CMake</a> supports the platform in question
85 with at least one generator for a native build tool, see <a
86 href="https://www.cmake.org/cmake/help/documentation.html">here</a>.
87 <li>
88 <acronym>deal.II</acronym> is mainly developed with <a
89 href="https://gcc.gnu.org/">gcc</a> on GNU/Linux, so it is
90 best to begin porting to a new platform with the help of <a
91 href="https://gcc.gnu.org/">gcc</a>.
92 After that a platform specific compiler might be tried.
93 <li>
94 Almost all <a href="https://www.opengroup.org/austin/">POSIX</a>
95 specific code is well guarded with fall-back code in case the
96 specific POSIX function is not available. There is (currently)
97 one exception, though: Routines that measure elapsed CPU time in
98 <code>source/base/timer.cc</code> have implementations for POSIX
99 and Windows and will not work correctly on other platforms.
100 <li>
101 Have a look at
102 <pre>
103 cmake/checks/check_01_cxx_features.cmake
104 cmake/checks/check_02_compiler_features.cmake
105 cmake/checks/check_02_system_features.cmake
106 cmake/checks/check_03_compiler_bugs.cmake
107 include/deal.II/base/config.h.in
108 </pre>
109 to see how platform and compiler specific checks are done.
110 <li>
111 Of course, we would be happy to hear about the changes you made
112 for your system, so that we can include them into the next version
113 of the library!
114 </ul>
115 </p>
116
117 <h2>Cross compiling</h2>
118
119 <p>
120 It is possible to use the
121 <a href="https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html">CMake toolchain</a>
122 to cross compile deal.II for a platform other than the one on which the
123 compiler is running. The target platform can have a different operating
124 system, different architecture or different set of libraries. Cross
125 compilation is a very useful technique, for instance it can be used to
126 compile deal.II with a compiler that is not available in the target
127 machine. An alternative technique is to use a
128 <a href="https://www.docker.com/">Docker container</a> or a
129 <a href="https://en.wikipedia.org/wiki/Virtualization">virtual machine</a>
130 that mimics the target machine.
131 </p>
132
133 <p>
134 You can use any compiler for cross compilation, although
135 <a href="https://clang.llvm.org/">LLVM/clang</a> might be more versatile
136 because it supports multiple architecture targets in a single
137 executable natively (see
138 <a href="https://clang.llvm.org/docs/CrossCompilation.html">Cross-compilation using Clang</a>).
139 Below you can find an example toolchain file for cross compilation with
140 clang (and another example for
141 <a href="Toolchain-x86_64-w64-mingw32.sample">Windows64 using MinGW</a>).
142 <pre>
143 set(target_root /path/to/sysroot)
144 set(dealii_dir ${target_root}/path/to/lib/dealii)
145
146 set(CMAKE_SYSTEM_NAME Linux)
147 set(CMAKE_SYSTEM_PROCESSOR x86_64)
148
149 set(CMAKE_SYSROOT ${target_root})
150
151 set(CMAKE_C_COMPILER clang)
152 set(CMAKE_CXX_COMPILER clang++)
153
154 set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN ${target_root}/path/to/gcc/toolchain)
155 set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN ${target_root}/path/to/gcc/toolchain)
156
157 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
158 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
159 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
160 set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
161 </pre>
162 If you use LLVM/clang you can use the gcc toolchain of the
163 target with the option <code>CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN</code>,
164 this is equivalent to the clang option
165 <a href="https://clang.llvm.org/docs/ClangCommandLineReference.html">--gcc-toolchain</a>.
166 You should place all the relevant libraries of the target in
167 <code>$target_root</code>. <code>ldd</code> is a great tool figure out the
168 libraries that you need. You can use the C libraries of the target such as
169 Blas, HDF5 and MPI. On the other hand C++ libraries can be problematic
170 because different C++ compilers (or even different versions of the same
171 compiler, or the same compiler on different platforms) mangle public
172 symbols in radically different ways. For this reason C++ libraries such
173 as Trilinos should be cross compiled by the same compiler as deal.II.
174 </p>
175
176 <p>
177 If the host and the target have a different architecture, you have to set
178 up a native deal.II build directory first and run
179 <code>make expand_instantiations_exe</code> in it. The executable is
180 needed for the build system (the cross compiled version cannot be used if
181 the architecture of the target and the host are not the same). Locate the
182 <code>expand_instantiations</code> executable (it usually resides under
183 <code>${CMAKE_BINARY_DIR}/bin</code>) and export its location with the
184 <code>PATH</code> environment variable. Below you can find a minimal cmake
185 script for the configuration of deal.II.
186 <pre>
187 mkdir $dealii_build
188 cd $dealii_build
189 export LD_LIBRARY_PATH=$target_root/lib/directories
190 cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
191 -DDEAL_II_FORCE_BUNDLED_BOOST=ON \
192 -DDEAL_II_ALLOW_AUTODETECTION=OFF \
193 -DDEAL_II_WITH_MPI=ON \
194 -DMPI_CXX_INCLUDE_PATH:STRING=$target_root'/path/to/mpi/include' \
195 -DMPI_CXX_LIBRARIES:STRING=$target_root'/path/to/mpi/lib/libmpi_1.so;'$target_root'/path/to/mpi/lib/libmpi_2.so' \
196 -DDEAL_II_WITH_TRILINOS=ON \
197 -DTRILINOS_DIR=$target_root/path/to/trilinos \
198 -DDEAL_II_WITH_P4EST=ON \
199 -DP4EST_DIR=$target_root/path/to/p4est \
200 -DCMAKE_INSTALL_PREFIX=$target_root/path/to/dealii \
201 /path/to/dealii/repository
202 make expand_instantiations_exe
203 export PATH=$dealii_build/bin/:$PATH
204 make -jN install
205 </pre>
206 If the target uses <code>LD_LIBRARY_PATH</code> to set up some libraries,
207 you may need to export <code>LD_PRELOAD_PATH</code> with those libraries
208 before you call CMake. Note that CMake might not be able to guess the MPI
209 configuration, therefore you may have to give all the MPI flags to CMake.
210 There are two ways to obtain the MPI flags, you can compile another
211 program at the target and then inspect <code>CMakeCache.txt</code>
212 or you can obtain the flags using <code>mpic++ --showme:compile</code> and
213 <code>mpic++ --showme:link</code>. The remaining configuration can be
214 adjusted at will, see <a href="../users/cmake_dealii.html">the documentation</a>. Note
215 that the <a href="https://en.wikipedia.org/wiki/Rpath">rpaths</a> of the
216 examples might not be correct, this can be fixed using
217 <code>LD_LIBRARY_PATH</code> or <code>chrpath</code>.
218 </p>
219
220 <hr />
221 <div class="right">
222 <a href="http://validator.w3.org/check?uri=referer" target="_top">
223 <img style="border:0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
224 <a href="http://jigsaw.w3.org/css-validator/check/referer" target="_top">
225 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
226 </div>
227
228 </body>
229 </html>