1 CMake Source Code Guide
2 ***********************
4 The following is a guide to the CMake source code for developers.
5 See documentation on `CMake Development`_ for more information.
7 .. _`CMake Development`: README.rst
12 We use `clang-format`_ version **6.0** to define our style for C++ code in
13 the CMake source tree. See the `.clang-format`_ configuration file for our
14 style settings. Use the `Utilities/Scripts/clang-format.bash`_ script to
15 format source code. It automatically runs ``clang-format`` on the set of
16 source files for which we enforce style. The script also has options to
17 format only a subset of files, such as those that are locally modified.
19 .. _`clang-format`: http://clang.llvm.org/docs/ClangFormat.html
20 .. _`.clang-format`: ../../.clang-format
21 .. _`Utilities/Scripts/clang-format.bash`: ../../Utilities/Scripts/clang-format.bash
26 CMake requires compiling as C++11 in order to support building on older
27 toolchains. However, to facilitate development, some standard library
28 features from more recent C++ standards are supported through a compatibility
29 layer. These features are defined under the namespace ``cm`` and headers
30 are accessible under the ``cm/`` directory. The headers under ``cm/`` can
31 be used in place of the standard ones when extended features are needed.
32 For example ``<cm/memory>`` can be used in place of ``<memory>``.
34 Available features are:
39 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
40 ``cm::crbegin``, ``cm::crend``
43 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
44 ``cm::crbegin``, ``cm::crend``
46 * ``<cm/forward_list>``:
47 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
48 ``cm::crbegin``, ``cm::crend``
54 ``cm::make_reverse_iterator``, ``cm::cbegin``, ``cm::cend``,
55 ``cm::rbegin``, ``cm::rend``, ``cm::crbegin``, ``cm::crend``
58 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
59 ``cm::crbegin``, ``cm::crend``
62 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
63 ``cm::crbegin``, ``cm::crend``
69 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
70 ``cm::crbegin``, ``cm::crend``
73 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
74 ``cm::crbegin``, ``cm::crend``
76 * ``<cm/string_view>``:
77 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
78 ``cm::crbegin``, ``cm::crend``
80 * ``<cm/shared_mutex>``:
83 * ``<cm/type_traits>``:
86 * ``<cm/unordered_map>``:
87 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
88 ``cm::crbegin``, ``cm::crend``
90 * ``<cm/unordered_set>``:
91 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
92 ``cm::crbegin``, ``cm::crend``
95 ``cm::cbegin``, ``cm::cend``, ``cm::rbegin``, ``cm::rend``,
96 ``cm::crbegin``, ``cm::crend``
100 * ``<cm/algorithm>``:
104 ``cm::size``, ``cm::empty``, ``cm::data``
107 ``cm::size``, ``cm::empty``, ``cm::data``
109 * ``cm/filesystem>``:
110 ``cm::filesystem::path``
112 * ``<cm/forward_list>``:
113 ``cm::size``, ``cm::empty``, ``cm::data``
116 ``cm::size``, ``cm::empty``, ``cm::data``
119 ``cm::size``, ``cm::empty``, ``cm::data``
122 ``cm::size``, ``cm::empty``, ``cm::data``
125 ``cm::nullopt_t``, ``cm::nullopt``, ``cm::optional``,
126 ``cm::make_optional``, ``cm::bad_optional_access``
129 ``cm::size``, ``cm::empty``, ``cm::data``
131 * ``<cm/shared_mutex>``:
135 ``cm::size``, ``cm::empty``, ``cm::data``
137 * ``<cm/string_view>``:
138 ``cm::string_view``, ``cm::size``, ``cm::empty``, ``cm::data``
140 * ``<cm/type_traits>``:
141 ``cm::bool_constant``, ``cm::invoke_result_t``, ``cm::invoke_result``,
144 * ``<cm/unordered_map>``:
145 ``cm::size``, ``cm::empty``, ``cm::data``
147 * ``<cm/unordered_set>``:
148 ``cm::size``, ``cm::empty``, ``cm::data``
151 ``cm::in_place_t``, ``cm::in_place``
154 ``cm::size``, ``cm::empty``, ``cm::data``
162 ``cm::erase``, ``cm::erase_if``, ``cm::ssize``
164 * ``<cm/forward_list>``:
171 ``cm::erase``, ``cm::erase_if``, ``cm::ssize``
174 ``cm::erase_if``, ``cm::ssize``
177 ``cm::erase_if``, ``cm::ssize``
179 * ``<cm/string_view>``:
183 ``cm::erase``, ``cm::erase_if``, ``cm::ssize``
185 * ``<cm/unordered_map>``:
186 ``cm::erase_if``, ``cm::ssize``
188 * ``<cm/unordered_set>``:
189 ``cm::erase_if``, ``cm::ssize``
192 ``cm::erase``, ``cm::erase_if``, ``cm::ssize``
194 Additionally, some useful non-standard extensions to the C++ standard library
195 are available in headers under the directory ``cmext/`` in namespace ``cm``.
198 * ``<cmext/algorithm>``:
201 Append elements to a sequential container.
204 Checks if element or key is contained in container.
206 * ``<cmext/enum_set>``
209 Container to manage set of elements from an ``enum class`` definition.
211 * ``<cmext/iterator>``:
213 * ``cm::is_terator``:
214 Checks if a type is an iterator type.
216 * ``cm::is_input_iterator``:
217 Checks if a type is an input iterator type.
220 Checks if a type is a range type: functions ``std::begin()`` and
221 ``std::end()`` apply.
223 * ``cm::is_input_range``:
224 Checks if a type is an input range type: functions ``std::begin()`` and
225 ``std::end()`` apply and return an input iterator.
227 * ``<cmext/memory>``:
229 * ``cm::static_reference_cast``:
230 Apply a ``static_cast`` to a smart pointer.
232 * ``cm::dynamic_reference_cast``:
233 Apply a ``dynamic_cast`` to a smart pointer.
235 * ``<cmext/type_traits>``:
237 * ``cm::is_container``:
238 Checks if a type is a container type.
240 * ``cm::is_associative_container``:
241 Checks if a type is an associative container type.
243 * ``cm::is_unordered_associative_container``:
244 Checks if a type is an unordered associative container type.
246 * ``cm::is_sequence_container``:
247 Checks if a type is a sequence container type.
249 * ``cm::is_unique_ptr``:
250 Checks if a type is a ``std::unique_ptr`` type.
252 CMake assumes the compiler supports ``#pragma once``. Use this for all
253 hand-written header files.
255 Dynamic Memory Management
256 =========================
258 To ensure efficient memory management, i.e. no memory leaks, it is required
259 to use smart pointers. Any dynamic memory allocation must be handled by a
260 smart pointer such as ``std::unique_ptr`` or ``std::shared_ptr``.
262 It is allowed to pass raw pointers between objects to enable objects sharing.
263 A raw pointer **must** not be deleted. Only the object(s) owning the smart
264 pointer are allowed to delete dynamically allocated memory.
269 To build CMake, some third parties are needed. Under ``Utilities``
270 directory, are versions of these third parties which can be used as an
271 alternate to the ones provided by the system.
273 To enable the selection of the third parties between the system and CMake ones,
274 in CMake sources, third parties headers must be prefixed by ``cm3p/``
275 (for example: ``<cm3p/json/reader.h>``). These wrappers are located under
276 ``Utilities/cm3p`` directory.
281 The CMake source tree is organized as follows.
284 Shell and editor integration files.
287 Documentation. See the `CMake Documentation Guide`_.
290 Developer documentation.
292 * ``Help/release/dev/``:
293 Release note snippets for development since last release.
296 License files for third-party libraries in binary distributions.
299 CMake language modules installed with CMake.
302 Files used for packaging CMake itself for distribution.
305 Source code of CMake itself.
308 Files distributed with CMake as implementation details for generators,
312 The test suite. See `Tests/README.rst`_.
315 Scripts, third-party source code.
317 * ``Utilities/std/cm``:
318 Support files for various C++ standards.
320 * ``Utilities/std/cmext``:
321 Extensions to the C++ STL.
323 * ``Utilities/cm3p``:
324 Public headers for third parties needed to build CMake.
326 * ``Utilities/Sphinx/``:
327 Sphinx configuration to build CMake user documentation.
329 * ``Utilities/Release/``:
330 Scripts used to package CMake itself for distribution on ``cmake.org``.
331 See `Utilities/Release/README.rst`_.
333 .. _`CMake Documentation Guide`: documentation.rst
334 .. _`Tests/README.rst`: ../../Tests/README.rst
335 .. _`Utilities/Release/README.rst`: ../../Utilities/Release/README.rst