file.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. file
  2. ----
  3. File manipulation command.
  4. This command is dedicated to file and path manipulation requiring access to the
  5. filesystem.
  6. For other path manipulation, handling only syntactic aspects, have a look at
  7. :command:`cmake_path` command.
  8. .. note::
  9. The sub-commands `RELATIVE_PATH`_, `TO_CMAKE_PATH`_ and `TO_NATIVE_PATH`_ has
  10. been superseded, respectively, by sub-commands
  11. :ref:`RELATIVE_PATH <cmake_path-RELATIVE_PATH>`,
  12. :ref:`CONVERT ... TO_CMAKE_PATH_LIST <cmake_path-TO_CMAKE_PATH_LIST>` and
  13. :ref:`CONVERT ... TO_NATIVE_PATH_LIST <cmake_path-TO_NATIVE_PATH_LIST>` of
  14. :command:`cmake_path` command.
  15. Synopsis
  16. ^^^^^^^^
  17. .. parsed-literal::
  18. `Reading`_
  19. file(`READ`_ <filename> <out-var> [...])
  20. file(`STRINGS`_ <filename> <out-var> [...])
  21. file(`\<HASH\> <HASH_>`_ <filename> <out-var>)
  22. file(`TIMESTAMP`_ <filename> <out-var> [...])
  23. file(`GET_RUNTIME_DEPENDENCIES`_ [...])
  24. `Writing`_
  25. file({`WRITE`_ | `APPEND`_} <filename> <content>...)
  26. file({`TOUCH`_ | `TOUCH_NOCREATE`_} [<file>...])
  27. file(`GENERATE`_ OUTPUT <output-file> [...])
  28. file(`CONFIGURE`_ OUTPUT <output-file> CONTENT <content> [...])
  29. `Filesystem`_
  30. file({`GLOB`_ | `GLOB_RECURSE`_} <out-var> [...] [<globbing-expr>...])
  31. file(`RENAME`_ <oldname> <newname> [...])
  32. file({`REMOVE`_ | `REMOVE_RECURSE`_ } [<files>...])
  33. file(`MAKE_DIRECTORY`_ [<dir>...])
  34. file({`COPY`_ | `INSTALL`_} <file>... DESTINATION <dir> [...])
  35. file(`SIZE`_ <filename> <out-var>)
  36. file(`READ_SYMLINK`_ <linkname> <out-var>)
  37. file(`CREATE_LINK`_ <original> <linkname> [...])
  38. file(`CHMOD`_ <files>... <directories>... PERMISSIONS <permissions>... [...])
  39. file(`CHMOD_RECURSE`_ <files>... <directories>... PERMISSIONS <permissions>... [...])
  40. `Path Conversion`_
  41. file(`REAL_PATH`_ <path> <out-var> [BASE_DIRECTORY <dir>])
  42. file(`RELATIVE_PATH`_ <out-var> <directory> <file>)
  43. file({`TO_CMAKE_PATH`_ | `TO_NATIVE_PATH`_} <path> <out-var>)
  44. `Transfer`_
  45. file(`DOWNLOAD`_ <url> [<file>] [...])
  46. file(`UPLOAD`_ <file> <url> [...])
  47. `Locking`_
  48. file(`LOCK`_ <path> [...])
  49. `Archiving`_
  50. file(`ARCHIVE_CREATE`_ OUTPUT <archive> PATHS <paths>... [...])
  51. file(`ARCHIVE_EXTRACT`_ INPUT <archive> [...])
  52. Reading
  53. ^^^^^^^
  54. .. _READ:
  55. .. code-block:: cmake
  56. file(READ <filename> <variable>
  57. [OFFSET <offset>] [LIMIT <max-in>] [HEX])
  58. Read content from a file called ``<filename>`` and store it in a
  59. ``<variable>``. Optionally start from the given ``<offset>`` and
  60. read at most ``<max-in>`` bytes. The ``HEX`` option causes data to
  61. be converted to a hexadecimal representation (useful for binary data). If the
  62. ``HEX`` option is specified, letters in the output (``a`` through ``f``) are in
  63. lowercase.
  64. .. _STRINGS:
  65. .. code-block:: cmake
  66. file(STRINGS <filename> <variable> [<options>...])
  67. Parse a list of ASCII strings from ``<filename>`` and store it in
  68. ``<variable>``. Binary data in the file are ignored. Carriage return
  69. (``\r``, CR) characters are ignored. The options are:
  70. ``LENGTH_MAXIMUM <max-len>``
  71. Consider only strings of at most a given length.
  72. ``LENGTH_MINIMUM <min-len>``
  73. Consider only strings of at least a given length.
  74. ``LIMIT_COUNT <max-num>``
  75. Limit the number of distinct strings to be extracted.
  76. ``LIMIT_INPUT <max-in>``
  77. Limit the number of input bytes to read from the file.
  78. ``LIMIT_OUTPUT <max-out>``
  79. Limit the number of total bytes to store in the ``<variable>``.
  80. ``NEWLINE_CONSUME``
  81. Treat newline characters (``\n``, LF) as part of string content
  82. instead of terminating at them.
  83. ``NO_HEX_CONVERSION``
  84. Intel Hex and Motorola S-record files are automatically converted to
  85. binary while reading unless this option is given.
  86. ``REGEX <regex>``
  87. Consider only strings that match the given regular expression.
  88. ``ENCODING <encoding-type>``
  89. .. versionadded:: 3.1
  90. Consider strings of a given encoding. Currently supported encodings are:
  91. ``UTF-8``, ``UTF-16LE``, ``UTF-16BE``, ``UTF-32LE``, ``UTF-32BE``.
  92. If the ``ENCODING`` option is not provided and the file has a Byte Order Mark,
  93. the ``ENCODING`` option will be defaulted to respect the Byte Order Mark.
  94. .. versionadded:: 3.2
  95. Added the ``UTF-16LE``, ``UTF-16BE``, ``UTF-32LE``, ``UTF-32BE`` encodings.
  96. For example, the code
  97. .. code-block:: cmake
  98. file(STRINGS myfile.txt myfile)
  99. stores a list in the variable ``myfile`` in which each item is a line
  100. from the input file.
  101. .. _HASH:
  102. .. code-block:: cmake
  103. file(<HASH> <filename> <variable>)
  104. Compute a cryptographic hash of the content of ``<filename>`` and
  105. store it in a ``<variable>``. The supported ``<HASH>`` algorithm names
  106. are those listed by the :ref:`string(\<HASH\>) <Supported Hash Algorithms>`
  107. command.
  108. .. _TIMESTAMP:
  109. .. code-block:: cmake
  110. file(TIMESTAMP <filename> <variable> [<format>] [UTC])
  111. Compute a string representation of the modification time of ``<filename>``
  112. and store it in ``<variable>``. Should the command be unable to obtain a
  113. timestamp variable will be set to the empty string ("").
  114. See the :command:`string(TIMESTAMP)` command for documentation of
  115. the ``<format>`` and ``UTC`` options.
  116. .. _GET_RUNTIME_DEPENDENCIES:
  117. .. code-block:: cmake
  118. file(GET_RUNTIME_DEPENDENCIES
  119. [RESOLVED_DEPENDENCIES_VAR <deps_var>]
  120. [UNRESOLVED_DEPENDENCIES_VAR <unresolved_deps_var>]
  121. [CONFLICTING_DEPENDENCIES_PREFIX <conflicting_deps_prefix>]
  122. [EXECUTABLES [<executable_files>...]]
  123. [LIBRARIES [<library_files>...]]
  124. [MODULES [<module_files>...]]
  125. [DIRECTORIES [<directories>...]]
  126. [BUNDLE_EXECUTABLE <bundle_executable_file>]
  127. [PRE_INCLUDE_REGEXES [<regexes>...]]
  128. [PRE_EXCLUDE_REGEXES [<regexes>...]]
  129. [POST_INCLUDE_REGEXES [<regexes>...]]
  130. [POST_EXCLUDE_REGEXES [<regexes>...]]
  131. )
  132. .. versionadded:: 3.16
  133. Recursively get the list of libraries depended on by the given files.
  134. Please note that this sub-command is not intended to be used in project mode.
  135. Instead, use it in an :command:`install(CODE)` or :command:`install(SCRIPT)`
  136. block. For example:
  137. .. code-block:: cmake
  138. install(CODE [[
  139. file(GET_RUNTIME_DEPENDENCIES
  140. # ...
  141. )
  142. ]])
  143. The arguments are as follows:
  144. ``RESOLVED_DEPENDENCIES_VAR <deps_var>``
  145. Name of the variable in which to store the list of resolved dependencies.
  146. ``UNRESOLVED_DEPENDENCIES_VAR <unresolved_deps_var>``
  147. Name of the variable in which to store the list of unresolved dependencies.
  148. If this variable is not specified, and there are any unresolved dependencies,
  149. an error is issued.
  150. ``CONFLICTING_DEPENDENCIES_PREFIX <conflicting_deps_prefix>``
  151. Variable prefix in which to store conflicting dependency information.
  152. Dependencies are conflicting if two files with the same name are found in
  153. two different directories. The list of filenames that conflict are stored in
  154. ``<conflicting_deps_prefix>_FILENAMES``. For each filename, the list of paths
  155. that were found for that filename are stored in
  156. ``<conflicting_deps_prefix>_<filename>``.
  157. ``EXECUTABLES <executable_files>``
  158. List of executable files to read for dependencies. These are executables that
  159. are typically created with :command:`add_executable`, but they do not have to
  160. be created by CMake. On Apple platforms, the paths to these files determine
  161. the value of ``@executable_path`` when recursively resolving the libraries.
  162. Specifying any kind of library (``STATIC``, ``MODULE``, or ``SHARED``) here
  163. will result in undefined behavior.
  164. ``LIBRARIES <library_files>``
  165. List of library files to read for dependencies. These are libraries that are
  166. typically created with :command:`add_library(SHARED)`, but they do not have
  167. to be created by CMake. Specifying ``STATIC`` libraries, ``MODULE``
  168. libraries, or executables here will result in undefined behavior.
  169. ``MODULES <module_files>``
  170. List of loadable module files to read for dependencies. These are modules
  171. that are typically created with :command:`add_library(MODULE)`, but they do
  172. not have to be created by CMake. They are typically used by calling
  173. ``dlopen()`` at runtime rather than linked at link time with ``ld -l``.
  174. Specifying ``STATIC`` libraries, ``SHARED`` libraries, or executables here
  175. will result in undefined behavior.
  176. ``DIRECTORIES <directories>``
  177. List of additional directories to search for dependencies. On Linux
  178. platforms, these directories are searched if the dependency is not found in
  179. any of the other usual paths. If it is found in such a directory, a warning
  180. is issued, because it means that the file is incomplete (it does not list all
  181. of the directories that contain its dependencies). On Windows platforms,
  182. these directories are searched if the dependency is not found in any of the
  183. other search paths, but no warning is issued, because searching other paths
  184. is a normal part of Windows dependency resolution. On Apple platforms, this
  185. argument has no effect.
  186. ``BUNDLE_EXECUTABLE <bundle_executable_file>``
  187. Executable to treat as the "bundle executable" when resolving libraries. On
  188. Apple platforms, this argument determines the value of ``@executable_path``
  189. when recursively resolving libraries for ``LIBRARIES`` and ``MODULES`` files.
  190. It has no effect on ``EXECUTABLES`` files. On other platforms, it has no
  191. effect. This is typically (but not always) one of the executables in the
  192. ``EXECUTABLES`` argument which designates the "main" executable of the
  193. package.
  194. The following arguments specify filters for including or excluding libraries to
  195. be resolved. See below for a full description of how they work.
  196. ``PRE_INCLUDE_REGEXES <regexes>``
  197. List of pre-include regexes through which to filter the names of
  198. not-yet-resolved dependencies.
  199. ``PRE_EXCLUDE_REGEXES <regexes>``
  200. List of pre-exclude regexes through which to filter the names of
  201. not-yet-resolved dependencies.
  202. ``POST_INCLUDE_REGEXES <regexes>``
  203. List of post-include regexes through which to filter the names of resolved
  204. dependencies.
  205. ``POST_EXCLUDE_REGEXES <regexes>``
  206. List of post-exclude regexes through which to filter the names of resolved
  207. dependencies.
  208. These arguments can be used to exclude unwanted system libraries when
  209. resolving the dependencies, or to include libraries from a specific
  210. directory. The filtering works as follows:
  211. 1. If the not-yet-resolved dependency matches any of the
  212. ``PRE_INCLUDE_REGEXES``, steps 2 and 3 are skipped, and the dependency
  213. resolution proceeds to step 4.
  214. 2. If the not-yet-resolved dependency matches any of the
  215. ``PRE_EXCLUDE_REGEXES``, dependency resolution stops for that dependency.
  216. 3. Otherwise, dependency resolution proceeds.
  217. 4. ``file(GET_RUNTIME_DEPENDENCIES)`` searches for the dependency according to
  218. the linking rules of the platform (see below).
  219. 5. If the dependency is found, and its full path matches one of the
  220. ``POST_INCLUDE_REGEXES``, the full path is added to the resolved
  221. dependencies, and ``file(GET_RUNTIME_DEPENDENCIES)`` recursively resolves
  222. that library's own dependencies. Otherwise, resolution proceeds to step 6.
  223. 6. If the dependency is found, but its full path matches one of the
  224. ``POST_EXCLUDE_REGEXES``, it is not added to the resolved dependencies, and
  225. dependency resolution stops for that dependency.
  226. 7. If the dependency is found, and its full path does not match either
  227. ``POST_INCLUDE_REGEXES`` or ``POST_EXCLUDE_REGEXES``, the full path is added
  228. to the resolved dependencies, and ``file(GET_RUNTIME_DEPENDENCIES)``
  229. recursively resolves that library's own dependencies.
  230. Different platforms have different rules for how dependencies are resolved.
  231. These specifics are described here.
  232. On Linux platforms, library resolution works as follows:
  233. 1. If the depending file does not have any ``RUNPATH`` entries, and the library
  234. exists in one of the depending file's ``RPATH`` entries, or its parents', in
  235. that order, the dependency is resolved to that file.
  236. 2. Otherwise, if the depending file has any ``RUNPATH`` entries, and the
  237. library exists in one of those entries, the dependency is resolved to that
  238. file.
  239. 3. Otherwise, if the library exists in one of the directories listed by
  240. ``ldconfig``, the dependency is resolved to that file.
  241. 4. Otherwise, if the library exists in one of the ``DIRECTORIES`` entries, the
  242. dependency is resolved to that file. In this case, a warning is issued,
  243. because finding a file in one of the ``DIRECTORIES`` means that the
  244. depending file is not complete (it does not list all the directories from
  245. which it pulls dependencies).
  246. 5. Otherwise, the dependency is unresolved.
  247. On Windows platforms, library resolution works as follows:
  248. 1. The dependent DLL name is converted to lowercase. Windows DLL names are
  249. case-insensitive, and some linkers mangle the case of the DLL dependency
  250. names. However, this makes it more difficult for ``PRE_INCLUDE_REGEXES``,
  251. ``PRE_EXCLUDE_REGEXES``, ``POST_INCLUDE_REGEXES``, and
  252. ``POST_EXCLUDE_REGEXES`` to properly filter DLL names - every regex would
  253. have to check for both uppercase and lowercase letters. For example:
  254. .. code-block:: cmake
  255. file(GET_RUNTIME_DEPENDENCIES
  256. # ...
  257. PRE_INCLUDE_REGEXES "^[Mm][Yy][Ll][Ii][Bb][Rr][Aa][Rr][Yy]\\.[Dd][Ll][Ll]$"
  258. )
  259. Converting the DLL name to lowercase allows the regexes to only match
  260. lowercase names, thus simplifying the regex. For example:
  261. .. code-block:: cmake
  262. file(GET_RUNTIME_DEPENDENCIES
  263. # ...
  264. PRE_INCLUDE_REGEXES "^mylibrary\\.dll$"
  265. )
  266. This regex will match ``mylibrary.dll`` regardless of how it is cased,
  267. either on disk or in the depending file. (For example, it will match
  268. ``mylibrary.dll``, ``MyLibrary.dll``, and ``MYLIBRARY.DLL``.)
  269. Please note that the directory portion of any resolved DLLs retains its
  270. casing and is not converted to lowercase. Only the filename portion is
  271. converted.
  272. 2. (**Not yet implemented**) If the depending file is a Windows Store app, and
  273. the dependency is listed as a dependency in the application's package
  274. manifest, the dependency is resolved to that file.
  275. 3. Otherwise, if the library exists in the same directory as the depending
  276. file, the dependency is resolved to that file.
  277. 4. Otherwise, if the library exists in either the operating system's
  278. ``system32`` directory or the ``Windows`` directory, in that order, the
  279. dependency is resolved to that file.
  280. 5. Otherwise, if the library exists in one of the directories specified by
  281. ``DIRECTORIES``, in the order they are listed, the dependency is resolved to
  282. that file. In this case, a warning is not issued, because searching other
  283. directories is a normal part of Windows library resolution.
  284. 6. Otherwise, the dependency is unresolved.
  285. On Apple platforms, library resolution works as follows:
  286. 1. If the dependency starts with ``@executable_path/``, and an ``EXECUTABLES``
  287. argument is in the process of being resolved, and replacing
  288. ``@executable_path/`` with the directory of the executable yields an
  289. existing file, the dependency is resolved to that file.
  290. 2. Otherwise, if the dependency starts with ``@executable_path/``, and there is
  291. a ``BUNDLE_EXECUTABLE`` argument, and replacing ``@executable_path/`` with
  292. the directory of the bundle executable yields an existing file, the
  293. dependency is resolved to that file.
  294. 3. Otherwise, if the dependency starts with ``@loader_path/``, and replacing
  295. ``@loader_path/`` with the directory of the depending file yields an
  296. existing file, the dependency is resolved to that file.
  297. 4. Otherwise, if the dependency starts with ``@rpath/``, and replacing
  298. ``@rpath/`` with one of the ``RPATH`` entries of the depending file yields
  299. an existing file, the dependency is resolved to that file. Note that
  300. ``RPATH`` entries that start with ``@executable_path/`` or ``@loader_path/``
  301. also have these items replaced with the appropriate path.
  302. 5. Otherwise, if the dependency is an absolute file that exists, the dependency
  303. is resolved to that file.
  304. 6. Otherwise, the dependency is unresolved.
  305. This function accepts several variables that determine which tool is used for
  306. dependency resolution:
  307. .. variable:: CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM
  308. Determines which operating system and executable format the files are built
  309. for. This could be one of several values:
  310. * ``linux+elf``
  311. * ``windows+pe``
  312. * ``macos+macho``
  313. If this variable is not specified, it is determined automatically by system
  314. introspection.
  315. .. variable:: CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL
  316. Determines the tool to use for dependency resolution. It could be one of
  317. several values, depending on the value of
  318. :variable:`CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM`:
  319. ================================================= =============================================
  320. ``CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM`` ``CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL``
  321. ================================================= =============================================
  322. ``linux+elf`` ``objdump``
  323. ``windows+pe`` ``dumpbin``
  324. ``windows+pe`` ``objdump``
  325. ``macos+macho`` ``otool``
  326. ================================================= =============================================
  327. If this variable is not specified, it is determined automatically by system
  328. introspection.
  329. .. variable:: CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND
  330. Determines the path to the tool to use for dependency resolution. This is the
  331. actual path to ``objdump``, ``dumpbin``, or ``otool``.
  332. If this variable is not specified, it is determined by the value of
  333. ``CMAKE_OBJDUMP`` if set, else by system introspection.
  334. .. versionadded:: 3.18
  335. Use ``CMAKE_OBJDUMP`` if set.
  336. Writing
  337. ^^^^^^^
  338. .. _WRITE:
  339. .. _APPEND:
  340. .. code-block:: cmake
  341. file(WRITE <filename> <content>...)
  342. file(APPEND <filename> <content>...)
  343. Write ``<content>`` into a file called ``<filename>``. If the file does
  344. not exist, it will be created. If the file already exists, ``WRITE``
  345. mode will overwrite it and ``APPEND`` mode will append to the end.
  346. Any directories in the path specified by ``<filename>`` that do not
  347. exist will be created.
  348. If the file is a build input, use the :command:`configure_file` command
  349. to update the file only when its content changes.
  350. .. _TOUCH:
  351. .. _TOUCH_NOCREATE:
  352. .. code-block:: cmake
  353. file(TOUCH [<files>...])
  354. file(TOUCH_NOCREATE [<files>...])
  355. .. versionadded:: 3.12
  356. Create a file with no content if it does not yet exist. If the file already
  357. exists, its access and/or modification will be updated to the time when the
  358. function call is executed.
  359. Use TOUCH_NOCREATE to touch a file if it exists but not create it. If a file
  360. does not exist it will be silently ignored.
  361. With TOUCH and TOUCH_NOCREATE the contents of an existing file will not be
  362. modified.
  363. .. _GENERATE:
  364. .. code-block:: cmake
  365. file(GENERATE OUTPUT output-file
  366. <INPUT input-file|CONTENT content>
  367. [CONDITION expression] [TARGET target]
  368. [FILE_PERMISSIONS <permissions>...]
  369. [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
  370. [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
  371. Generate an output file for each build configuration supported by the current
  372. :manual:`CMake Generator <cmake-generators(7)>`. Evaluate
  373. :manual:`generator expressions <cmake-generator-expressions(7)>`
  374. from the input content to produce the output content. The options are:
  375. ``CONDITION <condition>``
  376. Generate the output file for a particular configuration only if
  377. the condition is true. The condition must be either ``0`` or ``1``
  378. after evaluating generator expressions.
  379. ``CONTENT <content>``
  380. Use the content given explicitly as input.
  381. ``INPUT <input-file>``
  382. Use the content from a given file as input.
  383. .. versionchanged:: 3.10
  384. A relative path is treated with respect to the value of
  385. :variable:`CMAKE_CURRENT_SOURCE_DIR`. See policy :policy:`CMP0070`.
  386. ``OUTPUT <output-file>``
  387. Specify the output file name to generate. Use generator expressions
  388. such as ``$<CONFIG>`` to specify a configuration-specific output file
  389. name. Multiple configurations may generate the same output file only
  390. if the generated content is identical. Otherwise, the ``<output-file>``
  391. must evaluate to an unique name for each configuration.
  392. .. versionchanged:: 3.10
  393. A relative path (after evaluating generator expressions) is treated
  394. with respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`.
  395. See policy :policy:`CMP0070`.
  396. ``TARGET <target>``
  397. .. versionadded:: 3.19
  398. Specify which target to use when evaluating generator expressions that
  399. require a target for evaluation (e.g. ``$<COMPILE_FEATURES:...>``,
  400. ``$<TARGET_PROPERTY:prop>``).
  401. ``FILE_PERMISSIONS <permissions>...``
  402. Use user provided permissions for the generated file.
  403. ``NO_SOURCE_PERMISSIONS``
  404. The generated file permissions default to the standard 644 value
  405. (-rw-r--r--).
  406. ``USE_SOURCE_PERMISSIONS``
  407. Transfer the file permissions of the original file to the generated file.
  408. This option expects INPUT option.
  409. ``NEWLINE_STYLE <style>``
  410. .. versionadded:: 3.20
  411. Specify the newline style for the generated file. Specify
  412. ``UNIX`` or ``LF`` for ``\n`` newlines, or specify
  413. ``DOS``, ``WIN32``, or ``CRLF`` for ``\r\n`` newlines.
  414. Exactly one ``CONTENT`` or ``INPUT`` option must be given. A specific
  415. ``OUTPUT`` file may be named by at most one invocation of ``file(GENERATE)``.
  416. Generated files are modified and their timestamp updated on subsequent cmake
  417. runs only if their content is changed.
  418. Note also that ``file(GENERATE)`` does not create the output file until the
  419. generation phase. The output file will not yet have been written when the
  420. ``file(GENERATE)`` command returns, it is written only after processing all
  421. of a project's ``CMakeLists.txt`` files.
  422. .. _CONFIGURE:
  423. .. code-block:: cmake
  424. file(CONFIGURE OUTPUT output-file
  425. CONTENT content
  426. [ESCAPE_QUOTES] [@ONLY]
  427. [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ])
  428. .. versionadded:: 3.18
  429. Generate an output file using the input given by ``CONTENT`` and substitute
  430. variable values referenced as ``@VAR@`` or ``${VAR}`` contained therein. The
  431. substitution rules behave the same as the :command:`configure_file` command.
  432. In order to match :command:`configure_file`'s behavior, generator expressions
  433. are not supported for both ``OUTPUT`` and ``CONTENT``.
  434. The arguments are:
  435. ``OUTPUT <output-file>``
  436. Specify the output file name to generate. A relative path is treated with
  437. respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`.
  438. ``<output-file>`` does not support generator expressions.
  439. ``CONTENT <content>``
  440. Use the content given explicitly as input.
  441. ``<content>`` does not support generator expressions.
  442. ``ESCAPE_QUOTES``
  443. Escape any substituted quotes with backslashes (C-style).
  444. ``@ONLY``
  445. Restrict variable replacement to references of the form ``@VAR@``.
  446. This is useful for configuring scripts that use ``${VAR}`` syntax.
  447. ``NEWLINE_STYLE <style>``
  448. Specify the newline style for the output file. Specify
  449. ``UNIX`` or ``LF`` for ``\n`` newlines, or specify
  450. ``DOS``, ``WIN32``, or ``CRLF`` for ``\r\n`` newlines.
  451. Filesystem
  452. ^^^^^^^^^^
  453. .. _GLOB:
  454. .. _GLOB_RECURSE:
  455. .. code-block:: cmake
  456. file(GLOB <variable>
  457. [LIST_DIRECTORIES true|false] [RELATIVE <path>] [CONFIGURE_DEPENDS]
  458. [<globbing-expressions>...])
  459. file(GLOB_RECURSE <variable> [FOLLOW_SYMLINKS]
  460. [LIST_DIRECTORIES true|false] [RELATIVE <path>] [CONFIGURE_DEPENDS]
  461. [<globbing-expressions>...])
  462. Generate a list of files that match the ``<globbing-expressions>`` and
  463. store it into the ``<variable>``. Globbing expressions are similar to
  464. regular expressions, but much simpler. If ``RELATIVE`` flag is
  465. specified, the results will be returned as relative paths to the given
  466. path.
  467. .. versionchanged:: 3.6
  468. The results will be ordered lexicographically.
  469. On Windows and macOS, globbing is case-insensitive even if the underlying
  470. filesystem is case-sensitive (both filenames and globbing expressions are
  471. converted to lowercase before matching). On other platforms, globbing is
  472. case-sensitive.
  473. .. versionadded:: 3.3
  474. By default ``GLOB`` lists directories - directories are omitted in result if
  475. ``LIST_DIRECTORIES`` is set to false.
  476. .. versionadded:: 3.12
  477. If the ``CONFIGURE_DEPENDS`` flag is specified, CMake will add logic
  478. to the main build system check target to rerun the flagged ``GLOB`` commands
  479. at build time. If any of the outputs change, CMake will regenerate the build
  480. system.
  481. .. note::
  482. We do not recommend using GLOB to collect a list of source files from
  483. your source tree. If no CMakeLists.txt file changes when a source is
  484. added or removed then the generated build system cannot know when to
  485. ask CMake to regenerate.
  486. The ``CONFIGURE_DEPENDS`` flag may not work reliably on all generators, or if
  487. a new generator is added in the future that cannot support it, projects using
  488. it will be stuck. Even if ``CONFIGURE_DEPENDS`` works reliably, there is
  489. still a cost to perform the check on every rebuild.
  490. Examples of globbing expressions include::
  491. *.cxx - match all files with extension cxx
  492. *.vt? - match all files with extension vta,...,vtz
  493. f[3-5].txt - match files f3.txt, f4.txt, f5.txt
  494. The ``GLOB_RECURSE`` mode will traverse all the subdirectories of the
  495. matched directory and match the files. Subdirectories that are symlinks
  496. are only traversed if ``FOLLOW_SYMLINKS`` is given or policy
  497. :policy:`CMP0009` is not set to ``NEW``.
  498. .. versionadded:: 3.3
  499. By default ``GLOB_RECURSE`` omits directories from result list - setting
  500. ``LIST_DIRECTORIES`` to true adds directories to result list.
  501. If ``FOLLOW_SYMLINKS`` is given or policy :policy:`CMP0009` is not set to
  502. ``NEW`` then ``LIST_DIRECTORIES`` treats symlinks as directories.
  503. Examples of recursive globbing include::
  504. /dir/*.py - match all python files in /dir and subdirectories
  505. .. _RENAME:
  506. .. code-block:: cmake
  507. file(RENAME <oldname> <newname>
  508. [RESULT <result>]
  509. [NO_REPLACE])
  510. Move a file or directory within a filesystem from ``<oldname>`` to
  511. ``<newname>``, replacing the destination atomically.
  512. The options are:
  513. ``RESULT <result>``
  514. Set ``<result>`` variable to ``0`` on success or an error message otherwise.
  515. If ``RESULT`` is not specified and the operation fails, an error is emitted.
  516. ``NO_REPLACE``
  517. If the ``<newname>`` path already exists, do not replace it.
  518. If ``RESULT <result>`` is used, the result variable will be
  519. set to ``NO_REPLACE``. Otherwise, an error is emitted.
  520. .. _REMOVE:
  521. .. _REMOVE_RECURSE:
  522. .. code-block:: cmake
  523. file(REMOVE [<files>...])
  524. file(REMOVE_RECURSE [<files>...])
  525. Remove the given files. The ``REMOVE_RECURSE`` mode will remove the given
  526. files and directories, also non-empty directories. No error is emitted if a
  527. given file does not exist. Relative input paths are evaluated with respect
  528. to the current source directory.
  529. .. versionchanged:: 3.15
  530. Empty input paths are ignored with a warning. Previous versions of CMake
  531. interpreted empty string as a relative path with respect to the current
  532. directory and removed its contents.
  533. .. _MAKE_DIRECTORY:
  534. .. code-block:: cmake
  535. file(MAKE_DIRECTORY [<directories>...])
  536. Create the given directories and their parents as needed.
  537. .. _COPY:
  538. .. _INSTALL:
  539. .. code-block:: cmake
  540. file(<COPY|INSTALL> <files>... DESTINATION <dir>
  541. [FILE_PERMISSIONS <permissions>...]
  542. [DIRECTORY_PERMISSIONS <permissions>...]
  543. [NO_SOURCE_PERMISSIONS] [USE_SOURCE_PERMISSIONS]
  544. [FOLLOW_SYMLINK_CHAIN]
  545. [FILES_MATCHING]
  546. [[PATTERN <pattern> | REGEX <regex>]
  547. [EXCLUDE] [PERMISSIONS <permissions>...]] [...])
  548. The ``COPY`` signature copies files, directories, and symlinks to a
  549. destination folder. Relative input paths are evaluated with respect
  550. to the current source directory, and a relative destination is
  551. evaluated with respect to the current build directory. Copying
  552. preserves input file timestamps, and optimizes out a file if it exists
  553. at the destination with the same timestamp. Copying preserves input
  554. permissions unless explicit permissions or ``NO_SOURCE_PERMISSIONS``
  555. are given (default is ``USE_SOURCE_PERMISSIONS``).
  556. .. versionadded:: 3.15
  557. If ``FOLLOW_SYMLINK_CHAIN`` is specified, ``COPY`` will recursively resolve
  558. the symlinks at the paths given until a real file is found, and install
  559. a corresponding symlink in the destination for each symlink encountered. For
  560. each symlink that is installed, the resolution is stripped of the directory,
  561. leaving only the filename, meaning that the new symlink points to a file in
  562. the same directory as the symlink. This feature is useful on some Unix systems,
  563. where libraries are installed as a chain of symlinks with version numbers, with
  564. less specific versions pointing to more specific versions.
  565. ``FOLLOW_SYMLINK_CHAIN`` will install all of these symlinks and the library
  566. itself into the destination directory. For example, if you have the following
  567. directory structure:
  568. * ``/opt/foo/lib/libfoo.so.1.2.3``
  569. * ``/opt/foo/lib/libfoo.so.1.2 -> libfoo.so.1.2.3``
  570. * ``/opt/foo/lib/libfoo.so.1 -> libfoo.so.1.2``
  571. * ``/opt/foo/lib/libfoo.so -> libfoo.so.1``
  572. and you do:
  573. .. code-block:: cmake
  574. file(COPY /opt/foo/lib/libfoo.so DESTINATION lib FOLLOW_SYMLINK_CHAIN)
  575. This will install all of the symlinks and ``libfoo.so.1.2.3`` itself into
  576. ``lib``.
  577. See the :command:`install(DIRECTORY)` command for documentation of
  578. permissions, ``FILES_MATCHING``, ``PATTERN``, ``REGEX``, and
  579. ``EXCLUDE`` options. Copying directories preserves the structure
  580. of their content even if options are used to select a subset of
  581. files.
  582. The ``INSTALL`` signature differs slightly from ``COPY``: it prints
  583. status messages (subject to the :variable:`CMAKE_INSTALL_MESSAGE` variable),
  584. and ``NO_SOURCE_PERMISSIONS`` is default.
  585. Installation scripts generated by the :command:`install` command
  586. use this signature (with some undocumented options for internal use).
  587. .. _SIZE:
  588. .. code-block:: cmake
  589. file(SIZE <filename> <variable>)
  590. .. versionadded:: 3.14
  591. Determine the file size of the ``<filename>`` and put the result in
  592. ``<variable>`` variable. Requires that ``<filename>`` is a valid path
  593. pointing to a file and is readable.
  594. .. _READ_SYMLINK:
  595. .. code-block:: cmake
  596. file(READ_SYMLINK <linkname> <variable>)
  597. .. versionadded:: 3.14
  598. This subcommand queries the symlink ``<linkname>`` and stores the path it
  599. points to in the result ``<variable>``. If ``<linkname>`` does not exist or
  600. is not a symlink, CMake issues a fatal error.
  601. Note that this command returns the raw symlink path and does not resolve
  602. a relative path. The following is an example of how to ensure that an
  603. absolute path is obtained:
  604. .. code-block:: cmake
  605. set(linkname "/path/to/foo.sym")
  606. file(READ_SYMLINK "${linkname}" result)
  607. if(NOT IS_ABSOLUTE "${result}")
  608. get_filename_component(dir "${linkname}" DIRECTORY)
  609. set(result "${dir}/${result}")
  610. endif()
  611. .. _CREATE_LINK:
  612. .. code-block:: cmake
  613. file(CREATE_LINK <original> <linkname>
  614. [RESULT <result>] [COPY_ON_ERROR] [SYMBOLIC])
  615. .. versionadded:: 3.14
  616. Create a link ``<linkname>`` that points to ``<original>``.
  617. It will be a hard link by default, but providing the ``SYMBOLIC`` option
  618. results in a symbolic link instead. Hard links require that ``original``
  619. exists and is a file, not a directory. If ``<linkname>`` already exists,
  620. it will be overwritten.
  621. The ``<result>`` variable, if specified, receives the status of the operation.
  622. It is set to ``0`` upon success or an error message otherwise. If ``RESULT``
  623. is not specified and the operation fails, a fatal error is emitted.
  624. Specifying ``COPY_ON_ERROR`` enables copying the file as a fallback if
  625. creating the link fails. It can be useful for handling situations such as
  626. ``<original>`` and ``<linkname>`` being on different drives or mount points,
  627. which would make them unable to support a hard link.
  628. .. _CHMOD:
  629. .. code-block:: cmake
  630. file(CHMOD <files>... <directories>...
  631. [PERMISSIONS <permissions>...]
  632. [FILE_PERMISSIONS <permissions>...]
  633. [DIRECTORY_PERMISSIONS <permissions>...])
  634. .. versionadded:: 3.19
  635. Set the permissions for the ``<files>...`` and ``<directories>...`` specified.
  636. Valid permissions are ``OWNER_READ``, ``OWNER_WRITE``, ``OWNER_EXECUTE``,
  637. ``GROUP_READ``, ``GROUP_WRITE``, ``GROUP_EXECUTE``, ``WORLD_READ``,
  638. ``WORLD_WRITE``, ``WORLD_EXECUTE``, ``SETUID``, ``SETGID``.
  639. Valid combination of keywords are:
  640. ``PERMISSIONS``
  641. All items are changed.
  642. ``FILE_PERMISSIONS``
  643. Only files are changed.
  644. ``DIRECTORY_PERMISSIONS``
  645. Only directories are changed.
  646. ``PERMISSIONS`` and ``FILE_PERMISSIONS``
  647. ``FILE_PERMISSIONS`` overrides ``PERMISSIONS`` for files.
  648. ``PERMISSIONS`` and ``DIRECTORY_PERMISSIONS``
  649. ``DIRECTORY_PERMISSIONS`` overrides ``PERMISSIONS`` for directories.
  650. ``FILE_PERMISSIONS`` and ``DIRECTORY_PERMISSIONS``
  651. Use ``FILE_PERMISSIONS`` for files and ``DIRECTORY_PERMISSIONS`` for
  652. directories.
  653. .. _CHMOD_RECURSE:
  654. .. code-block:: cmake
  655. file(CHMOD_RECURSE <files>... <directories>...
  656. [PERMISSIONS <permissions>...]
  657. [FILE_PERMISSIONS <permissions>...]
  658. [DIRECTORY_PERMISSIONS <permissions>...])
  659. .. versionadded:: 3.19
  660. Same as `CHMOD`_, but change the permissions of files and directories present in
  661. the ``<directories>...`` recursively.
  662. Path Conversion
  663. ^^^^^^^^^^^^^^^
  664. .. _REAL_PATH:
  665. .. code-block:: cmake
  666. file(REAL_PATH <path> <out-var> [BASE_DIRECTORY <dir>])
  667. .. versionadded:: 3.19
  668. Compute the absolute path to an existing file or directory with symlinks
  669. resolved.
  670. If the provided ``<path>`` is a relative path, it is evaluated relative to the
  671. given base directory ``<dir>``. If no base directory is provided, the default
  672. base directory will be :variable:`CMAKE_CURRENT_SOURCE_DIR`.
  673. .. _RELATIVE_PATH:
  674. .. code-block:: cmake
  675. file(RELATIVE_PATH <variable> <directory> <file>)
  676. Compute the relative path from a ``<directory>`` to a ``<file>`` and
  677. store it in the ``<variable>``.
  678. .. _TO_CMAKE_PATH:
  679. .. _TO_NATIVE_PATH:
  680. .. code-block:: cmake
  681. file(TO_CMAKE_PATH "<path>" <variable>)
  682. file(TO_NATIVE_PATH "<path>" <variable>)
  683. The ``TO_CMAKE_PATH`` mode converts a native ``<path>`` into a cmake-style
  684. path with forward-slashes (``/``). The input can be a single path or a
  685. system search path like ``$ENV{PATH}``. A search path will be converted
  686. to a cmake-style list separated by ``;`` characters.
  687. The ``TO_NATIVE_PATH`` mode converts a cmake-style ``<path>`` into a native
  688. path with platform-specific slashes (``\`` on Windows and ``/`` elsewhere).
  689. Always use double quotes around the ``<path>`` to be sure it is treated
  690. as a single argument to this command.
  691. Transfer
  692. ^^^^^^^^
  693. .. _DOWNLOAD:
  694. .. _UPLOAD:
  695. .. code-block:: cmake
  696. file(DOWNLOAD <url> [<file>] [<options>...])
  697. file(UPLOAD <file> <url> [<options>...])
  698. The ``DOWNLOAD`` subcommand downloads the given ``<url>`` to a local ``<file>``.
  699. The ``UPLOAD`` mode uploads a local ``<file>`` to a given ``<url>``.
  700. .. versionadded:: 3.19
  701. If ``<file>`` is not specified for ``file(DOWNLOAD)``, the file is not saved.
  702. This can be useful if you want to know if a file can be downloaded (for example,
  703. to check that it exists) without actually saving it anywhere.
  704. Options to both ``DOWNLOAD`` and ``UPLOAD`` are:
  705. ``INACTIVITY_TIMEOUT <seconds>``
  706. Terminate the operation after a period of inactivity.
  707. ``LOG <variable>``
  708. Store a human-readable log of the operation in a variable.
  709. ``SHOW_PROGRESS``
  710. Print progress information as status messages until the operation is
  711. complete.
  712. ``STATUS <variable>``
  713. Store the resulting status of the operation in a variable.
  714. The status is a ``;`` separated list of length 2.
  715. The first element is the numeric return value for the operation,
  716. and the second element is a string value for the error.
  717. A ``0`` numeric error means no error in the operation.
  718. ``TIMEOUT <seconds>``
  719. Terminate the operation after a given total time has elapsed.
  720. ``USERPWD <username>:<password>``
  721. .. versionadded:: 3.7
  722. Set username and password for operation.
  723. ``HTTPHEADER <HTTP-header>``
  724. .. versionadded:: 3.7
  725. HTTP header for operation. Suboption can be repeated several times.
  726. ``NETRC <level>``
  727. .. versionadded:: 3.11
  728. Specify whether the .netrc file is to be used for operation. If this
  729. option is not specified, the value of the ``CMAKE_NETRC`` variable
  730. will be used instead.
  731. Valid levels are:
  732. ``IGNORED``
  733. The .netrc file is ignored.
  734. This is the default.
  735. ``OPTIONAL``
  736. The .netrc file is optional, and information in the URL is preferred.
  737. The file will be scanned to find which ever information is not specified
  738. in the URL.
  739. ``REQUIRED``
  740. The .netrc file is required, and information in the URL is ignored.
  741. ``NETRC_FILE <file>``
  742. .. versionadded:: 3.11
  743. Specify an alternative .netrc file to the one in your home directory,
  744. if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option
  745. is not specified, the value of the ``CMAKE_NETRC_FILE`` variable will
  746. be used instead.
  747. If neither ``NETRC`` option is given CMake will check variables
  748. ``CMAKE_NETRC`` and ``CMAKE_NETRC_FILE``, respectively.
  749. ``TLS_VERIFY <ON|OFF>``
  750. Specify whether to verify the server certificate for ``https://`` URLs.
  751. The default is to *not* verify.
  752. .. versionadded:: 3.18
  753. Added support to ``file(UPLOAD)``.
  754. ``TLS_CAINFO <file>``
  755. Specify a custom Certificate Authority file for ``https://`` URLs.
  756. .. versionadded:: 3.18
  757. Added support to ``file(UPLOAD)``.
  758. For ``https://`` URLs CMake must be built with OpenSSL support. ``TLS/SSL``
  759. certificates are not checked by default. Set ``TLS_VERIFY`` to ``ON`` to
  760. check certificates. If neither ``TLS`` option is given CMake will check
  761. variables ``CMAKE_TLS_VERIFY`` and ``CMAKE_TLS_CAINFO``, respectively.
  762. Additional options to ``DOWNLOAD`` are:
  763. ``EXPECTED_HASH ALGO=<value>``
  764. Verify that the downloaded content hash matches the expected value, where
  765. ``ALGO`` is one of the algorithms supported by ``file(<HASH>)``.
  766. If it does not match, the operation fails with an error. It is an error to
  767. specify this if ``DOWNLOAD`` is not given a ``<file>``.
  768. ``EXPECTED_MD5 <value>``
  769. Historical short-hand for ``EXPECTED_HASH MD5=<value>``. It is an error to
  770. specify this if ``DOWNLOAD`` is not given a ``<file>``.
  771. Locking
  772. ^^^^^^^
  773. .. _LOCK:
  774. .. code-block:: cmake
  775. file(LOCK <path> [DIRECTORY] [RELEASE]
  776. [GUARD <FUNCTION|FILE|PROCESS>]
  777. [RESULT_VARIABLE <variable>]
  778. [TIMEOUT <seconds>])
  779. .. versionadded:: 3.2
  780. Lock a file specified by ``<path>`` if no ``DIRECTORY`` option present and file
  781. ``<path>/cmake.lock`` otherwise. File will be locked for scope defined by
  782. ``GUARD`` option (default value is ``PROCESS``). ``RELEASE`` option can be used
  783. to unlock file explicitly. If option ``TIMEOUT`` is not specified CMake will
  784. wait until lock succeed or until fatal error occurs. If ``TIMEOUT`` is set to
  785. ``0`` lock will be tried once and result will be reported immediately. If
  786. ``TIMEOUT`` is not ``0`` CMake will try to lock file for the period specified
  787. by ``<seconds>`` value. Any errors will be interpreted as fatal if there is no
  788. ``RESULT_VARIABLE`` option. Otherwise result will be stored in ``<variable>``
  789. and will be ``0`` on success or error message on failure.
  790. Note that lock is advisory - there is no guarantee that other processes will
  791. respect this lock, i.e. lock synchronize two or more CMake instances sharing
  792. some modifiable resources. Similar logic applied to ``DIRECTORY`` option -
  793. locking parent directory doesn't prevent other ``LOCK`` commands to lock any
  794. child directory or file.
  795. Trying to lock file twice is not allowed. Any intermediate directories and
  796. file itself will be created if they not exist. ``GUARD`` and ``TIMEOUT``
  797. options ignored on ``RELEASE`` operation.
  798. Archiving
  799. ^^^^^^^^^
  800. .. _ARCHIVE_CREATE:
  801. .. code-block:: cmake
  802. file(ARCHIVE_CREATE OUTPUT <archive>
  803. PATHS <paths>...
  804. [FORMAT <format>]
  805. [COMPRESSION <compression> [COMPRESSION_LEVEL <compression-level>]]
  806. [MTIME <mtime>]
  807. [VERBOSE])
  808. .. versionadded:: 3.18
  809. Creates the specified ``<archive>`` file with the files and directories
  810. listed in ``<paths>``. Note that ``<paths>`` must list actual files or
  811. directories, wildcards are not supported.
  812. Use the ``FORMAT`` option to specify the archive format. Supported values
  813. for ``<format>`` are ``7zip``, ``gnutar``, ``pax``, ``paxr``, ``raw`` and
  814. ``zip``. If ``FORMAT`` is not given, the default format is ``paxr``.
  815. Some archive formats allow the type of compression to be specified.
  816. The ``7zip`` and ``zip`` archive formats already imply a specific type of
  817. compression. The other formats use no compression by default, but can be
  818. directed to do so with the ``COMPRESSION`` option. Valid values for
  819. ``<compression>`` are ``None``, ``BZip2``, ``GZip``, ``XZ``, and ``Zstd``.
  820. .. versionadded:: 3.19
  821. The compression level can be specified with the ``COMPRESSION_LEVEL`` option.
  822. The ``<compression-level>`` should be between 0-9, with the default being 0.
  823. The ``COMPRESSION`` option must be present when ``COMPRESSION_LEVEL`` is given.
  824. .. note::
  825. With ``FORMAT`` set to ``raw`` only one file will be compressed with the
  826. compression type specified by ``COMPRESSION``.
  827. The ``VERBOSE`` option enables verbose output for the archive operation.
  828. To specify the modification time recorded in tarball entries, use
  829. the ``MTIME`` option.
  830. .. _ARCHIVE_EXTRACT:
  831. .. code-block:: cmake
  832. file(ARCHIVE_EXTRACT INPUT <archive>
  833. [DESTINATION <dir>]
  834. [PATTERNS <patterns>...]
  835. [LIST_ONLY]
  836. [VERBOSE])
  837. .. versionadded:: 3.18
  838. Extracts or lists the content of the specified ``<archive>``.
  839. The directory where the content of the archive will be extracted to can
  840. be specified using the ``DESTINATION`` option. If the directory does not
  841. exist, it will be created. If ``DESTINATION`` is not given, the current
  842. binary directory will be used.
  843. If required, you may select which files and directories to list or extract
  844. from the archive using the specified ``<patterns>``. Wildcards are supported.
  845. If the ``PATTERNS`` option is not given, the entire archive will be listed or
  846. extracted.
  847. ``LIST_ONLY`` will list the files in the archive rather than extract them.
  848. With ``VERBOSE``, the command will produce verbose output.