blob: 8f2d0cd2dd67bc4d4d5fb195ebffd66dcfdb9e47 [file] [log] [blame]
Eric Fiselier5cf9a822015-10-13 22:12:02 +00001=======================================================
2Capturing configuration information during installation
3=======================================================
4
5.. contents::
6 :local:
7
8The Problem
9===========
10
11Currently the libc++ supports building the library with a number of different
12configuration options. Unfortunately all of that configuration information is
13lost when libc++ is installed. In order to support "persistent"
14configurations libc++ needs a mechanism to capture the configuration options
15in the INSTALLED headers.
16
17
18Design Goals
19============
20
21* The solution should not INSTALL any additional headers. We don't want an extra
22 #include slowing everybody down.
23
24* The solution should not unduly affect libc++ developers. The problem is limited
25 to installed versions of libc++ and the solution should be as well.
26
27* The solution should not modify any existing headers EXCEPT during installation.
28 It makes developers lives harder if they have to regenerate the libc++ headers
29 every time they are modified.
30
Sylvestre Ledru80fe8b12018-09-20 08:05:01 +000031* The solution should not make any of the libc++ headers dependent on
Eric Fiselier5cf9a822015-10-13 22:12:02 +000032 files generated by the build system. The headers should be able to compile
33 out of the box without any modification.
34
35* The solution should not have ANY effect on users who don't need special
36 configuration options. The vast majority of users will never need this so it
37 shouldn't cost them.
38
39
40The Solution
41============
42
43When you first configure libc++ using CMake we check to see if we need to
44capture any options. If we haven't been given any "persistent" options then
45we do NOTHING.
46
47Otherwise we create a custom installation rule that modifies the installed __config
48header. The rule first generates a dummy "__config_site" header containing the required
Bruce Mitchener2715e2c2018-02-13 08:12:00 +000049#defines. The contents of the dummy header are then prepended to the installed
Eric Fiselier5cf9a822015-10-13 22:12:02 +000050__config header. By manually prepending the files we avoid the cost of an
51extra #include and we allow the __config header to be ignorant of the extra
Eric Fiselier0111ae62015-10-13 22:22:42 +000052configuration all together. An example "__config" header generated when
Eric Fiselier5cf9a822015-10-13 22:12:02 +000053-DLIBCXX_ENABLE_THREADS=OFF is given to CMake would look something like:
54
55.. code-block:: cpp
56
57 //===----------------------------------------------------------------------===//
58 //
Chandler Carruth12dc4232019-01-19 11:54:04 +000059 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
60 // See https://llvm.org/LICENSE.txt for license information.
61 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Eric Fiselier5cf9a822015-10-13 22:12:02 +000062 //
63 //===----------------------------------------------------------------------===//
64
65 #ifndef _LIBCPP_CONFIG_SITE
66 #define _LIBCPP_CONFIG_SITE
67
68 /* #undef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE */
69 /* #undef _LIBCPP_HAS_NO_STDIN */
70 /* #undef _LIBCPP_HAS_NO_STDOUT */
71 #define _LIBCPP_HAS_NO_THREADS
72 /* #undef _LIBCPP_HAS_NO_MONOTONIC_CLOCK */
73 /* #undef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS */
74
75 #endif
76 // -*- C++ -*-
77 //===--------------------------- __config ---------------------------------===//
78 //
Chandler Carruth12dc4232019-01-19 11:54:04 +000079 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
80 // See https://llvm.org/LICENSE.txt for license information.
81 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Eric Fiselier5cf9a822015-10-13 22:12:02 +000082 //
83 //===----------------------------------------------------------------------===//
84
85 #ifndef _LIBCPP_CONFIG
86 #define _LIBCPP_CONFIG