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