blob: 0173326a5a669eac75270789eddb5c8fc7b354e6 [file] [log] [blame]
Eric Fiselierd720d1f2015-08-22 19:40:49 +00001
2===============
3Building libc++
4===============
5
6.. contents::
7 :local:
8
9Getting Started
10===============
11
12On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install
13Xcode 4.2 or later. However if you want to install tip-of-trunk from here
14(getting the bleeding edge), read on.
15
16The basic steps needed to build libc++ are:
17
18#. Checkout LLVM:
19
20 * ``cd where-you-want-llvm-to-live``
21 * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
22
23#. Checkout libc++:
24
25 * ``cd where-you-want-llvm-to-live``
Eric Fiselierc3ca4712015-12-14 22:26:28 +000026 * ``cd llvm/projects``
Eric Fiselierd720d1f2015-08-22 19:40:49 +000027 * ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
28
29#. Checkout libc++abi:
30
31 * ``cd where-you-want-llvm-to-live``
32 * ``cd llvm/projects``
Eric Fiselierc3ca4712015-12-14 22:26:28 +000033 * ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
Eric Fiselierd720d1f2015-08-22 19:40:49 +000034
35#. Configure and build libc++ with libc++abi:
36
Alexey Samsonovadc99cd2016-01-30 01:11:42 +000037 CMake is the only supported configuration system.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000038
39 Clang is the preferred compiler when building and using libc++.
40
41 * ``cd where you want to build llvm``
42 * ``mkdir build``
43 * ``cd build``
44 * ``cmake -G <generator> [options] <path to llvm sources>``
45
46 For more information about configuring libc++ see :ref:`CMake Options`.
47
48 * ``make cxx`` --- will build libc++ and libc++abi.
49 * ``make check-libcxx check-libcxxabi`` --- will run the test suites.
50
51 Shared libraries for libc++ and libc++ abi should now be present in llvm/build/lib.
52 See :ref:`using an alternate libc++ installation <alternate libcxx>`
53
54#. **Optional**: Install libc++ and libc++abi
55
56 If your system already provides a libc++ installation it is important to be
57 careful not to replace it. Remember Use the CMake option ``CMAKE_INSTALL_PREFIX`` to
58 select a safe place to install libc++.
59
60 * ``make install-libcxx install-libcxxabi`` --- Will install the libraries and the headers
61
62 .. warning::
63 * Replacing your systems libc++ installation could render the system non-functional.
64 * Mac OS X will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``.
65
66
67The instructions are for building libc++ on
68FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library.
69On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt.
70
Eric Fiselierb1c50fd2015-09-06 23:31:16 +000071It is sometimes beneficial to build outside of the LLVM tree. An out-of-tree
72build would look like this:
Eric Fiselierd720d1f2015-08-22 19:40:49 +000073
74.. code-block:: bash
75
76 $ cd where-you-want-libcxx-to-live
77 $ # Check out llvm, libc++ and libc++abi.
78 $ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
79 $ ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
80 $ ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
81 $ cd where-you-want-to-build
82 $ mkdir build && cd build
83 $ export CC=clang CXX=clang++
84 $ cmake -DLLVM_PATH=path/to/llvm \
85 -DLIBCXX_CXX_ABI=libcxxabi \
86 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxabi/include \
87 path/to/libcxx
88 $ make
89 $ make check-libcxx # optional
90
91
92.. _`libc++abi`: http://libcxxabi.llvm.org/
93
94
95.. _CMake Options:
96
97CMake Options
98=============
99
100Here are some of the CMake variables that are used often, along with a
101brief explanation and LLVM-specific notes. For full documentation, check the
102CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
103
104**CMAKE_BUILD_TYPE**:STRING
105 Sets the build type for ``make`` based generators. Possible values are
106 Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
107 the user sets the build type with the IDE settings.
108
109**CMAKE_INSTALL_PREFIX**:PATH
110 Path where LLVM will be installed if "make install" is invoked or the
111 "INSTALL" target is built.
112
113**CMAKE_CXX_COMPILER**:STRING
114 The C++ compiler to use when building and testing libc++.
115
116
117.. _libcxx-specific options:
118
119libc++ specific options
120-----------------------
121
122.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL
123
124 **Default**: ``ON``
125
126 Build libc++ with assertions enabled.
127
128.. option:: LIBCXX_BUILD_32_BITS:BOOL
129
130 **Default**: ``OFF``
131
132 Build libc++ as a 32 bit library. Also see :option:`LLVM_BUILD_32_BITS`.
133
134.. option:: LIBCXX_ENABLE_SHARED:BOOL
135
136 **Default**: ``ON``
137
138 Build libc++ as a shared library. If ``OFF`` is specified then libc++ is
139 built as a static library.
140
141.. option:: LIBCXX_LIBDIR_SUFFIX:STRING
142
143 Extra suffix to append to the directory where libraries are to be installed.
144 This option overrides :option:`LLVM_LIBDIR_SUFFIX`.
145
146.. _ABI Library Specific Options:
147
148ABI Library Specific Options
149----------------------------
150
151.. option:: LIBCXX_CXX_ABI:STRING
152
153 **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``.
154
155 Select the ABI library to build libc++ against.
156
157.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
158
159 Provide additional search paths for the ABI library headers.
160
161.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
162
163 Provide the path to the ABI library that libc++ should link against.
164
165.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
166
167 **Default**: ``OFF``
168
169 If this option is enabled, libc++ will try and link the selected ABI library
170 statically.
171
Eric Fiselier0b09dd12015-10-15 22:41:51 +0000172.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
173
174 **Default**: ``ON`` by default on UNIX platforms other than Apple unless
175 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
176
177 This option generate and installs a linker script as ``libc++.so`` which
178 links the correct ABI library.
179
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000180.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
181
182 **Default**: ``OFF``
183
184 Build and use the LLVM unwinder. Note: This option can only be used when
185 libc++abi is the C++ ABI library used.
186
187
188libc++ Feature options
189----------------------
190
191.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
192
193 **Default**: ``ON``
194
195 Build libc++ with exception support.
196
197.. option:: LIBCXX_ENABLE_RTTI:BOOL
198
199 **Default**: ``ON``
200
201 Build libc++ with run time type information.
202
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000203
204libc++ Feature options
205----------------------
206
207The following options allow building libc++ for a different ABI version.
208
209.. option:: LIBCXX_ABI_VERSION:STRING
210
211 **Default**: ``1``
212
213 Defines the target ABI version of libc++.
214
215.. option:: LIBCXX_ABI_UNSTABLE:BOOL
216
217 **Default**: ``OFF``
218
219 Build the "unstable" ABI version of libc++. Includes all ABI changing features
220 on top of the current stable version.
221
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000222.. _LLVM-specific variables:
223
224LLVM-specific options
225---------------------
226
227.. option:: LLVM_LIBDIR_SUFFIX:STRING
228
229 Extra suffix to append to the directory where libraries are to be
230 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
231 to install libraries to ``/usr/lib64``.
232
233.. option:: LLVM_BUILD_32_BITS:BOOL
234
235 Build 32-bits executables and libraries on 64-bits systems. This option is
236 available only on some 64-bits unix systems. Defaults to OFF.
237
238.. option:: LLVM_LIT_ARGS:STRING
239
240 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
241 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
242 others.
243
244
245Using Alternate ABI libraries
246=============================
247
248
249.. _libsupcxx:
250
251Using libsupc++ on Linux
252------------------------
253
254You will need libstdc++ in order to provide libsupc++.
255
256Figure out where the libsupc++ headers are on your system. On Ubuntu this
257is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
258
259You can also figure this out by running
260
261.. code-block:: bash
262
263 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
264 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
265 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
266 #include "..." search starts here:
267 #include &lt;...&gt; search starts here:
268 /usr/include/c++/4.7
269 /usr/include/c++/4.7/x86_64-linux-gnu
270 /usr/include/c++/4.7/backward
271 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
272 /usr/local/include
273 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
274 /usr/include/x86_64-linux-gnu
275 /usr/include
276 End of search list.
277
278Note that the first two entries happen to be what we are looking for. This
279may not be correct on other platforms.
280
281We can now run CMake:
282
283.. code-block:: bash
284
285 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
286 -DLIBCXX_CXX_ABI=libstdc++ \
287 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \
288 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
289 <libc++-source-dir>
290
291
292You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
293above, which will cause the library to be linked to libsupc++ instead
294of libstdc++, but this is only recommended if you know that you will
295never need to link against libstdc++ in the same executable as libc++.
296GCC ships libsupc++ separately but only as a static library. If a
297program also needs to link against libstdc++, it will provide its
298own copy of libsupc++ and this can lead to subtle problems.
299
300.. code-block:: bash
301
302 $ make cxx
303 $ make install
304
305You can now run clang with -stdlib=libc++.