project.rst 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. project
  2. -------
  3. Sets project details such as name, version, etc. and enables languages.
  4. .. code-block:: cmake
  5. project(<PROJECT-NAME> [LANGUAGES] [<language-name>...])
  6. project(<PROJECT-NAME>
  7. [VERSION <major>[.<minor>[.<patch>[.<tweak>]]]]
  8. [DESCRIPTION <project-description-string>]
  9. [HOMEPAGE_URL <url-string>]
  10. [LANGUAGES <language-name>...])
  11. Sets the name of the project and stores the name in the
  12. :variable:`PROJECT_NAME` variable. Additionally this sets variables
  13. * :variable:`PROJECT_SOURCE_DIR`,
  14. :variable:`<PROJECT-NAME>_SOURCE_DIR`
  15. * :variable:`PROJECT_BINARY_DIR`,
  16. :variable:`<PROJECT-NAME>_BINARY_DIR`
  17. If ``VERSION`` is specified, given components must be non-negative integers.
  18. If ``VERSION`` is not specified, the default version is the empty string.
  19. The ``VERSION`` option may not be used unless policy :policy:`CMP0048` is
  20. set to ``NEW``.
  21. The :command:`project()` command stores the version number and its components
  22. in variables
  23. * :variable:`PROJECT_VERSION`,
  24. :variable:`<PROJECT-NAME>_VERSION`
  25. * :variable:`PROJECT_VERSION_MAJOR`,
  26. :variable:`<PROJECT-NAME>_VERSION_MAJOR`
  27. * :variable:`PROJECT_VERSION_MINOR`,
  28. :variable:`<PROJECT-NAME>_VERSION_MINOR`
  29. * :variable:`PROJECT_VERSION_PATCH`,
  30. :variable:`<PROJECT-NAME>_VERSION_PATCH`
  31. * :variable:`PROJECT_VERSION_TWEAK`,
  32. :variable:`<PROJECT-NAME>_VERSION_TWEAK`
  33. Variables corresponding to unspecified versions are set to the empty string
  34. (if policy :policy:`CMP0048` is set to ``NEW``).
  35. If the optional ``DESCRIPTION`` is given, then :variable:`PROJECT_DESCRIPTION`
  36. and :variable:`<PROJECT-NAME>_DESCRIPTION` will be set to its argument.
  37. These variables will be cleared if ``DESCRIPTION`` is not given.
  38. The description is expected to be a relatively short string, usually no more
  39. than a few words.
  40. The optional ``HOMEPAGE_URL`` sets the analogous variables
  41. :variable:`PROJECT_HOMEPAGE_URL` and :variable:`<PROJECT-NAME>_HOMEPAGE_URL`.
  42. When this option is given, the URL provided should be the canonical home for
  43. the project.
  44. These variables will be cleared if ``HOMEPAGE_URL`` is not given.
  45. Note that the description and homepage URL may be used as defaults for
  46. things like packaging meta-data, documentation, etc.
  47. Optionally you can specify which languages your project supports.
  48. Example languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``,
  49. ``Fortran``, and ``ASM``.
  50. By default ``C`` and ``CXX`` are enabled if no language options are
  51. given. Specify language ``NONE``, or use the ``LANGUAGES`` keyword
  52. and list no languages, to skip enabling any languages.
  53. If enabling ``ASM``, list it last so that CMake can check whether
  54. compilers for other languages like ``C`` work for assembly too.
  55. If a variable exists called :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
  56. the file pointed to by that variable will be included as the last step of the
  57. project command.
  58. The top-level ``CMakeLists.txt`` file for a project must contain a
  59. literal, direct call to the :command:`project` command; loading one
  60. through the :command:`include` command is not sufficient. If no such
  61. call exists CMake will implicitly add one to the top that enables the
  62. default languages (``C`` and ``CXX``). The name of the project set in
  63. the top level ``CMakeLists.txt`` file is available from the
  64. :variable:`CMAKE_PROJECT_NAME` variable, its description from
  65. :variable:`CMAKE_PROJECT_DESCRIPTION`, its homepage URL from
  66. :variable:`CMAKE_PROJECT_HOMEPAGE_URL` and its version from
  67. :variable:`CMAKE_PROJECT_VERSION`.
  68. .. note::
  69. Call the :command:`cmake_minimum_required` command at the beginning
  70. of the top-level ``CMakeLists.txt`` file even before calling the
  71. ``project()`` command. It is important to establish version and
  72. policy settings before invoking other commands whose behavior they
  73. may affect. See also policy :policy:`CMP0000`.