project.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. The description is expected to be a relatively short string, usually no more
  38. than a few words.
  39. The optional ``HOMEPAGE_URL`` sets the analogous variables
  40. :variable:`PROJECT_HOMEPAGE_URL` and :variable:`<PROJECT-NAME>_HOMEPAGE_URL`.
  41. When this option is given, the URL provided should be the canonical home for
  42. the project.
  43. Note that the description and homepage URL may be used as defaults for
  44. things like packaging meta-data, documentation, etc.
  45. Optionally you can specify which languages your project supports.
  46. Example languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``,
  47. ``Fortran``, and ``ASM``.
  48. By default ``C`` and ``CXX`` are enabled if no language options are
  49. given. Specify language ``NONE``, or use the ``LANGUAGES`` keyword
  50. and list no languages, to skip enabling any languages.
  51. If enabling ``ASM``, list it last so that CMake can check whether
  52. compilers for other languages like ``C`` work for assembly too.
  53. If a variable exists called :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
  54. the file pointed to by that variable will be included as the last step of the
  55. project command.
  56. The top-level ``CMakeLists.txt`` file for a project must contain a
  57. literal, direct call to the :command:`project` command; loading one
  58. through the :command:`include` command is not sufficient. If no such
  59. call exists CMake will implicitly add one to the top that enables the
  60. default languages (``C`` and ``CXX``). The name of the project set in
  61. the top level ``CMakeLists.txt`` file is available from the
  62. :variable:`CMAKE_PROJECT_NAME` variable, its description from
  63. :variable:`CMAKE_PROJECT_DESCRIPTION` and its homepage URL from
  64. :variable:`CMAKE_PROJECT_HOMEPAGE_URL`.
  65. .. note::
  66. Call the :command:`cmake_minimum_required` command at the beginning
  67. of the top-level ``CMakeLists.txt`` file even before calling the
  68. ``project()`` command. It is important to establish version and
  69. policy settings before invoking other commands whose behavior they
  70. may affect. See also policy :policy:`CMP0000`.