blob: f00ce4f9cff1a8318c8e7893b0d82ef906af85c3 [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
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
Eric Fiselier0b09dd12015-10-15 22:41:51 +0000173.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
174
175 **Default**: ``ON`` by default on UNIX platforms other than Apple unless
176 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
177
178 This option generate and installs a linker script as ``libc++.so`` which
179 links the correct ABI library.
180
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000181.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
182
183 **Default**: ``OFF``
184
185 Build and use the LLVM unwinder. Note: This option can only be used when
186 libc++abi is the C++ ABI library used.
187
188
189libc++ Feature options
190----------------------
191
192.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
193
194 **Default**: ``ON``
195
196 Build libc++ with exception support.
197
198.. option:: LIBCXX_ENABLE_RTTI:BOOL
199
200 **Default**: ``ON``
201
202 Build libc++ with run time type information.
203
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000204
205libc++ Feature options
206----------------------
207
208The following options allow building libc++ for a different ABI version.
209
210.. option:: LIBCXX_ABI_VERSION:STRING
211
212 **Default**: ``1``
213
214 Defines the target ABI version of libc++.
215
216.. option:: LIBCXX_ABI_UNSTABLE:BOOL
217
218 **Default**: ``OFF``
219
220 Build the "unstable" ABI version of libc++. Includes all ABI changing features
221 on top of the current stable version.
222
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000223.. _LLVM-specific variables:
224
225LLVM-specific options
226---------------------
227
228.. option:: LLVM_LIBDIR_SUFFIX:STRING
229
230 Extra suffix to append to the directory where libraries are to be
231 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
232 to install libraries to ``/usr/lib64``.
233
234.. option:: LLVM_BUILD_32_BITS:BOOL
235
236 Build 32-bits executables and libraries on 64-bits systems. This option is
237 available only on some 64-bits unix systems. Defaults to OFF.
238
239.. option:: LLVM_LIT_ARGS:STRING
240
241 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
242 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
243 others.
244
245
246Using Alternate ABI libraries
247=============================
248
249
250.. _libsupcxx:
251
252Using libsupc++ on Linux
253------------------------
254
255You will need libstdc++ in order to provide libsupc++.
256
257Figure out where the libsupc++ headers are on your system. On Ubuntu this
258is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
259
260You can also figure this out by running
261
262.. code-block:: bash
263
264 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
265 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
266 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
267 #include "..." search starts here:
268 #include &lt;...&gt; search starts here:
269 /usr/include/c++/4.7
270 /usr/include/c++/4.7/x86_64-linux-gnu
271 /usr/include/c++/4.7/backward
272 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
273 /usr/local/include
274 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
275 /usr/include/x86_64-linux-gnu
276 /usr/include
277 End of search list.
278
279Note that the first two entries happen to be what we are looking for. This
280may not be correct on other platforms.
281
282We can now run CMake:
283
284.. code-block:: bash
285
286 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
287 -DLIBCXX_CXX_ABI=libstdc++ \
288 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \
289 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
290 <libc++-source-dir>
291
292
293You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
294above, which will cause the library to be linked to libsupc++ instead
295of libstdc++, but this is only recommended if you know that you will
296never need to link against libstdc++ in the same executable as libc++.
297GCC ships libsupc++ separately but only as a static library. If a
298program also needs to link against libstdc++, it will provide its
299own copy of libsupc++ and this can lead to subtle problems.
300
301.. code-block:: bash
302
303 $ make cxx
304 $ make install
305
306You can now run clang with -stdlib=libc++.