project.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_<PROJECT-NAME>_INCLUDE` exists,
  26. the file pointed to by that variable will be included as the last step of the
  27. project command.
  28. Options
  29. ^^^^^^^
  30. The options are:
  31. ``VERSION <version>``
  32. Optional; may not be used unless policy :policy:`CMP0048` is
  33. set to ``NEW``.
  34. Takes a ``<version>`` argument composed of non-negative integer components,
  35. i.e. ``<major>[.<minor>[.<patch>[.<tweak>]]]``,
  36. and sets the variables
  37. * :variable:`PROJECT_VERSION`,
  38. :variable:`<PROJECT-NAME>_VERSION`
  39. * :variable:`PROJECT_VERSION_MAJOR`,
  40. :variable:`<PROJECT-NAME>_VERSION_MAJOR`
  41. * :variable:`PROJECT_VERSION_MINOR`,
  42. :variable:`<PROJECT-NAME>_VERSION_MINOR`
  43. * :variable:`PROJECT_VERSION_PATCH`,
  44. :variable:`<PROJECT-NAME>_VERSION_PATCH`
  45. * :variable:`PROJECT_VERSION_TWEAK`,
  46. :variable:`<PROJECT-NAME>_VERSION_TWEAK`.
  47. When the :command:`project()` command is called from the top-level ``CMakeLists.txt``,
  48. then the version is also stored in the variable :variable:`CMAKE_PROJECT_VERSION`.
  49. ``DESCRIPTION <project-description-string>``
  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 :command:`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. ``HOMEPAGE_URL <url-string>``
  59. Optional.
  60. Sets the variables
  61. * :variable:`PROJECT_HOMEPAGE_URL`, :variable:`<PROJECT-NAME>_HOMEPAGE_URL`
  62. to ``<url-string>``, which should be the canonical home URL for the project.
  63. When the :command:`project()` command is called from the top-level ``CMakeLists.txt``,
  64. then the URL also is stored in the variable :variable:`CMAKE_PROJECT_HOMEPAGE_URL`.
  65. ``LANGUAGES <language-name>...``
  66. Optional.
  67. Can also be specified without ``LANGUAGES`` keyword per the first, short signature.
  68. Selects which programming languages are needed to build the project.
  69. Supported languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``, ``Fortran``, and ``ASM``.
  70. By default ``C`` and ``CXX`` are enabled if no language options are given.
  71. Specify language ``NONE``, or use the ``LANGUAGES`` keyword and list no languages,
  72. to skip enabling any languages.
  73. If enabling ``ASM``, list it last so that CMake can check whether
  74. compilers for other languages like ``C`` work for assembly too.
  75. The variables set through the ``VERSION``, ``DESCRIPTION`` and ``HOMEPAGE_URL``
  76. options are intended for use as default values in package metadata and documentation.
  77. Usage
  78. ^^^^^
  79. The top-level ``CMakeLists.txt`` file for a project must contain a
  80. literal, direct call to the :command:`project` command; loading one
  81. through the :command:`include` command is not sufficient. If no such
  82. call exists CMake will implicitly add one to the top that enables the
  83. default languages (``C`` and ``CXX``).
  84. .. note::
  85. Call the :command:`cmake_minimum_required` command at the beginning
  86. of the top-level ``CMakeLists.txt`` file even before calling the
  87. :command:`project()` command. It is important to establish version and
  88. policy settings before invoking other commands whose behavior they
  89. may affect. See also policy :policy:`CMP0000`.