CapturingConfigInfo.rst 3.3 KB

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