file ---- File manipulation command. This command is dedicated to file and path manipulation requiring access to the filesystem. For other path manipulation, handling only syntactic aspects, have a look at :command:`cmake_path` command. .. note:: The sub-commands `RELATIVE_PATH`_, `TO_CMAKE_PATH`_ and `TO_NATIVE_PATH`_ has been superseded, respectively, by sub-commands :ref:`RELATIVE_PATH `, :ref:`CONVERT ... TO_CMAKE_PATH_LIST ` and :ref:`CONVERT ... TO_NATIVE_PATH_LIST ` of :command:`cmake_path` command. Synopsis ^^^^^^^^ .. parsed-literal:: `Reading`_ file(`READ`_ [...]) file(`STRINGS`_ [...]) file(`\`_ ) file(`TIMESTAMP`_ [...]) `Writing`_ file({`WRITE`_ | `APPEND`_} ...) file({`TOUCH`_ | `TOUCH_NOCREATE`_} ...) file(`GENERATE`_ OUTPUT [...]) file(`CONFIGURE`_ OUTPUT CONTENT [...]) `Filesystem`_ file({`GLOB`_ | `GLOB_RECURSE`_} [...] ...) file(`MAKE_DIRECTORY`_ ...) file({`REMOVE`_ | `REMOVE_RECURSE`_ } ...) file(`RENAME`_ [...]) file(`COPY_FILE`_ [...]) file({`COPY`_ | `INSTALL`_} ... DESTINATION [...]) file(`SIZE`_ ) file(`READ_SYMLINK`_ ) file(`CREATE_LINK`_ [...]) file(`CHMOD`_ ... ... PERMISSIONS ... [...]) file(`CHMOD_RECURSE`_ ... ... PERMISSIONS ... [...]) `Path Conversion`_ file(`REAL_PATH`_ [BASE_DIRECTORY ] [EXPAND_TILDE]) file(`RELATIVE_PATH`_ ) file({`TO_CMAKE_PATH`_ | `TO_NATIVE_PATH`_} ) `Transfer`_ file(`DOWNLOAD`_ [] [...]) file(`UPLOAD`_ [...]) `Locking`_ file(`LOCK`_ [...]) `Archiving`_ file(`ARCHIVE_CREATE`_ OUTPUT PATHS ... [...]) file(`ARCHIVE_EXTRACT`_ INPUT [...]) `Handling Runtime Binaries`_ file(`GET_RUNTIME_DEPENDENCIES`_ [...]) Reading ^^^^^^^ .. signature:: file(READ [OFFSET ] [LIMIT ] [HEX]) Read content from a file called ```` and store it in a ````. Optionally start from the given ```` and read at most ```` bytes. The ``HEX`` option causes data to be converted to a hexadecimal representation (useful for binary data). If the ``HEX`` option is specified, letters in the output (``a`` through ``f``) are in lowercase. .. signature:: file(STRINGS ...) Parse a list of ASCII strings from ```` and store it in ````. Binary data in the file are ignored. Carriage return (``\r``, CR) characters are ignored. The options are: ``LENGTH_MAXIMUM `` Consider only strings of at most a given length. ``LENGTH_MINIMUM `` Consider only strings of at least a given length. ``LIMIT_COUNT `` Limit the number of distinct strings to be extracted. ``LIMIT_INPUT `` Limit the number of input bytes to read from the file. ``LIMIT_OUTPUT `` Limit the number of total bytes to store in the ````. ``NEWLINE_CONSUME`` Treat newline characters (``\n``, LF) as part of string content instead of terminating at them. ``NO_HEX_CONVERSION`` Intel Hex and Motorola S-record files are automatically converted to binary while reading unless this option is given. ``REGEX `` Consider only strings that match the given regular expression, as described under :ref:`string(REGEX) `. .. versionchanged:: 3.29 Capture groups from the last match in the file are stored in :variable:`CMAKE_MATCH_`, similar to :command:`string(REGEX MATCHALL)`. See policy :policy:`CMP0159`. ``ENCODING `` .. versionadded:: 3.1 Consider strings of a given encoding. Currently supported encodings are: ``UTF-8``, ``UTF-16LE``, ``UTF-16BE``, ``UTF-32LE``, ``UTF-32BE``. If the ``ENCODING`` option is not provided and the file has a Byte Order Mark, the ``ENCODING`` option will be defaulted to respect the Byte Order Mark. .. versionadded:: 3.2 Added the ``UTF-16LE``, ``UTF-16BE``, ``UTF-32LE``, ``UTF-32BE`` encodings. For example, the code .. code-block:: cmake file(STRINGS myfile.txt myfile) stores a list in the variable ``myfile`` in which each item is a line from the input file. .. signature:: file( ) :target: Compute a cryptographic hash of the content of ```` and store it in a ````. The supported ```` algorithm names are those listed by the :command:`string()` command. .. signature:: file(TIMESTAMP [] [UTC]) Compute a string representation of the modification time of ```` and store it in ````. Should the command be unable to obtain a timestamp variable will be set to the empty string (""). See the :command:`string(TIMESTAMP)` command for documentation of the ```` and ``UTC`` options. Writing ^^^^^^^ .. signature:: file(WRITE ...) file(APPEND ...) Write ```` into a file called ````. If the file does not exist, it will be created. If the file already exists, ``WRITE`` mode will overwrite it and ``APPEND`` mode will append to the end. Any directories in the path specified by ```` that do not exist will be created. If the file is a build input, use the :command:`configure_file` command to update the file only when its content changes. .. signature:: file(TOUCH ...) file(TOUCH_NOCREATE ...) .. versionadded:: 3.12 Create a file with no content if it does not yet exist. If the file already exists, its access and/or modification will be updated to the time when the function call is executed. Use ``TOUCH_NOCREATE`` to touch a file if it exists but not create it. If a file does not exist it will be silently ignored. With ``TOUCH`` and ``TOUCH_NOCREATE``, the contents of an existing file will not be modified. .. signature:: file(GENERATE [...]) Generate an output file for each build configuration supported by the current :manual:`CMake Generator `. Evaluate :manual:`generator expressions ` from the input content to produce the output content. .. code-block:: cmake file(GENERATE OUTPUT |CONTENT > [CONDITION ] [TARGET ] [NO_SOURCE_PERMISSIONS | USE_SOURCE_PERMISSIONS | FILE_PERMISSIONS ...] [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) The options are: ``CONDITION `` Generate the output file for a particular configuration only if the condition is true. The condition must be either ``0`` or ``1`` after evaluating generator expressions. ``CONTENT `` Use the content given explicitly as input. ``INPUT `` Use the content from a given file as input. .. versionchanged:: 3.10 A relative path is treated with respect to the value of :variable:`CMAKE_CURRENT_SOURCE_DIR`. See policy :policy:`CMP0070`. ``OUTPUT `` Specify the output file name to generate. Use generator expressions such as :genex:`$` to specify a configuration-specific output file name. Multiple configurations may generate the same output file only if the generated content is identical. Otherwise, the ```` must evaluate to an unique name for each configuration. .. versionchanged:: 3.10 A relative path (after evaluating generator expressions) is treated with respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`. See policy :policy:`CMP0070`. ``TARGET `` .. versionadded:: 3.19 Specify which target to use when evaluating generator expressions that require a target for evaluation (e.g. :genex:`$`, :genex:`$`). ``NO_SOURCE_PERMISSIONS`` .. versionadded:: 3.20 The generated file permissions default to the standard 644 value (-rw-r--r--). ``USE_SOURCE_PERMISSIONS`` .. versionadded:: 3.20 Transfer the file permissions of the ``INPUT`` file to the generated file. This is already the default behavior if none of the three permissions-related keywords are given (``NO_SOURCE_PERMISSIONS``, ``USE_SOURCE_PERMISSIONS`` or ``FILE_PERMISSIONS``). The ``USE_SOURCE_PERMISSIONS`` keyword mostly serves as a way of making the intended behavior clearer at the call site. It is an error to specify this option without ``INPUT``. ``FILE_PERMISSIONS ...`` .. versionadded:: 3.20 Use the specified permissions for the generated file. ``NEWLINE_STYLE