Files
CMake/Help/dev/source.rst
Brad King fd4fd9a276 Require C++11 to build CMake itself
CMake can now compile as C++11 on all supported platforms.  Check that
std::unique_ptr is available and fail early if missing.  This will allow
us to use C++11 more broadly in CMake's implementation (previously it
was restricted to the serve mode implementation).

Co-Author: Daniel Pfeifer <daniel@pfeifer-mail.de>
2017-08-16 10:13:38 -04:00

106 lines
3.5 KiB
ReStructuredText

CMake Source Code Guide
***********************
The following is a guide to the CMake source code for developers.
See documentation on `CMake Development`_ for more information.
.. _`CMake Development`: README.rst
C++ Code Style
==============
We use `clang-format`_ version **3.8** to define our style for C++ code in
the CMake source tree. See the `.clang-format`_ configuration file for our
style settings. Use the `Utilities/Scripts/clang-format.bash`_ script to
format source code. It automatically runs ``clang-format`` on the set of
source files for which we enforce style. The script also has options to
format only a subset of files, such as those that are locally modified.
.. _`clang-format`: http://clang.llvm.org/docs/ClangFormat.html
.. _`.clang-format`: ../../.clang-format
.. _`Utilities/Scripts/clang-format.bash`: ../../Utilities/Scripts/clang-format.bash
C++ Subset Permitted
====================
CMake requires compiling as C++11 or above. However, in order to support
building on older toolchains some constructs need to be handled with care:
* Do not use ``CM_AUTO_PTR`` or ``std::auto_ptr``.
The ``std::auto_ptr`` template is deprecated in C++11. The ``CM_AUTO_PTR``
macro remains leftover from C++98 support until its uses can be ported to
``std::unique_ptr``. Do not add new uses of the macro.
* Use ``CM_EQ_DELETE;`` instead of ``= delete;``.
Older C++11 compilers do not support deleting functions. Using
``CM_EQ_DELETE`` will delete the functions if the compiler supports it and
give them no implementation otherwise. Calling such a function will lead
to compiler errors if the compiler supports *deleted* functions and linker
errors otherwise.
* Use ``CM_DISABLE_COPY(Class)`` to mark classes as non-copyable.
The ``CM_DISABLE_COPY`` macro should be used in the private section of a
class to make sure that attempts to copy or assign an instance of the class
lead to compiler errors even if the compiler does not support *deleted*
functions. As a guideline, all polymorphic classes should be made
non-copyable in order to avoid slicing. Classes that are composed of or
derived from non-copyable classes must also be made non-copyable explicitly
with ``CM_DISABLE_COPY``.
* Use ``size_t`` instead of ``std::size_t``.
Various implementations have differing implementation of ``size_t``.
When assigning the result of ``.size()`` on a container for example,
the result should be assigned to ``size_t`` not to ``std::size_t``,
``unsigned int`` or similar types.
Source Tree Layout
==================
The CMake source tree is organized as follows.
* ``Auxiliary/``:
Shell and editor integration files.
* ``Help/``:
Documentation.
* ``Help/dev/``:
Developer documentation.
* ``Help/release/dev/``:
Release note snippets for development since last release.
* ``Licenses/``:
License files for third-party libraries in binary distributions.
* ``Modules/``:
CMake language modules installed with CMake.
* ``Packaging/``:
Files used for packaging CMake itself for distribution.
* ``Source/``:
Source code of CMake itself.
* ``Templates/``:
Files distributed with CMake as implementation details for generators,
packagers, etc.
* ``Tests/``:
The test suite. See `Tests/README.rst`_.
* ``Utilities/``:
Scripts, third-party source code.
* ``Utilities/Sphinx/``:
Sphinx configuration to build CMake user documentation.
* ``Utilities/Release/``:
Scripts used to package CMake itself for distribution on ``cmake.org``.
.. _`Tests/README.rst`: ../../Tests/README.rst