project.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. [LANGUAGES <language-name>...])
  9. Sets the name of the project and stores the name in the
  10. :variable:`PROJECT_NAME` variable. Additionally this sets variables
  11. * :variable:`PROJECT_SOURCE_DIR`,
  12. :variable:`<PROJECT-NAME>_SOURCE_DIR`
  13. * :variable:`PROJECT_BINARY_DIR`,
  14. :variable:`<PROJECT-NAME>_BINARY_DIR`
  15. If ``VERSION`` is specified, given components must be non-negative integers.
  16. If ``VERSION`` is not specified, the default version is the empty string.
  17. The ``VERSION`` option may not be used unless policy :policy:`CMP0048` is
  18. set to ``NEW``.
  19. The :command:`project()` command stores the version number and its components
  20. in variables
  21. * :variable:`PROJECT_VERSION`,
  22. :variable:`<PROJECT-NAME>_VERSION`
  23. * :variable:`PROJECT_VERSION_MAJOR`,
  24. :variable:`<PROJECT-NAME>_VERSION_MAJOR`
  25. * :variable:`PROJECT_VERSION_MINOR`,
  26. :variable:`<PROJECT-NAME>_VERSION_MINOR`
  27. * :variable:`PROJECT_VERSION_PATCH`,
  28. :variable:`<PROJECT-NAME>_VERSION_PATCH`
  29. * :variable:`PROJECT_VERSION_TWEAK`,
  30. :variable:`<PROJECT-NAME>_VERSION_TWEAK`
  31. Variables corresponding to unspecified versions are set to the empty string
  32. (if policy :policy:`CMP0048` is set to ``NEW``).
  33. Optionally you can specify which languages your project supports.
  34. Example languages are ``C``, ``CXX`` (i.e. C++), ``Fortran``, etc.
  35. By default ``C`` and ``CXX`` are enabled if no language options are
  36. given. Specify language ``NONE``, or use the ``LANGUAGES`` keyword
  37. and list no languages, to skip enabling any languages.
  38. If a variable exists called :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE`,
  39. the file pointed to by that variable will be included as the last step of the
  40. project command.
  41. The top-level ``CMakeLists.txt`` file for a project must contain a
  42. literal, direct call to the :command:`project` command; loading one
  43. through the :command:`include` command is not sufficient. If no such
  44. call exists CMake will implicitly add one to the top that enables the
  45. default languages (``C`` and ``CXX``).