source.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 **3.8** 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 supports compiling as C++98 in addition to C++11 and C++14.
  20. In order to support building on older toolchains some constructs
  21. need to be handled with care:
  22. * Use ``CM_AUTO_PTR`` instead of ``std::auto_ptr``.
  23. The ``std::auto_ptr`` template is deprecated in C++11. We want to use it
  24. so we can build on C++98 compilers but we do not want to turn off compiler
  25. warnings about deprecated interfaces in general. Use the ``CM_AUTO_PTR``
  26. macro instead.
  27. * Use ``CM_EQ_DELETE;`` instead of ``= delete;``.
  28. Defining functions as *deleted* is not supported in C++98. Using
  29. ``CM_EQ_DELETE`` will delete the functions if the compiler supports it and
  30. give them no implementation otherwise. Calling such a function will lead
  31. to compiler errors if the compiler supports *deleted* functions and linker
  32. errors otherwise.
  33. * Use ``CM_DISABLE_COPY(Class)`` to mark classes as non-copyable.
  34. The ``CM_DISABLE_COPY`` macro should be used in the private section of a
  35. class to make sure that attempts to copy or assign an instance of the class
  36. lead to compiler errors even if the compiler does not support *deleted*
  37. functions. As a guideline, all polymorphic classes should be made
  38. non-copyable in order to avoid slicing. Classes that are composed of or
  39. derived from non-copyable classes must also be made non-copyable explicitly
  40. with ``CM_DISABLE_COPY``.
  41. * Use ``size_t`` instead of ``std::size_t``.
  42. Various implementations have differing implementation of ``size_t``.
  43. When assigning the result of ``.size()`` on a container for example,
  44. the result should be assigned to ``size_t`` not to ``std::size_t``,
  45. ``unsigned int`` or similar types.