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