file.rst 48 KB

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