source.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 requires compiling as C++11 or above. However, in order to support
  20. building on older toolchains some constructs need to be handled with care:
  21. * Do not use ``CM_AUTO_PTR`` or ``std::auto_ptr``.
  22. The ``std::auto_ptr`` template is deprecated in C++11. The ``CM_AUTO_PTR``
  23. macro remains leftover from C++98 support until its uses can be ported to
  24. ``std::unique_ptr``. Do not add new uses of the macro.
  25. * Use ``CM_EQ_DELETE;`` instead of ``= delete;``.
  26. Older C++11 compilers do not support deleting functions. Using
  27. ``CM_EQ_DELETE`` will delete the functions if the compiler supports it and
  28. give them no implementation otherwise. Calling such a function will lead
  29. to compiler errors if the compiler supports *deleted* functions and linker
  30. errors otherwise.
  31. * Use ``CM_DISABLE_COPY(Class)`` to mark classes as non-copyable.
  32. The ``CM_DISABLE_COPY`` macro should be used in the private section of a
  33. class to make sure that attempts to copy or assign an instance of the class
  34. lead to compiler errors even if the compiler does not support *deleted*
  35. functions. As a guideline, all polymorphic classes should be made
  36. non-copyable in order to avoid slicing. Classes that are composed of or
  37. derived from non-copyable classes must also be made non-copyable explicitly
  38. with ``CM_DISABLE_COPY``.
  39. * Use ``size_t`` instead of ``std::size_t``.
  40. Various implementations have differing implementation of ``size_t``.
  41. When assigning the result of ``.size()`` on a container for example,
  42. the result should be assigned to ``size_t`` not to ``std::size_t``,
  43. ``unsigned int`` or similar types.
  44. Source Tree Layout
  45. ==================
  46. The CMake source tree is organized as follows.
  47. * ``Auxiliary/``:
  48. Shell and editor integration files.
  49. * ``Help/``:
  50. Documentation.
  51. * ``Help/dev/``:
  52. Developer documentation.
  53. * ``Help/release/dev/``:
  54. Release note snippets for development since last release.
  55. * ``Licenses/``:
  56. License files for third-party libraries in binary distributions.
  57. * ``Modules/``:
  58. CMake language modules installed with CMake.
  59. * ``Packaging/``:
  60. Files used for packaging CMake itself for distribution.
  61. * ``Source/``:
  62. Source code of CMake itself.
  63. * ``Templates/``:
  64. Files distributed with CMake as implementation details for generators,
  65. packagers, etc.
  66. * ``Tests/``:
  67. The test suite. See `Tests/README.rst`_.
  68. * ``Utilities/``:
  69. Scripts, third-party source code.
  70. * ``Utilities/Sphinx/``:
  71. Sphinx configuration to build CMake user documentation.
  72. * ``Utilities/Release/``:
  73. Scripts used to package CMake itself for distribution on ``cmake.org``.
  74. .. _`Tests/README.rst`: ../../Tests/README.rst