source.rst 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. CMake Source Code Guide
  2. ***********************
  3. The following is a guide to the CMake source code for developers.
  4. See documentation on `CMake Development`_ for more information.
  5. .. _`CMake Development`: README.rst
  6. C++ Code Style
  7. ==============
  8. We use `clang-format`_ version **6.0** to define our style for C++ code in
  9. the CMake source tree. See the `.clang-format`_ configuration file for our
  10. style settings. Use the `Utilities/Scripts/clang-format.bash`_ script to
  11. format source code. It automatically runs ``clang-format`` on the set of
  12. source files for which we enforce style. The script also has options to
  13. format only a subset of files, such as those that are locally modified.
  14. .. _`clang-format`: http://clang.llvm.org/docs/ClangFormat.html
  15. .. _`.clang-format`: ../../.clang-format
  16. .. _`Utilities/Scripts/clang-format.bash`: ../../Utilities/Scripts/clang-format.bash
  17. C++ Subset Permitted
  18. ====================
  19. CMake requires compiling as C++11 in order to support building on older
  20. toolchains. However, to facilitate development, some standard library
  21. features from more recent C++ standards are supported through a compatibility
  22. layer. These features are defined under the namespace ``cm`` and headers
  23. are accessible under the ``cm/`` directory. The headers under ``cm/`` can
  24. be used in place of the standard ones when extended features are needed.
  25. For example ``<cm/memory>`` can be used in place of ``<memory>``.
  26. Available features are:
  27. * From ``C++14``:
  28. * ``<cm/iterator>``:
  29. ``cm::make_reverse_iterator``, ``cm::cbegin``, ``cm::cend``,
  30. ``cm::rbegin``, ``cm::rend``, ``cm::crbegin``, ``cm::crend``
  31. * ``<cm/memory>``:
  32. ``cm::make_unique``
  33. * ``<cm/shared_mutex>``:
  34. ``cm::shared_lock``
  35. * ``<cm/type_traits>``:
  36. ``cm::enable_if_t``
  37. * From ``C++17``:
  38. * ``<cm/algorithm>``:
  39. ``cm::clamp``
  40. * ``<cm/iterator>``:
  41. ``cm::size``, ``cm::empty``, ``cm::data``
  42. * ``<cm/optional>``:
  43. ``cm::nullopt_t``, ``cm::nullopt``, ``cm::optional``,
  44. ``cm::make_optional``, ``cm::bad_optional_access``
  45. * ``<cm/shared_mutex>``:
  46. ``cm::shared_mutex``
  47. * ``<cm/string_view>``:
  48. ``cm::string_view``
  49. * ``<cm/type_traits>``:
  50. ``cm::bool_constant``, ``cm::invoke_result_t``, ``cm::invoke_result``,
  51. ``cm::void_t``
  52. * ``<cm/utility>``:
  53. ``cm::in_place_t``, ``cm::in_place``
  54. * From ``C++20``:
  55. * ``<cm/deque>``:
  56. ``cm::erase``, ``cm::erase_if``
  57. * ``<cm/list>``:
  58. ``cm::erase``, ``cm::erase_if``
  59. * ``<cm/map>`` :
  60. ``cm::erase_if``
  61. * ``<cm/set>`` :
  62. ``cm::erase_if``
  63. * ``<cm/string>``:
  64. ``cm::erase``, ``cm::erase_if``
  65. * ``<cm/unordered_map>``:
  66. ``cm::erase_if``
  67. * ``<cm/unordered_set>``:
  68. ``cm::erase_if``
  69. * ``<cm/vector>``:
  70. ``cm::erase``, ``cm::erase_if``
  71. Additionally, some useful non-standard extensions to the C++ standard library
  72. are available in headers under the directory ``cmext/`` in namespace ``cm``.
  73. These are:
  74. * ``<cmext/algorithm>``:
  75. * ``cm::append``:
  76. Append elements to a sequential container.
  77. * ``<cmext/iterator>``:
  78. * ``cm::is_terator``:
  79. Checks if a type is an iterator type.
  80. * ``cm::is_input_iterator``:
  81. Checks if a type is an input iterator type.
  82. * ``cm::is_range``:
  83. Checks if a type is a range type: must have methods ``begin()`` and
  84. ``end()`` returning an iterator.
  85. * ``cm::is_input_range``:
  86. Checks if a type is an input range type: must have methods ``begin()`` and
  87. ``end()`` returning an input iterator.
  88. * ``<cmext/memory>``:
  89. * ``cm::static_reference_cast``:
  90. Apply a ``static_cast`` to a smart pointer.
  91. * ``cm::dynamic_reference_cast``:
  92. Apply a ``dynamic_cast`` to a smart pointer.
  93. * ``<cmext/type_traits>``:
  94. * ``cm::is_container``:
  95. Checks if a type is a container type.
  96. * ``cm::is_associative_container``:
  97. Checks if a type is an associative container type.
  98. * ``cm::is_unordered_associative_container``:
  99. Checks if a type is an unordered associative container type.
  100. * ``cm::is_sequence_container``:
  101. Checks if a type is a sequence container type.
  102. * ``cm::is_unique_ptr``:
  103. Checks if a type is a ``std::unique_ptr`` type.
  104. Dynamic Memory Management
  105. =========================
  106. To ensure efficient memory management, i.e. no memory leaks, it is required
  107. to use smart pointers. Any dynamic memory allocation must be handled by a
  108. smart pointer such as ``std::unique_ptr`` or ``std::shared_ptr``.
  109. It is allowed to pass raw pointers between objects to enable objects sharing.
  110. A raw pointer **must** not be deleted. Only the object(s) owning the smart
  111. pointer are allowed to delete dynamically allocated memory.
  112. Source Tree Layout
  113. ==================
  114. The CMake source tree is organized as follows.
  115. * ``Auxiliary/``:
  116. Shell and editor integration files.
  117. * ``Help/``:
  118. Documentation. See the `CMake Documentation Guide`_.
  119. * ``Help/dev/``:
  120. Developer documentation.
  121. * ``Help/release/dev/``:
  122. Release note snippets for development since last release.
  123. * ``Licenses/``:
  124. License files for third-party libraries in binary distributions.
  125. * ``Modules/``:
  126. CMake language modules installed with CMake.
  127. * ``Packaging/``:
  128. Files used for packaging CMake itself for distribution.
  129. * ``Source/``:
  130. Source code of CMake itself.
  131. * ``Templates/``:
  132. Files distributed with CMake as implementation details for generators,
  133. packagers, etc.
  134. * ``Tests/``:
  135. The test suite. See `Tests/README.rst`_.
  136. * ``Utilities/``:
  137. Scripts, third-party source code.
  138. * ``Utilities/std/cm``:
  139. Support files for various C++ standards.
  140. * ``Utilities/std/cmext``:
  141. Extensions to the C++ STL.
  142. * ``Utilities/Sphinx/``:
  143. Sphinx configuration to build CMake user documentation.
  144. * ``Utilities/Release/``:
  145. Scripts used to package CMake itself for distribution on ``cmake.org``.
  146. See `Utilities/Release/README.rst`_.
  147. .. _`CMake Documentation Guide`: documentation.rst
  148. .. _`Tests/README.rst`: ../../Tests/README.rst
  149. .. _`Utilities/Release/README.rst`: ../../Utilities/Release/README.rst