blob: 17e90f9bea2cfa7029e6523288d4c1c97a61a600 [file] [log] [blame]
Eric Fiseliera0733922016-06-02 02:16:28 +00001.. _BuildingLibcxx:
Eric Fiselierd720d1f2015-08-22 19:40:49 +00002
3===============
4Building libc++
5===============
6
7.. contents::
8 :local:
9
Eric Fiselierfa43a5c2016-05-03 22:32:08 +000010.. _build instructions:
11
Louis Dionne4b1b70d2021-07-06 10:39:01 -040012The instructions on this page are aimed at vendors who ship libc++ as part of an
13operating system distribution, a toolchain or similar shipping vehicules. If you
14are a user merely trying to use libc++ in your program, you most likely want to
15refer to your vendor's documentation, or to the general documentation for using
16libc++ :ref:`here <using-libcxx>`.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000017
Dan Albert08302aa2019-11-07 12:40:05 -080018.. warning::
Louis Dionne4b1b70d2021-07-06 10:39:01 -040019 If your operating system already provides libc++, it is important to be careful
20 not to replace it. Replacing your system's libc++ installation could render it
21 non-functional. Use the CMake option ``CMAKE_INSTALL_PREFIX`` to select a safe
22 place to install libc++.
23
24
25The default build
26=================
27
Louis Dionne076fd0c2021-10-07 16:19:11 -040028The default way of building libc++, libc++abi and libunwind is to root the CMake
29invocation at ``<monorepo>/runtimes``. While those projects are under the LLVM
30umbrella, they are different in nature from other build tools, so it makes sense
31to treat them as a separate set of entities. The default build can be achieved
32with the following CMake invocation:
Eric Fiselierd720d1f2015-08-22 19:40:49 +000033
Dan Albert08302aa2019-11-07 12:40:05 -080034.. code-block:: bash
Eric Fiselierd720d1f2015-08-22 19:40:49 +000035
Dan Albert08302aa2019-11-07 12:40:05 -080036 $ git clone https://github.com/llvm/llvm-project.git
37 $ cd llvm-project
Louis Dionne4b1b70d2021-07-06 10:39:01 -040038 $ mkdir build
Louis Dionne076fd0c2021-10-07 16:19:11 -040039 $ cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" # Configure
40 $ ninja -C build cxx cxxabi unwind # Build
41 $ ninja -C build check-cxx check-cxxabi check-unwind # Test
42 $ ninja -C build install-cxx install-cxxabi install-unwind # Install
Eric Fiselierd720d1f2015-08-22 19:40:49 +000043
Louis Dionne4b1b70d2021-07-06 10:39:01 -040044.. note::
45 See :ref:`CMake Options` below for more configuration options.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000046
Louis Dionne076fd0c2021-10-07 16:19:11 -040047After building the various ``install-XXX`` targets, shared libraries for libc++, libc++abi and
48libunwind should now be present in ``<CMAKE_INSTALL_PREFIX>/lib``, and headers in
49``<CMAKE_INSTALL_PREFIX>/include/c++/v1``. See :ref:`using an alternate libc++ installation
50<alternate libcxx>` for information on how to use this libc++ over the default one.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000051
Louis Dionne076fd0c2021-10-07 16:19:11 -040052In the default configuration, the runtimes will be built using the compiler available by default
53on your system. Of course, you can change what compiler is being used with the usual CMake
54variables. If you wish to build the runtimes from a just-built Clang, the bootstrapping build
55explained below makes this task easy.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000056
Louis Dionne4b1b70d2021-07-06 10:39:01 -040057
58Bootstrapping build
59===================
60
Louis Dionne076fd0c2021-10-07 16:19:11 -040061It is possible to build Clang and then build the runtimes using that just-built compiler in a
62single CMake invocation. This is usually the correct way to build the runtimes when putting together
63a toolchain, or when the system compiler is not adequate to build them (too old, unsupported, etc.).
64To do this, use the following CMake invocation, and in particular notice how we're now rooting the
65CMake invocation at ``<monorepo>/llvm``:
Eric Fiselierd720d1f2015-08-22 19:40:49 +000066
67.. code-block:: bash
68
Louis Dionne4b1b70d2021-07-06 10:39:01 -040069 $ mkdir build
Louis Dionne076fd0c2021-10-07 16:19:11 -040070 $ cmake -G Ninja -S llvm -B build -DLLVM_ENABLE_PROJECTS="clang" \ # Configure
71 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \
Louis Dionne4b1b70d2021-07-06 10:39:01 -040072 -DLLVM_RUNTIME_TARGETS="<target-triple>"
Louis Dionne076fd0c2021-10-07 16:19:11 -040073 $ ninja -C build runtimes # Build
74 $ ninja -C build check-runtimes # Test
75 $ ninja -C build install-runtimes # Install
Eric Fiselierd720d1f2015-08-22 19:40:49 +000076
Louis Dionne076fd0c2021-10-07 16:19:11 -040077.. note::
78 This type of build is also commonly called a "Runtimes build", but we would like to move
79 away from that terminology, which is too confusing.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000080
Martin Storsjöf9535f72021-02-22 01:20:28 +020081Support for Windows
Louis Dionne4b1b70d2021-07-06 10:39:01 -040082===================
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000083
Martin Storsjöf9535f72021-02-22 01:20:28 +020084libcxx supports being built with clang-cl, but not with MSVC's cl.exe, as
Martin Storsjöbb9586b2021-03-17 11:40:17 +020085cl doesn't support the ``#include_next`` extension. Furthermore, VS 2017 or
Martin Storsjöf9535f72021-02-22 01:20:28 +020086newer (19.14) is required.
87
88libcxx also supports being built with clang targeting MinGW environments.
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000089
90CMake + Visual Studio
Louis Dionne4b1b70d2021-07-06 10:39:01 -040091---------------------
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000092
93Building with Visual Studio currently does not permit running tests. However,
94it is the simplest way to build.
95
96.. code-block:: batch
97
Louis Dionne4b1b70d2021-07-06 10:39:01 -040098 > cmake -G "Visual Studio 16 2019" -S libcxx -B build ^
99 -T "ClangCL" ^
100 -DLIBCXX_ENABLE_SHARED=YES ^
101 -DLIBCXX_ENABLE_STATIC=NO ^
102 -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO
103 > cmake --build build
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000104
Martin Storsjöf9535f72021-02-22 01:20:28 +0200105CMake + ninja (MSVC)
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400106--------------------
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000107
108Building with ninja is required for development to enable tests.
Martin Storsjö9728c102021-05-03 22:14:00 +0300109A couple of tests require Bash to be available, and a couple dozens
110of tests require other posix tools (cp, grep and similar - LLVM's tests
111require the same). Without those tools the vast majority of tests
112can still be ran successfully.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200113
114If Git for Windows is available, that can be used to provide the bash
115shell by adding the right bin directory to the path, e.g.
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200116``set PATH=%PATH%;C:\Program Files\Git\usr\bin``.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200117
118Alternatively, one can also choose to run the whole build in a MSYS2
119shell. That can be set up e.g. by starting a Visual Studio Tools Command
120Prompt (for getting the environment variables pointing to the headers and
121import libraries), and making sure that clang-cl is available in the
122path. From there, launch an MSYS2 shell via e.g.
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200123``C:\msys64\msys2_shell.cmd -full-path -mingw64`` (preserving the earlier
Martin Storsjöf9535f72021-02-22 01:20:28 +0200124environment, allowing the MSVC headers/libraries and clang-cl to be found).
125
126In either case, then run:
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000127
128.. code-block:: batch
129
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400130 > cmake -G Ninja -S libcxx -B build ^
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000131 -DCMAKE_C_COMPILER=clang-cl ^
Martin Storsjöf9535f72021-02-22 01:20:28 +0200132 -DCMAKE_CXX_COMPILER=clang-cl ^
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400133 -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO
134 > ninja -C build cxx
135 > ninja -C build check-cxx
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000136
Martin Storsjöf9535f72021-02-22 01:20:28 +0200137If you are running in an MSYS2 shell and you have installed the
138MSYS2-provided clang package (which defaults to a non-MSVC target), you
Louis Dionnedd0baa62021-10-12 15:59:08 -0400139should add e.g. ``-DCMAKE_CXX_COMPILER_TARGET=x86_64-windows-msvc`` (replacing
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200140``x86_64`` with the architecture you're targeting) to the ``cmake`` command
141line above. This will instruct ``check-cxx`` to use the right target triple
142when invoking ``clang++``.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200143
144Also note that if not building in Release mode, a failed assert in the tests
145pops up a blocking dialog box, making it hard to run a larger number of tests.
146
147CMake + ninja (MinGW)
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400148---------------------
Martin Storsjöf9535f72021-02-22 01:20:28 +0200149
150libcxx can also be built in MinGW environments, e.g. with the MinGW
151compilers in MSYS2. This requires clang to be available (installed with
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200152e.g. the ``mingw-w64-x86_64-clang`` package), together with CMake and ninja.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200153
154.. code-block:: bash
155
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400156 > cmake -G Ninja -S libcxx -B build \
Martin Storsjöf9535f72021-02-22 01:20:28 +0200157 -DCMAKE_C_COMPILER=clang \
158 -DCMAKE_CXX_COMPILER=clang++ \
159 -DLIBCXX_HAS_WIN32_THREAD_API=ON \
160 -DLIBCXX_CXX_ABI=libstdc++ \
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400161 -DLIBCXX_TARGET_INFO="libcxx.test.target_info.MingwLocalTI"
162 > ninja -C build cxx
Martin Storsjöf9535f72021-02-22 01:20:28 +0200163 > cp /mingw64/bin/{libstdc++-6,libgcc_s_seh-1,libwinpthread-1}.dll lib
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400164 > ninja -C build check-cxx
Martin Storsjöf9535f72021-02-22 01:20:28 +0200165
166As this build configuration ends up depending on a couple other DLLs that
167aren't available in path while running tests, copy them into the same
168directory as the tested libc++ DLL.
169
170(Building a libc++ that depends on libstdc++ isn't necessarily a config one
171would want to deploy, but it simplifies the config for testing purposes.)
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000172
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000173.. _`libc++abi`: http://libcxxabi.llvm.org/
174
175
176.. _CMake Options:
177
178CMake Options
179=============
180
181Here are some of the CMake variables that are used often, along with a
182brief explanation and LLVM-specific notes. For full documentation, check the
183CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
184
185**CMAKE_BUILD_TYPE**:STRING
186 Sets the build type for ``make`` based generators. Possible values are
187 Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
188 the user sets the build type with the IDE settings.
189
190**CMAKE_INSTALL_PREFIX**:PATH
191 Path where LLVM will be installed if "make install" is invoked or the
192 "INSTALL" target is built.
193
194**CMAKE_CXX_COMPILER**:STRING
195 The C++ compiler to use when building and testing libc++.
196
197
198.. _libcxx-specific options:
199
200libc++ specific options
201-----------------------
202
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000203.. option:: LIBCXX_INSTALL_LIBRARY:BOOL
204
205 **Default**: ``ON``
206
207 Toggle the installation of the library portion of libc++.
208
209.. option:: LIBCXX_INSTALL_HEADERS:BOOL
210
211 **Default**: ``ON``
212
213 Toggle the installation of the libc++ headers.
214
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000215.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL
216
Raul Tambree3f9fa52020-03-30 12:44:15 -0400217 **Default**: ``OFF``
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000218
Louis Dionne6e8eb552022-03-03 17:37:03 -0500219 Build libc++ with assertions enabled in the compiled library, and enable assertions
220 by default when building user code as well. Assertions can be turned off by users
221 by defining ``_LIBCPP_ENABLE_ASSERTIONS=0``. For details, see
222 :ref:`the documentation <assertions-mode>`.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000223
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000224.. option:: LIBCXX_ENABLE_SHARED:BOOL
225
226 **Default**: ``ON``
227
Eric Fiselier887b86b2016-09-16 03:47:53 +0000228 Build libc++ as a shared library. Either `LIBCXX_ENABLE_SHARED` or
229 `LIBCXX_ENABLE_STATIC` has to be enabled.
Petr Hosek13620052016-08-08 22:57:25 +0000230
231.. option:: LIBCXX_ENABLE_STATIC:BOOL
232
233 **Default**: ``ON``
234
Eric Fiselier887b86b2016-09-16 03:47:53 +0000235 Build libc++ as a static library. Either `LIBCXX_ENABLE_SHARED` or
236 `LIBCXX_ENABLE_STATIC` has to be enabled.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000237
238.. option:: LIBCXX_LIBDIR_SUFFIX:STRING
239
240 Extra suffix to append to the directory where libraries are to be installed.
Eric Fiselier887b86b2016-09-16 03:47:53 +0000241 This option overrides `LLVM_LIBDIR_SUFFIX`.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000242
Petr Hosekb42e3492019-01-06 06:14:31 +0000243.. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL
244
245 **Default**: ``OFF``
246
Jonathan Metzmance2328d2019-04-10 23:44:27 +0000247 Do not export any symbols from the static libc++ library.
Petr Hosekb42e3492019-01-06 06:14:31 +0000248 This is useful when the static libc++ library is being linked into shared
249 libraries that may be used in with other shared libraries that use different
Louis Dionned0889672019-08-23 19:42:09 +0000250 C++ library. We want to avoid exporting any libc++ symbols in that case.
Petr Hosekb42e3492019-01-06 06:14:31 +0000251
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000252.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL
253
Mark de Wever42bf3d02021-07-29 07:54:48 +0200254 **Default**: ``ON`` except on Windows when using MSVC.
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000255
256 This option can be used to enable or disable the filesystem components on
Mark de Wever42bf3d02021-07-29 07:54:48 +0200257 platforms that may not support them. For example on Windows when using MSVC.
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000258
Louis Dionne89258142021-08-23 15:32:36 -0400259.. option:: LIBCXX_ENABLE_WIDE_CHARACTERS:BOOL
260
261 **Default**: ``ON``
262
263 This option can be used to disable support for ``wchar_t`` in the library. It also
264 allows the library to work on top of a C Standard Library that does not provide
265 support for ``wchar_t``. This is especially useful in embedded settings where
266 C Standard Libraries don't always provide all the usual bells and whistles.
267
Mark de Wever8a0a1882021-07-25 09:18:53 +0200268.. option:: LIBCXX_ENABLE_INCOMPLETE_FEATURES:BOOL
269
270 **Default**: ``ON``
271
272 Whether to enable support for incomplete library features. Incomplete features
273 are new library features under development. These features don't guarantee
274 ABI stability nor the quality of completed library features. Vendors
275 shipping the library may want to disable this option.
276
John Ericson97c6f272021-04-28 22:36:47 +0000277.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH
278
279 **Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}``
280
281 Path where built libc++ libraries should be installed. If a relative path,
282 relative to ``CMAKE_INSTALL_PREFIX``.
283
284.. option:: LIBCXX_INSTALL_INCLUDE_DIR:PATH
285
286 **Default**: ``include/c++/v1``
287
288 Path where target-agnostic libc++ headers should be installed. If a relative
289 path, relative to ``CMAKE_INSTALL_PREFIX``.
290
291.. option:: LIBCXX_INSTALL_INCLUDE_TARGET_DIR:PATH
292
293 **Default**: ``include/c++/v1`` or
294 ``include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1``
295
296 Path where target-specific libc++ headers should be installed. If a relative
297 path, relative to ``CMAKE_INSTALL_PREFIX``.
298
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000299.. _libc++experimental options:
300
301libc++experimental Specific Options
302------------------------------------
303
304.. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL
305
306 **Default**: ``ON``
307
308 Build and test libc++experimental.a.
309
310.. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL
311
Eric Fiselier121594e2016-09-07 01:15:10 +0000312 **Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY AND LIBCXX_INSTALL_LIBRARY``
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000313
314 Install libc++experimental.a alongside libc++.
315
316
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000317.. _ABI Library Specific Options:
318
319ABI Library Specific Options
320----------------------------
321
322.. option:: LIBCXX_CXX_ABI:STRING
323
Michał Górny1cf16e12022-03-01 13:43:25 -0500324 **Values**: ``none``, ``libcxxabi``, ``system-libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000325
326 Select the ABI library to build libc++ against.
327
328.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
329
330 Provide additional search paths for the ABI library headers.
331
332.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
333
334 Provide the path to the ABI library that libc++ should link against.
335
336.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
337
338 **Default**: ``OFF``
339
340 If this option is enabled, libc++ will try and link the selected ABI library
341 statically.
342
Eric Fiselier0b09dd12015-10-15 22:41:51 +0000343.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
344
345 **Default**: ``ON`` by default on UNIX platforms other than Apple unless
346 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
347
348 This option generate and installs a linker script as ``libc++.so`` which
349 links the correct ABI library.
350
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000351.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
352
353 **Default**: ``OFF``
354
355 Build and use the LLVM unwinder. Note: This option can only be used when
356 libc++abi is the C++ ABI library used.
357
358
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000359libc++ Feature Options
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000360----------------------
361
362.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
363
364 **Default**: ``ON``
365
366 Build libc++ with exception support.
367
368.. option:: LIBCXX_ENABLE_RTTI:BOOL
369
370 **Default**: ``ON``
371
372 Build libc++ with run time type information.
373
Saleem Abdulrasool1e06a1d2019-07-04 19:08:16 +0000374.. option:: LIBCXX_INCLUDE_TESTS:BOOL
375
Nico Weberf1038c22021-02-18 11:58:48 -0500376 **Default**: ``ON`` (or value of ``LLVM_INCLUDE_TESTS``)
Saleem Abdulrasool1e06a1d2019-07-04 19:08:16 +0000377
378 Build the libc++ tests.
379
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000380.. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000381
Eric Fiselier93f212c2016-08-29 19:50:49 +0000382 **Default**: ``ON``
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000383
384 Build the libc++ benchmark tests and the Google Benchmark library needed
385 to support them.
386
Eric Fiselier453bc182018-11-14 20:38:46 +0000387.. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING
388
389 **Default**: ``--benchmark_min_time=0.01``
390
391 A semicolon list of arguments to pass when running the libc++ benchmarks using the
392 ``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time,
393 since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to
394 get accurate measurements.
395
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000396.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000397
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000398 **Default**:: ``""``
399
400 **Values**:: ``libc++``, ``libstdc++``
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000401
402 Build the libc++ benchmark tests and Google Benchmark library against the
Louis Dionneecc89552019-10-01 20:34:50 +0000403 specified standard library on the platform. On Linux this can be used to
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000404 compare libc++ to libstdc++ by building the benchmark tests against both
405 standard libraries.
406
407.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING
408
409 Use the specified GCC toolchain and standard library when building the native
410 stdlib benchmark tests.
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000411
Louis Dionne1821de42018-08-16 12:44:28 +0000412.. option:: LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT:BOOL
413
414 **Default**: ``OFF``
415
416 Pick the default for whether to constrain ABI-unstable symbols to
417 each individual translation unit. This setting controls whether
418 `_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT` is defined by default --
419 see the documentation of that macro for details.
420
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000421
422libc++ ABI Feature Options
423--------------------------
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000424
425The following options allow building libc++ for a different ABI version.
426
427.. option:: LIBCXX_ABI_VERSION:STRING
428
429 **Default**: ``1``
430
431 Defines the target ABI version of libc++.
432
433.. option:: LIBCXX_ABI_UNSTABLE:BOOL
434
435 **Default**: ``OFF``
436
437 Build the "unstable" ABI version of libc++. Includes all ABI changing features
438 on top of the current stable version.
439
Eric Fiselierb33778a2018-10-30 21:44:53 +0000440.. option:: LIBCXX_ABI_NAMESPACE:STRING
441
442 **Default**: ``__n`` where ``n`` is the current ABI version.
443
444 This option defines the name of the inline ABI versioning namespace. It can be used for building
445 custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues
446 with other libc++ versions.
447
448 .. warning::
Louis Dionne15b1cdf2022-02-07 14:52:17 -0500449 When providing a custom namespace, it's the user's responsibility to ensure the name won't cause
Louis Dionne6f2c6fb2018-11-16 14:57:47 +0000450 conflicts with other names defined by libc++, both now and in the future. In particular, inline
Louis Dionne15b1cdf2022-02-07 14:52:17 -0500451 namespaces of the form ``__[0-9]+`` could cause conflicts with future versions of the library,
452 and so should be avoided.
Eric Fiselierb33778a2018-10-30 21:44:53 +0000453
Shoaib Meenai4ca4b7c2017-10-04 23:17:12 +0000454.. option:: LIBCXX_ABI_DEFINES:STRING
455
456 **Default**: ``""``
457
458 A semicolon-separated list of ABI macros to persist in the site config header.
459 See ``include/__config`` for the list of ABI macros.
460
Eric Fiselierf3566292019-05-29 02:21:37 +0000461
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000462.. _LLVM-specific variables:
463
464LLVM-specific options
465---------------------
466
467.. option:: LLVM_LIBDIR_SUFFIX:STRING
468
469 Extra suffix to append to the directory where libraries are to be
470 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
471 to install libraries to ``/usr/lib64``.
472
473.. option:: LLVM_BUILD_32_BITS:BOOL
474
475 Build 32-bits executables and libraries on 64-bits systems. This option is
Louis Dionneecc89552019-10-01 20:34:50 +0000476 available only on some 64-bits Unix systems. Defaults to OFF.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000477
478.. option:: LLVM_LIT_ARGS:STRING
479
480 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
481 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
482 others.
483
484
485Using Alternate ABI libraries
486=============================
487
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400488In order to implement various features like exceptions, RTTI, ``dynamic_cast`` and
489more, libc++ requires what we refer to as an ABI library. Typically, that library
490implements the `Itanium C++ ABI <https://itanium-cxx-abi.github.io/cxx-abi/abi.html>`_.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000491
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400492By default, libc++ uses libc++abi as an ABI library. However, it is possible to use
493other ABI libraries too.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000494
495Using libsupc++ on Linux
496------------------------
497
498You will need libstdc++ in order to provide libsupc++.
499
500Figure out where the libsupc++ headers are on your system. On Ubuntu this
501is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
502
503You can also figure this out by running
504
505.. code-block:: bash
506
507 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
508 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
509 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
510 #include "..." search starts here:
511 #include &lt;...&gt; search starts here:
512 /usr/include/c++/4.7
513 /usr/include/c++/4.7/x86_64-linux-gnu
514 /usr/include/c++/4.7/backward
515 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
516 /usr/local/include
517 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
518 /usr/include/x86_64-linux-gnu
519 /usr/include
520 End of search list.
521
522Note that the first two entries happen to be what we are looking for. This
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400523may not be correct on all platforms.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000524
525We can now run CMake:
526
527.. code-block:: bash
528
Louis Dionne25a00502022-02-09 12:08:44 -0500529 $ cmake -G Ninja -S runtimes -B build \
530 -DLLVM_ENABLE_RUNTIMES="libcxx" \
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400531 -DLIBCXX_CXX_ABI=libstdc++ \
532 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/"
533 $ ninja -C build install-cxx
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000534
535
536You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
537above, which will cause the library to be linked to libsupc++ instead
538of libstdc++, but this is only recommended if you know that you will
539never need to link against libstdc++ in the same executable as libc++.
540GCC ships libsupc++ separately but only as a static library. If a
541program also needs to link against libstdc++, it will provide its
542own copy of libsupc++ and this can lead to subtle problems.
543
Eric Fiseliera0733922016-06-02 02:16:28 +0000544Using libcxxrt on Linux
545------------------------
546
547You will need to keep the source tree of `libcxxrt`_ available
548on your build machine and your copy of the libcxxrt shared library must
549be placed where your linker will find it.
550
551We can now run CMake like:
552
553.. code-block:: bash
554
Louis Dionne25a00502022-02-09 12:08:44 -0500555 $ cmake -G Ninja -S runtimes -B build \
556 -DLLVM_ENABLE_RUNTIMES="libcxx" \
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400557 -DLIBCXX_CXX_ABI=libcxxrt \
558 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src
559 $ ninja -C build install-cxx
Eric Fiseliera0733922016-06-02 02:16:28 +0000560
561Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as
562clang is set up to link for libc++ linked to libsupc++. To get around this
563you'll have to set up your linker yourself (or patch clang). For example,
564
565.. code-block:: bash
566
567 $ clang++ -stdlib=libc++ helloworld.cpp \
568 -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
569
570Alternately, you could just add libcxxrt to your libraries list, which in most
571situations will give the same result:
572
573.. code-block:: bash
574
575 $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
576
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400577.. _`libcxxrt`: https://github.com/libcxxrt/libcxxrt