project.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. project
  2. -------
  3. Set the name of the project.
  4. Synopsis
  5. ^^^^^^^^
  6. .. code-block:: cmake
  7. project(<PROJECT-NAME> [<language-name>...])
  8. project(<PROJECT-NAME>
  9. [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
  10. [DESCRIPTION <project-description-string>]
  11. [HOMEPAGE_URL <url-string>]
  12. [LANGUAGES <language-name>...])
  13. Sets the name of the project, and stores it in the variable
  14. :variable:`PROJECT_NAME`. When called from the top-level
  15. ``CMakeLists.txt`` also stores the project name in the
  16. variable :variable:`CMAKE_PROJECT_NAME`.
  17. Also sets the variables
  18. * :variable:`PROJECT_SOURCE_DIR`,
  19. :variable:`<PROJECT-NAME>_SOURCE_DIR`
  20. * :variable:`PROJECT_BINARY_DIR`,
  21. :variable:`<PROJECT-NAME>_BINARY_DIR`
  22. Further variables are set by the optional arguments described in the following.
  23. If any of these arguments is not used, then the corresponding variables are
  24. set to the empty string.
  25. Options
  26. ^^^^^^^
  27. The options are:
  28. ``VERSION <version>``
  29. Optional; may not be used unless policy :policy:`CMP0048` is
  30. set to ``NEW``.
  31. Takes a ``<version>`` argument composed of non-negative integer components,
  32. i.e. ``<major>[.<minor>[.<patch>[.<tweak>]]]``,
  33. and sets the variables
  34. * :variable:`PROJECT_VERSION`,
  35. :variable:`<PROJECT-NAME>_VERSION`
  36. * :variable:`PROJECT_VERSION_MAJOR`,
  37. :variable:`<PROJECT-NAME>_VERSION_MAJOR`
  38. * :variable:`PROJECT_VERSION_MINOR`,
  39. :variable:`<PROJECT-NAME>_VERSION_MINOR`
  40. * :variable:`PROJECT_VERSION_PATCH`,
  41. :variable:`<PROJECT-NAME>_VERSION_PATCH`
  42. * :variable:`PROJECT_VERSION_TWEAK`,
  43. :variable:`<PROJECT-NAME>_VERSION_TWEAK`.
  44. When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
  45. then the version is also stored in the variable :variable:`CMAKE_PROJECT_VERSION`.
  46. ``DESCRIPTION <project-description-string>``
  47. Optional.
  48. Sets the variables
  49. * :variable:`PROJECT_DESCRIPTION`, :variable:`<PROJECT-NAME>_DESCRIPTION`
  50. to ``<project-description-string>``.
  51. It is recommended that this description is a relatively short string,
  52. usually no more than a few words.
  53. When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
  54. then the description is also stored in the variable :variable:`CMAKE_PROJECT_DESCRIPTION`.
  55. ``HOMEPAGE_URL <url-string>``
  56. Optional.
  57. Sets the variables
  58. * :variable:`PROJECT_HOMEPAGE_URL`, :variable:`<PROJECT-NAME>_HOMEPAGE_URL`
  59. to ``<url-string>``, which should be the canonical home URL for the project.
  60. When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
  61. then the URL also is stored in the variable :variable:`CMAKE_PROJECT_HOMEPAGE_URL`.
  62. ``LANGUAGES <language-name>...``
  63. Optional.
  64. Can also be specified without ``LANGUAGES`` keyword per the first, short signature.
  65. Selects which programming languages are needed to build the project.
  66. Supported languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``,
  67. ``OBJC`` (i.e. Objective-C), ``OBJCXX``, ``Fortran``, and ``ASM``.
  68. By default ``C`` and ``CXX`` are enabled if no language options are given.
  69. Specify language ``NONE``, or use the ``LANGUAGES`` keyword and list no languages,
  70. to skip enabling any languages.
  71. If enabling ``ASM``, list it last so that CMake can check whether
  72. compilers for other languages like ``C`` work for assembly too.
  73. The variables set through the ``VERSION``, ``DESCRIPTION`` and ``HOMEPAGE_URL``
  74. options are intended for use as default values in package metadata and documentation.
  75. Code Injection
  76. ^^^^^^^^^^^^^^
  77. If the :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` variable is set, the file
  78. pointed to by that variable will be included as the first step of the
  79. ``project()`` command.
  80. If the :variable:`CMAKE_PROJECT_INCLUDE` or
  81. :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` variables are set, the files
  82. they point to will be included as the last step of the ``project()`` command.
  83. If both are set, then :variable:`CMAKE_PROJECT_INCLUDE` will be included before
  84. :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`.
  85. Usage
  86. ^^^^^
  87. The top-level ``CMakeLists.txt`` file for a project must contain a
  88. literal, direct call to the ``project()`` command; loading one
  89. through the :command:`include` command is not sufficient. If no such
  90. call exists, CMake will issue a warning and pretend there is a
  91. ``project(Project)`` at the top to enable the default languages
  92. (``C`` and ``CXX``).
  93. .. note::
  94. Call the ``project()`` command near the top of the top-level
  95. ``CMakeLists.txt``, but *after* calling :command:`cmake_minimum_required`.
  96. It is important to establish version and policy settings before invoking
  97. other commands whose behavior they may affect.
  98. See also policy :policy:`CMP0000`.