include.rst 1.0 KB

12345678910111213141516171819202122232425
  1. include
  2. -------
  3. Load and run CMake code from a file or module.
  4. ::
  5. include(<file|module> [OPTIONAL] [RESULT_VARIABLE <VAR>]
  6. [NO_POLICY_SCOPE])
  7. Load and run CMake code from the file given. Variable reads and
  8. writes access the scope of the caller (dynamic scoping). If ``OPTIONAL``
  9. is present, then no error is raised if the file does not exist. If
  10. ``RESULT_VARIABLE`` is given the variable will be set to the full filename
  11. which has been included or NOTFOUND if it failed.
  12. If a module is specified instead of a file, the file with name
  13. ``<modulename>.cmake`` is searched first in :variable:`CMAKE_MODULE_PATH`,
  14. then in the CMake module directory. There is one exception to this: if
  15. the file which calls ``include()`` is located itself in the CMake builtin
  16. module directory, then first the CMake builtin module directory is searched and
  17. :variable:`CMAKE_MODULE_PATH` afterwards. See also policy :policy:`CMP0017`.
  18. See the :command:`cmake_policy` command documentation for discussion of the
  19. ``NO_POLICY_SCOPE`` option.