source.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 ``std::auto_ptr``.
  22. The ``std::auto_ptr`` template is deprecated in C++11. Use ``std::unique_ptr``.
  23. * Use ``CM_DISABLE_COPY(Class)`` to mark classes as non-copyable.
  24. The ``CM_DISABLE_COPY`` macro should be used in the private section of a
  25. class to make sure that attempts to copy or assign an instance of the class
  26. lead to compiler errors even if the compiler does not support *deleted*
  27. functions. As a guideline, all polymorphic classes should be made
  28. non-copyable in order to avoid slicing. Classes that are composed of or
  29. derived from non-copyable classes must also be made non-copyable explicitly
  30. with ``CM_DISABLE_COPY``.
  31. * Use ``size_t`` instead of ``std::size_t``.
  32. Various implementations have differing implementation of ``size_t``.
  33. When assigning the result of ``.size()`` on a container for example,
  34. the result should be assigned to ``size_t`` not to ``std::size_t``,
  35. ``unsigned int`` or similar types.
  36. Source Tree Layout
  37. ==================
  38. The CMake source tree is organized as follows.
  39. * ``Auxiliary/``:
  40. Shell and editor integration files.
  41. * ``Help/``:
  42. Documentation.
  43. * ``Help/dev/``:
  44. Developer documentation.
  45. * ``Help/release/dev/``:
  46. Release note snippets for development since last release.
  47. * ``Licenses/``:
  48. License files for third-party libraries in binary distributions.
  49. * ``Modules/``:
  50. CMake language modules installed with CMake.
  51. * ``Packaging/``:
  52. Files used for packaging CMake itself for distribution.
  53. * ``Source/``:
  54. Source code of CMake itself.
  55. * ``Templates/``:
  56. Files distributed with CMake as implementation details for generators,
  57. packagers, etc.
  58. * ``Tests/``:
  59. The test suite. See `Tests/README.rst`_.
  60. * ``Utilities/``:
  61. Scripts, third-party source code.
  62. * ``Utilities/Sphinx/``:
  63. Sphinx configuration to build CMake user documentation.
  64. * ``Utilities/Release/``:
  65. Scripts used to package CMake itself for distribution on ``cmake.org``.
  66. .. _`Tests/README.rst`: ../../Tests/README.rst