project.rst 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. project
  2. -------
  3. Set a name, version, and enable languages for the entire project.
  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. [LANGUAGES <language-name>...])
  10. Sets the name of the project and stores the name in the
  11. :variable:`PROJECT_NAME` variable. Additionally this sets variables
  12. * :variable:`PROJECT_SOURCE_DIR`,
  13. :variable:`<PROJECT-NAME>_SOURCE_DIR`
  14. * :variable:`PROJECT_BINARY_DIR`,
  15. :variable:`<PROJECT-NAME>_BINARY_DIR`
  16. If ``VERSION`` is specified, given components must be non-negative integers.
  17. If ``VERSION`` is not specified, the default version is the empty string.
  18. The ``VERSION`` option may not be used unless policy :policy:`CMP0048` is
  19. set to ``NEW``.
  20. The :command:`project()` command stores the version number and its components
  21. in variables
  22. * :variable:`PROJECT_VERSION`,
  23. :variable:`<PROJECT-NAME>_VERSION`
  24. * :variable:`PROJECT_VERSION_MAJOR`,
  25. :variable:`<PROJECT-NAME>_VERSION_MAJOR`
  26. * :variable:`PROJECT_VERSION_MINOR`,
  27. :variable:`<PROJECT-NAME>_VERSION_MINOR`
  28. * :variable:`PROJECT_VERSION_PATCH`,
  29. :variable:`<PROJECT-NAME>_VERSION_PATCH`
  30. * :variable:`PROJECT_VERSION_TWEAK`,
  31. :variable:`<PROJECT-NAME>_VERSION_TWEAK`
  32. Variables corresponding to unspecified versions are set to the empty string
  33. (if policy :policy:`CMP0048` is set to ``NEW``).
  34. If optional ``DESCRIPTION`` is given, then additional :variable:`PROJECT_DESCRIPTION`
  35. variable will be set to its argument. The argument must be a string with short
  36. description of the project (only a few words).
  37. Optionally you can specify which languages your project supports.
  38. Example languages include ``C``, ``CXX`` (i.e. C++), ``CUDA``,
  39. ``Fortran``, and ``ASM``.
  40. By default ``C`` and ``CXX`` are enabled if no language options are
  41. given. Specify language ``NONE``, or use the ``LANGUAGES`` keyword
  42. and list no languages, to skip enabling any languages.
  43. If enabling ``ASM``, list it last so that CMake can check whether
  44. compilers for other languages like ``C`` work for assembly too.
  45. If a variable exists called :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
  46. the file pointed to by that variable will be included as the last step of the
  47. project command.
  48. The top-level ``CMakeLists.txt`` file for a project must contain a
  49. literal, direct call to the :command:`project` command; loading one
  50. through the :command:`include` command is not sufficient. If no such
  51. call exists CMake will implicitly add one to the top that enables the
  52. default languages (``C`` and ``CXX``).
  53. .. note::
  54. Call the :command:`cmake_minimum_required` command at the beginning
  55. of the top-level ``CMakeLists.txt`` file even before calling the
  56. ``project()`` command. It is important to establish version and
  57. policy settings before invoking other commands whose behavior they
  58. may affect. See also policy :policy:`CMP0000`.