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