project.rst 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. .. versionadded:: 3.12
  45. When the ``project()`` command is called from the top-level
  46. ``CMakeLists.txt``, then the version is also stored in the variable
  47. :variable:`CMAKE_PROJECT_VERSION`.
  48. ``DESCRIPTION <project-description-string>``
  49. .. versionadded:: 3.9
  50. Optional.
  51. Sets the variables
  52. * :variable:`PROJECT_DESCRIPTION`, :variable:`<PROJECT-NAME>_DESCRIPTION`
  53. to ``<project-description-string>``.
  54. It is recommended that this description is a relatively short string,
  55. usually no more than a few words.
  56. When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
  57. then the description is also stored in the variable :variable:`CMAKE_PROJECT_DESCRIPTION`.
  58. .. versionadded:: 3.12
  59. Added the ``<PROJECT-NAME>_DESCRIPTION`` variable.
  60. ``HOMEPAGE_URL <url-string>``
  61. .. versionadded:: 3.12
  62. Optional.
  63. Sets the variables
  64. * :variable:`PROJECT_HOMEPAGE_URL`, :variable:`<PROJECT-NAME>_HOMEPAGE_URL`
  65. to ``<url-string>``, which should be the canonical home URL for the project.
  66. When the ``project()`` command is called from the top-level ``CMakeLists.txt``,
  67. then the URL also is stored in the variable :variable:`CMAKE_PROJECT_HOMEPAGE_URL`.
  68. ``LANGUAGES <language-name>...``
  69. Optional.
  70. Can also be specified without ``LANGUAGES`` keyword per the first, short signature.
  71. Selects which programming languages are needed to build the project.
  72. Supported languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``,
  73. ``OBJC`` (i.e. Objective-C), ``OBJCXX``, ``Fortran``, ``ISPC``, and ``ASM``.
  74. By default ``C`` and ``CXX`` are enabled if no language options are given.
  75. Specify language ``NONE``, or use the ``LANGUAGES`` keyword and list no languages,
  76. to skip enabling any languages.
  77. .. versionadded:: 3.8
  78. Added ``CUDA`` support.
  79. .. versionadded:: 3.16
  80. Added ``OBJC`` and ``OBJCXX`` support.
  81. .. versionadded:: 3.18
  82. Added ``ISPC`` support.
  83. If enabling ``ASM``, list it last so that CMake can check whether
  84. compilers for other languages like ``C`` work for assembly too.
  85. The variables set through the ``VERSION``, ``DESCRIPTION`` and ``HOMEPAGE_URL``
  86. options are intended for use as default values in package metadata and documentation.
  87. Code Injection
  88. ^^^^^^^^^^^^^^
  89. If the :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` or
  90. :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE` variables are set,
  91. the files they point to will be included as the first step of the
  92. ``project()`` command.
  93. If both are set, then :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` will be
  94. included before :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE`.
  95. If the :variable:`CMAKE_PROJECT_INCLUDE` or
  96. :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` variables are set, the files
  97. they point to will be included as the last step of the ``project()`` command.
  98. If both are set, then :variable:`CMAKE_PROJECT_INCLUDE` will be included before
  99. :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`.
  100. .. versionadded:: 3.15
  101. Added the ``CMAKE_PROJECT_INCLUDE`` and ``CMAKE_PROJECT_INCLUDE_BEFORE``
  102. variables.
  103. .. versionadded:: 3.17
  104. Added the ``CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE_BEFORE`` variable.
  105. Usage
  106. ^^^^^
  107. The top-level ``CMakeLists.txt`` file for a project must contain a
  108. literal, direct call to the ``project()`` command; loading one
  109. through the :command:`include` command is not sufficient. If no such
  110. call exists, CMake will issue a warning and pretend there is a
  111. ``project(Project)`` at the top to enable the default languages
  112. (``C`` and ``CXX``).
  113. .. note::
  114. Call the ``project()`` command near the top of the top-level
  115. ``CMakeLists.txt``, but *after* calling :command:`cmake_minimum_required`.
  116. It is important to establish version and policy settings before invoking
  117. other commands whose behavior they may affect.
  118. See also policy :policy:`CMP0000`.