Eric Fiselier | a073392 | 2016-06-02 02:16:28 +0000 | [diff] [blame] | 1 | .. _BuildingLibcxx: |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 2 | |
| 3 | =============== |
| 4 | Building libc++ |
| 5 | =============== |
| 6 | |
| 7 | .. contents:: |
| 8 | :local: |
| 9 | |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 10 | .. _build instructions: |
| 11 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 12 | Getting Started |
| 13 | =============== |
| 14 | |
| 15 | On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install |
| 16 | Xcode 4.2 or later. However if you want to install tip-of-trunk from here |
| 17 | (getting the bleeding edge), read on. |
| 18 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 19 | The following instructions describe how to checkout, build, test and |
| 20 | (optionally) install libc++ and libc++abi. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 21 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 22 | If your system already provides a libc++ installation it is important to be |
| 23 | careful not to replace it. Remember Use the CMake option |
| 24 | ``CMAKE_INSTALL_PREFIX`` to select a safe place to install libc++. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 25 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 26 | .. warning:: |
| 27 | * Replacing your systems libc++ installation could render the system non-functional. |
| 28 | * macOS will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 29 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 30 | .. code-block:: bash |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 31 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 32 | $ git clone https://github.com/llvm/llvm-project.git |
| 33 | $ cd llvm-project |
| 34 | $ mkdir build && cd build |
| 35 | $ cmake -DCMAKE_C_COMPILER=clang \ |
| 36 | -DCMAKE_CXX_COMPILER=clang++ \ |
| 37 | -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \ |
| 38 | ../llvm |
| 39 | $ make # Build |
| 40 | $ make check-cxx # Test |
| 41 | $ make install-cxx install-cxxabi # Install |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 42 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 43 | For more information about configuring libc++ see :ref:`CMake Options`. You may |
| 44 | also want to read the `LLVM getting started |
| 45 | <https://llvm.org/docs/GettingStarted.html>`_ documentation. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 46 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 47 | Shared libraries for libc++ and libc++ abi should now be present in |
| 48 | ``build/lib``. See :ref:`using an alternate libc++ installation <alternate |
| 49 | libcxx>` for information on how to use this libc++. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 50 | |
| 51 | The instructions are for building libc++ on |
| 52 | FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library. |
| 53 | On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt. |
| 54 | |
Dan Albert | 08302aa | 2019-11-07 12:40:05 -0800 | [diff] [blame] | 55 | It is possible to keep your LLVM and libc++ trees separate so you can avoid |
| 56 | rebuilding LLVM as often. An out-of-tree build would look like this: |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 57 | |
| 58 | .. code-block:: bash |
| 59 | |
| 60 | $ cd where-you-want-libcxx-to-live |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 61 | $ # Check out the sources (includes everything, but we'll only use libcxx) |
| 62 | $ ``git clone https://github.com/llvm/llvm-project.git`` |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 63 | $ cd where-you-want-to-build |
| 64 | $ mkdir build && cd build |
| 65 | $ export CC=clang CXX=clang++ |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 66 | $ cmake -DLLVM_PATH=path/to/separate/llvm \ |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 67 | -DLIBCXX_CXX_ABI=libcxxabi \ |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 68 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/separate/libcxxabi/include \ |
| 69 | path/to/llvm-project/libcxx |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 70 | $ make |
Louis Dionne | f58d829 | 2020-03-11 17:03:00 -0400 | [diff] [blame] | 71 | $ make check-cxx # optional |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 72 | |
| 73 | |
Saleem Abdulrasool | 3ab0b70 | 2017-02-10 03:58:20 +0000 | [diff] [blame] | 74 | Experimental Support for Windows |
| 75 | -------------------------------- |
| 76 | |
| 77 | The Windows support requires building with clang-cl as cl does not support one |
| 78 | required extension: `#include_next`. Furthermore, VS 2015 or newer (19.00) is |
| 79 | required. In the case of clang-cl, we need to specify the "MS Compatibility |
| 80 | Version" as it defaults to 2014 (18.00). |
| 81 | |
| 82 | CMake + Visual Studio |
| 83 | ~~~~~~~~~~~~~~~~~~~~~ |
| 84 | |
| 85 | Building with Visual Studio currently does not permit running tests. However, |
| 86 | it is the simplest way to build. |
| 87 | |
| 88 | .. code-block:: batch |
| 89 | |
| 90 | > cmake -G "Visual Studio 14 2015" ^ |
| 91 | -T "LLVM-vs2014" ^ |
| 92 | -DLIBCXX_ENABLE_SHARED=YES ^ |
| 93 | -DLIBCXX_ENABLE_STATIC=NO ^ |
| 94 | -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^ |
| 95 | \path\to\libcxx |
| 96 | > cmake --build . |
| 97 | |
| 98 | CMake + ninja |
| 99 | ~~~~~~~~~~~~~ |
| 100 | |
| 101 | Building with ninja is required for development to enable tests. |
| 102 | Unfortunately, doing so requires additional configuration as we cannot |
| 103 | just specify a toolset. |
| 104 | |
| 105 | .. code-block:: batch |
| 106 | |
| 107 | > cmake -G Ninja ^ |
| 108 | -DCMAKE_MAKE_PROGRAM=/path/to/ninja ^ |
| 109 | -DCMAKE_SYSTEM_NAME=Windows ^ |
| 110 | -DCMAKE_C_COMPILER=clang-cl ^ |
| 111 | -DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 --target=i686--windows" ^ |
Hamza Sood | 4e2e471 | 2017-12-03 10:18:35 +0000 | [diff] [blame] | 112 | -DCMAKE_CXX_COMPILER=clang-cl ^ |
Saleem Abdulrasool | 3ab0b70 | 2017-02-10 03:58:20 +0000 | [diff] [blame] | 113 | -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 --target=i686--windows" ^ |
| 114 | -DLLVM_PATH=/path/to/llvm/tree ^ |
| 115 | -DLIBCXX_ENABLE_SHARED=YES ^ |
| 116 | -DLIBCXX_ENABLE_STATIC=NO ^ |
| 117 | -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^ |
| 118 | \path\to\libcxx |
| 119 | > /path/to/ninja cxx |
| 120 | > /path/to/ninja check-cxx |
| 121 | |
| 122 | Note that the paths specified with backward slashes must use the `\\` as the |
| 123 | directory separator as clang-cl may otherwise parse the path as an argument. |
| 124 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 125 | .. _`libc++abi`: http://libcxxabi.llvm.org/ |
| 126 | |
| 127 | |
| 128 | .. _CMake Options: |
| 129 | |
| 130 | CMake Options |
| 131 | ============= |
| 132 | |
| 133 | Here are some of the CMake variables that are used often, along with a |
| 134 | brief explanation and LLVM-specific notes. For full documentation, check the |
| 135 | CMake docs or execute ``cmake --help-variable VARIABLE_NAME``. |
| 136 | |
| 137 | **CMAKE_BUILD_TYPE**:STRING |
| 138 | Sets the build type for ``make`` based generators. Possible values are |
| 139 | Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio |
| 140 | the user sets the build type with the IDE settings. |
| 141 | |
| 142 | **CMAKE_INSTALL_PREFIX**:PATH |
| 143 | Path where LLVM will be installed if "make install" is invoked or the |
| 144 | "INSTALL" target is built. |
| 145 | |
| 146 | **CMAKE_CXX_COMPILER**:STRING |
| 147 | The C++ compiler to use when building and testing libc++. |
| 148 | |
| 149 | |
| 150 | .. _libcxx-specific options: |
| 151 | |
| 152 | libc++ specific options |
| 153 | ----------------------- |
| 154 | |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 155 | .. option:: LIBCXX_INSTALL_LIBRARY:BOOL |
| 156 | |
| 157 | **Default**: ``ON`` |
| 158 | |
| 159 | Toggle the installation of the library portion of libc++. |
| 160 | |
| 161 | .. option:: LIBCXX_INSTALL_HEADERS:BOOL |
| 162 | |
| 163 | **Default**: ``ON`` |
| 164 | |
| 165 | Toggle the installation of the libc++ headers. |
| 166 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 167 | .. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL |
| 168 | |
| 169 | **Default**: ``ON`` |
| 170 | |
| 171 | Build libc++ with assertions enabled. |
| 172 | |
| 173 | .. option:: LIBCXX_BUILD_32_BITS:BOOL |
| 174 | |
| 175 | **Default**: ``OFF`` |
| 176 | |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 177 | Build libc++ as a 32 bit library. Also see `LLVM_BUILD_32_BITS`. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 178 | |
| 179 | .. option:: LIBCXX_ENABLE_SHARED:BOOL |
| 180 | |
| 181 | **Default**: ``ON`` |
| 182 | |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 183 | Build libc++ as a shared library. Either `LIBCXX_ENABLE_SHARED` or |
| 184 | `LIBCXX_ENABLE_STATIC` has to be enabled. |
Petr Hosek | 1362005 | 2016-08-08 22:57:25 +0000 | [diff] [blame] | 185 | |
| 186 | .. option:: LIBCXX_ENABLE_STATIC:BOOL |
| 187 | |
| 188 | **Default**: ``ON`` |
| 189 | |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 190 | Build libc++ as a static library. Either `LIBCXX_ENABLE_SHARED` or |
| 191 | `LIBCXX_ENABLE_STATIC` has to be enabled. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 192 | |
| 193 | .. option:: LIBCXX_LIBDIR_SUFFIX:STRING |
| 194 | |
| 195 | Extra suffix to append to the directory where libraries are to be installed. |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 196 | This option overrides `LLVM_LIBDIR_SUFFIX`. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 197 | |
Petr Hosek | 3975d8d | 2017-07-11 02:39:50 +0000 | [diff] [blame] | 198 | .. option:: LIBCXX_INSTALL_PREFIX:STRING |
| 199 | |
| 200 | **Default**: ``""`` |
| 201 | |
| 202 | Define libc++ destination prefix. |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 203 | |
Petr Hosek | b42e349 | 2019-01-06 06:14:31 +0000 | [diff] [blame] | 204 | .. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL |
| 205 | |
| 206 | **Default**: ``OFF`` |
| 207 | |
Jonathan Metzman | ce2328d | 2019-04-10 23:44:27 +0000 | [diff] [blame] | 208 | Do not export any symbols from the static libc++ library. |
Petr Hosek | b42e349 | 2019-01-06 06:14:31 +0000 | [diff] [blame] | 209 | This is useful when the static libc++ library is being linked into shared |
| 210 | libraries that may be used in with other shared libraries that use different |
Louis Dionne | d088967 | 2019-08-23 19:42:09 +0000 | [diff] [blame] | 211 | C++ library. We want to avoid exporting any libc++ symbols in that case. |
Petr Hosek | b42e349 | 2019-01-06 06:14:31 +0000 | [diff] [blame] | 212 | |
Eric Fiselier | 72e2dd8 | 2019-03-21 00:04:31 +0000 | [diff] [blame] | 213 | .. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL |
| 214 | |
| 215 | **Default**: ``ON`` except on Windows. |
| 216 | |
| 217 | This option can be used to enable or disable the filesystem components on |
| 218 | platforms that may not support them. For example on Windows. |
| 219 | |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 220 | .. _libc++experimental options: |
| 221 | |
| 222 | libc++experimental Specific Options |
| 223 | ------------------------------------ |
| 224 | |
| 225 | .. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL |
| 226 | |
| 227 | **Default**: ``ON`` |
| 228 | |
| 229 | Build and test libc++experimental.a. |
| 230 | |
| 231 | .. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL |
| 232 | |
Eric Fiselier | 121594e | 2016-09-07 01:15:10 +0000 | [diff] [blame] | 233 | **Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY AND LIBCXX_INSTALL_LIBRARY`` |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 234 | |
| 235 | Install libc++experimental.a alongside libc++. |
| 236 | |
| 237 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 238 | .. _ABI Library Specific Options: |
| 239 | |
| 240 | ABI Library Specific Options |
| 241 | ---------------------------- |
| 242 | |
| 243 | .. option:: LIBCXX_CXX_ABI:STRING |
| 244 | |
| 245 | **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``. |
| 246 | |
| 247 | Select the ABI library to build libc++ against. |
| 248 | |
| 249 | .. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS |
| 250 | |
| 251 | Provide additional search paths for the ABI library headers. |
| 252 | |
| 253 | .. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH |
| 254 | |
| 255 | Provide the path to the ABI library that libc++ should link against. |
| 256 | |
| 257 | .. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL |
| 258 | |
| 259 | **Default**: ``OFF`` |
| 260 | |
| 261 | If this option is enabled, libc++ will try and link the selected ABI library |
| 262 | statically. |
| 263 | |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 264 | .. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL |
| 265 | |
| 266 | **Default**: ``ON`` by default on UNIX platforms other than Apple unless |
| 267 | 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``. |
| 268 | |
| 269 | This option generate and installs a linker script as ``libc++.so`` which |
| 270 | links the correct ABI library. |
| 271 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 272 | .. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL |
| 273 | |
| 274 | **Default**: ``OFF`` |
| 275 | |
| 276 | Build and use the LLVM unwinder. Note: This option can only be used when |
| 277 | libc++abi is the C++ ABI library used. |
| 278 | |
| 279 | |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 280 | libc++ Feature Options |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 281 | ---------------------- |
| 282 | |
| 283 | .. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL |
| 284 | |
| 285 | **Default**: ``ON`` |
| 286 | |
| 287 | Build libc++ with exception support. |
| 288 | |
| 289 | .. option:: LIBCXX_ENABLE_RTTI:BOOL |
| 290 | |
| 291 | **Default**: ``ON`` |
| 292 | |
| 293 | Build libc++ with run time type information. |
| 294 | |
Saleem Abdulrasool | 1e06a1d | 2019-07-04 19:08:16 +0000 | [diff] [blame] | 295 | .. option:: LIBCXX_INCLUDE_TESTS:BOOL |
| 296 | |
| 297 | **Default**: ``ON`` (or value of ``LLVM_INCLUDE_DIR``) |
| 298 | |
| 299 | Build the libc++ tests. |
| 300 | |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 301 | .. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 302 | |
Eric Fiselier | 93f212c | 2016-08-29 19:50:49 +0000 | [diff] [blame] | 303 | **Default**: ``ON`` |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 304 | |
| 305 | Build the libc++ benchmark tests and the Google Benchmark library needed |
| 306 | to support them. |
| 307 | |
Eric Fiselier | 453bc18 | 2018-11-14 20:38:46 +0000 | [diff] [blame] | 308 | .. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING |
| 309 | |
| 310 | **Default**: ``--benchmark_min_time=0.01`` |
| 311 | |
| 312 | A semicolon list of arguments to pass when running the libc++ benchmarks using the |
| 313 | ``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time, |
| 314 | since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to |
| 315 | get accurate measurements. |
| 316 | |
Eric Fiselier | 18d2fa3 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 317 | .. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 318 | |
Eric Fiselier | 18d2fa3 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 319 | **Default**:: ``""`` |
| 320 | |
| 321 | **Values**:: ``libc++``, ``libstdc++`` |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 322 | |
| 323 | Build the libc++ benchmark tests and Google Benchmark library against the |
Louis Dionne | ecc8955 | 2019-10-01 20:34:50 +0000 | [diff] [blame] | 324 | specified standard library on the platform. On Linux this can be used to |
Eric Fiselier | 18d2fa3 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 325 | compare libc++ to libstdc++ by building the benchmark tests against both |
| 326 | standard libraries. |
| 327 | |
| 328 | .. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING |
| 329 | |
| 330 | Use the specified GCC toolchain and standard library when building the native |
| 331 | stdlib benchmark tests. |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 332 | |
Louis Dionne | 1821de4 | 2018-08-16 12:44:28 +0000 | [diff] [blame] | 333 | .. option:: LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT:BOOL |
| 334 | |
| 335 | **Default**: ``OFF`` |
| 336 | |
| 337 | Pick the default for whether to constrain ABI-unstable symbols to |
| 338 | each individual translation unit. This setting controls whether |
| 339 | `_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT` is defined by default -- |
| 340 | see the documentation of that macro for details. |
| 341 | |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 342 | |
| 343 | libc++ ABI Feature Options |
| 344 | -------------------------- |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 345 | |
| 346 | The following options allow building libc++ for a different ABI version. |
| 347 | |
| 348 | .. option:: LIBCXX_ABI_VERSION:STRING |
| 349 | |
| 350 | **Default**: ``1`` |
| 351 | |
| 352 | Defines the target ABI version of libc++. |
| 353 | |
| 354 | .. option:: LIBCXX_ABI_UNSTABLE:BOOL |
| 355 | |
| 356 | **Default**: ``OFF`` |
| 357 | |
| 358 | Build the "unstable" ABI version of libc++. Includes all ABI changing features |
| 359 | on top of the current stable version. |
| 360 | |
Eric Fiselier | b33778a | 2018-10-30 21:44:53 +0000 | [diff] [blame] | 361 | .. option:: LIBCXX_ABI_NAMESPACE:STRING |
| 362 | |
| 363 | **Default**: ``__n`` where ``n`` is the current ABI version. |
| 364 | |
| 365 | This option defines the name of the inline ABI versioning namespace. It can be used for building |
| 366 | custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues |
| 367 | with other libc++ versions. |
| 368 | |
| 369 | .. warning:: |
| 370 | When providing a custom namespace, it's the users responsibility to ensure the name won't cause |
Louis Dionne | 6f2c6fb | 2018-11-16 14:57:47 +0000 | [diff] [blame] | 371 | conflicts with other names defined by libc++, both now and in the future. In particular, inline |
| 372 | namespaces of the form ``__[0-9]+`` are strictly reserved by libc++ and may not be used by users. |
| 373 | Doing otherwise could cause conflicts and hinder libc++ ABI evolution. |
Eric Fiselier | b33778a | 2018-10-30 21:44:53 +0000 | [diff] [blame] | 374 | |
Shoaib Meenai | 4ca4b7c | 2017-10-04 23:17:12 +0000 | [diff] [blame] | 375 | .. option:: LIBCXX_ABI_DEFINES:STRING |
| 376 | |
| 377 | **Default**: ``""`` |
| 378 | |
| 379 | A semicolon-separated list of ABI macros to persist in the site config header. |
| 380 | See ``include/__config`` for the list of ABI macros. |
| 381 | |
Eric Fiselier | f356629 | 2019-05-29 02:21:37 +0000 | [diff] [blame] | 382 | |
| 383 | .. option:: LIBCXX_HAS_MERGED_TYPEINFO_NAMES_DEFAULT |
| 384 | |
| 385 | **Default**: ``None``. When defined this option overrides the libraries default configuration |
| 386 | for whether merged type info names are present. |
| 387 | |
| 388 | |
| 389 | Build ``std::type_info`` with the assumption that type info names for a type have been fully |
| 390 | merged are unique across the entire program. This may not be the case for libraries built with |
| 391 | ``-Bsymbolic`` or due to compiler or linker bugs (Ex. llvm.org/PR37398). |
| 392 | |
| 393 | When the value is ``ON`` typeinfo comparisons compare only the pointer value, otherwise ``strcmp`` |
| 394 | is used as a fallback. |
| 395 | |
| 396 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 397 | .. _LLVM-specific variables: |
| 398 | |
| 399 | LLVM-specific options |
| 400 | --------------------- |
| 401 | |
| 402 | .. option:: LLVM_LIBDIR_SUFFIX:STRING |
| 403 | |
| 404 | Extra suffix to append to the directory where libraries are to be |
| 405 | installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` |
| 406 | to install libraries to ``/usr/lib64``. |
| 407 | |
| 408 | .. option:: LLVM_BUILD_32_BITS:BOOL |
| 409 | |
| 410 | Build 32-bits executables and libraries on 64-bits systems. This option is |
Louis Dionne | ecc8955 | 2019-10-01 20:34:50 +0000 | [diff] [blame] | 411 | available only on some 64-bits Unix systems. Defaults to OFF. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 412 | |
| 413 | .. option:: LLVM_LIT_ARGS:STRING |
| 414 | |
| 415 | Arguments given to lit. ``make check`` and ``make clang-test`` are affected. |
| 416 | By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on |
| 417 | others. |
| 418 | |
| 419 | |
| 420 | Using Alternate ABI libraries |
| 421 | ============================= |
| 422 | |
| 423 | |
| 424 | .. _libsupcxx: |
| 425 | |
| 426 | Using libsupc++ on Linux |
| 427 | ------------------------ |
| 428 | |
| 429 | You will need libstdc++ in order to provide libsupc++. |
| 430 | |
| 431 | Figure out where the libsupc++ headers are on your system. On Ubuntu this |
| 432 | is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>`` |
| 433 | |
| 434 | You can also figure this out by running |
| 435 | |
| 436 | .. code-block:: bash |
| 437 | |
| 438 | $ echo | g++ -Wp,-v -x c++ - -fsyntax-only |
| 439 | ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" |
| 440 | ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include" |
| 441 | #include "..." search starts here: |
| 442 | #include <...> search starts here: |
| 443 | /usr/include/c++/4.7 |
| 444 | /usr/include/c++/4.7/x86_64-linux-gnu |
| 445 | /usr/include/c++/4.7/backward |
| 446 | /usr/lib/gcc/x86_64-linux-gnu/4.7/include |
| 447 | /usr/local/include |
| 448 | /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed |
| 449 | /usr/include/x86_64-linux-gnu |
| 450 | /usr/include |
| 451 | End of search list. |
| 452 | |
| 453 | Note that the first two entries happen to be what we are looking for. This |
| 454 | may not be correct on other platforms. |
| 455 | |
| 456 | We can now run CMake: |
| 457 | |
| 458 | .. code-block:: bash |
| 459 | |
| 460 | $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \ |
| 461 | -DLIBCXX_CXX_ABI=libstdc++ \ |
| 462 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \ |
| 463 | -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \ |
| 464 | <libc++-source-dir> |
| 465 | |
| 466 | |
| 467 | You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++`` |
| 468 | above, which will cause the library to be linked to libsupc++ instead |
| 469 | of libstdc++, but this is only recommended if you know that you will |
| 470 | never need to link against libstdc++ in the same executable as libc++. |
| 471 | GCC ships libsupc++ separately but only as a static library. If a |
| 472 | program also needs to link against libstdc++, it will provide its |
| 473 | own copy of libsupc++ and this can lead to subtle problems. |
| 474 | |
| 475 | .. code-block:: bash |
| 476 | |
| 477 | $ make cxx |
| 478 | $ make install |
| 479 | |
| 480 | You can now run clang with -stdlib=libc++. |
Eric Fiselier | a073392 | 2016-06-02 02:16:28 +0000 | [diff] [blame] | 481 | |
| 482 | |
| 483 | .. _libcxxrt_ref: |
| 484 | |
| 485 | Using libcxxrt on Linux |
| 486 | ------------------------ |
| 487 | |
| 488 | You will need to keep the source tree of `libcxxrt`_ available |
| 489 | on your build machine and your copy of the libcxxrt shared library must |
| 490 | be placed where your linker will find it. |
| 491 | |
| 492 | We can now run CMake like: |
| 493 | |
| 494 | .. code-block:: bash |
| 495 | |
| 496 | $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \ |
| 497 | -DLIBCXX_CXX_ABI=libcxxrt \ |
| 498 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src \ |
| 499 | -DCMAKE_BUILD_TYPE=Release \ |
| 500 | -DCMAKE_INSTALL_PREFIX=/usr \ |
| 501 | <libc++-source-directory> |
| 502 | $ make cxx |
| 503 | $ make install |
| 504 | |
| 505 | Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as |
| 506 | clang is set up to link for libc++ linked to libsupc++. To get around this |
| 507 | you'll have to set up your linker yourself (or patch clang). For example, |
| 508 | |
| 509 | .. code-block:: bash |
| 510 | |
| 511 | $ clang++ -stdlib=libc++ helloworld.cpp \ |
| 512 | -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc |
| 513 | |
| 514 | Alternately, you could just add libcxxrt to your libraries list, which in most |
| 515 | situations will give the same result: |
| 516 | |
| 517 | .. code-block:: bash |
| 518 | |
| 519 | $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt |
| 520 | |
| 521 | .. _`libcxxrt`: https://github.com/pathscale/libcxxrt/ |
| 522 | |
| 523 | |
| 524 | Using a local ABI library installation |
| 525 | --------------------------------------- |
| 526 | |
| 527 | .. warning:: |
| 528 | This is not recommended in almost all cases. |
| 529 | |
| 530 | These instructions should only be used when you can't install your ABI library. |
| 531 | |
| 532 | Normally you must link libc++ against a ABI shared library that the |
| 533 | linker can find. If you want to build and test libc++ against an ABI |
Louis Dionne | ecc8955 | 2019-10-01 20:34:50 +0000 | [diff] [blame] | 534 | library not in the linker's path you need to set |
Eric Fiselier | a073392 | 2016-06-02 02:16:28 +0000 | [diff] [blame] | 535 | ``-DLIBCXX_CXX_ABI_LIBRARY_PATH=/path/to/abi/lib`` when configuring CMake. |
| 536 | |
| 537 | An example build using libc++abi would look like: |
| 538 | |
| 539 | .. code-block:: bash |
| 540 | |
| 541 | $ CC=clang CXX=clang++ cmake \ |
| 542 | -DLIBCXX_CXX_ABI=libc++abi \ |
| 543 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/path/to/libcxxabi/include" \ |
| 544 | -DLIBCXX_CXX_ABI_LIBRARY_PATH="/path/to/libcxxabi-build/lib" \ |
| 545 | path/to/libcxx |
| 546 | $ make |
| 547 | |
| 548 | When testing libc++ LIT will automatically link against the proper ABI |
| 549 | library. |