project.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. If the variable :variable:`CMAKE_PROJECT_INCLUDE_BEFORE` exists, the file
  26. pointed to by that variable will be included as the first step of the project
  27. command.
  28. If the variable :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`
  29. or :variable:`CMAKE_PROJECT_INCLUDE` exists, the file pointed to by that
  30. variable will be included as the last step of the project command.
  31. Options
  32. ^^^^^^^
  33. The options are:
  34. ``VERSION <version>``
  35. Optional; may not be used unless policy :policy:`CMP0048` is
  36. set to ``NEW``.
  37. Takes a ``<version>`` argument composed of non-negative integer components,
  38. i.e. ``<major>[.<minor>[.<patch>[.<tweak>]]]``,
  39. and sets the variables
  40. * :variable:`PROJECT_VERSION`,
  41. :variable:`<PROJECT-NAME>_VERSION`
  42. * :variable:`PROJECT_VERSION_MAJOR`,
  43. :variable:`<PROJECT-NAME>_VERSION_MAJOR`
  44. * :variable:`PROJECT_VERSION_MINOR`,
  45. :variable:`<PROJECT-NAME>_VERSION_MINOR`
  46. * :variable:`PROJECT_VERSION_PATCH`,
  47. :variable:`<PROJECT-NAME>_VERSION_PATCH`
  48. * :variable:`PROJECT_VERSION_TWEAK`,
  49. :variable:`<PROJECT-NAME>_VERSION_TWEAK`.
  50. When the :command:`project()` command is called from the top-level ``CMakeLists.txt``,
  51. then the version is also stored in the variable :variable:`CMAKE_PROJECT_VERSION`.
  52. ``DESCRIPTION <project-description-string>``
  53. Optional.
  54. Sets the variables
  55. * :variable:`PROJECT_DESCRIPTION`, :variable:`<PROJECT-NAME>_DESCRIPTION`
  56. to ``<project-description-string>``.
  57. It is recommended that this description is a relatively short string,
  58. usually no more than a few words.
  59. When the :command:`project()` command is called from the top-level ``CMakeLists.txt``,
  60. then the description is also stored in the variable :variable:`CMAKE_PROJECT_DESCRIPTION`.
  61. ``HOMEPAGE_URL <url-string>``
  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 :command:`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``, ``Fortran``, and ``ASM``.
  73. By default ``C`` and ``CXX`` are enabled if no language options are given.
  74. Specify language ``NONE``, or use the ``LANGUAGES`` keyword and list no languages,
  75. to skip enabling any languages.
  76. If enabling ``ASM``, list it last so that CMake can check whether
  77. compilers for other languages like ``C`` work for assembly too.
  78. The variables set through the ``VERSION``, ``DESCRIPTION`` and ``HOMEPAGE_URL``
  79. options are intended for use as default values in package metadata and documentation.
  80. Usage
  81. ^^^^^
  82. The top-level ``CMakeLists.txt`` file for a project must contain a
  83. literal, direct call to the :command:`project` command; loading one
  84. through the :command:`include` command is not sufficient. If no such
  85. call exists CMake will implicitly add one to the top that enables the
  86. default languages (``C`` and ``CXX``).
  87. .. note::
  88. Call the :command:`cmake_minimum_required` command at the beginning
  89. of the top-level ``CMakeLists.txt`` file even before calling the
  90. :command:`project()` command. It is important to establish version and
  91. policy settings before invoking other commands whose behavior they
  92. may affect. See also policy :policy:`CMP0000`.