From b16750f2d2ca8a5f5617a9d83ff73ce213b60384 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Fri, 6 Mar 2020 13:41:07 +0100 Subject: [PATCH] file: Add CONFIGURE subcommand Extend the `file()` command with a new `CONFIGURE` subcommand that behaves the same as `string(CONFIGURE)` except that it writes the resulting output immediately to a file. Fixes: #20388 --- Help/command/file.rst | 40 ++++++ Help/release/dev/file_configure.rst | 6 + Source/cmFileCommand.cxx | 118 ++++++++++++++++++ Tests/RunCMake/CMakeLists.txt | 1 + .../RunCMake/File_Configure/BadArg-result.txt | 1 + .../RunCMake/File_Configure/BadArg-stderr.txt | 4 + Tests/RunCMake/File_Configure/BadArg.cmake | 1 + ...adArgGeneratorExpressionContent-result.txt | 1 + ...adArgGeneratorExpressionContent-stderr.txt | 5 + .../BadArgGeneratorExpressionContent.cmake | 4 + ...BadArgGeneratorExpressionOutput-result.txt | 1 + ...BadArgGeneratorExpressionOutput-stderr.txt | 5 + .../BadArgGeneratorExpressionOutput.cmake | 4 + Tests/RunCMake/File_Configure/CMakeLists.txt | 3 + .../File_Configure/DirOutput-stderr.txt | 1 + Tests/RunCMake/File_Configure/DirOutput.cmake | 4 + Tests/RunCMake/File_Configure/DirOutput.txt | 1 + .../NewLineStyle-NoArg-result.txt | 1 + .../NewLineStyle-NoArg-stderr.txt | 5 + .../File_Configure/NewLineStyle-NoArg.cmake | 6 + .../NewLineStyle-ValidArg.cmake | 20 +++ .../NewLineStyle-WrongArg-result.txt | 1 + .../NewLineStyle-WrongArg-stderr.txt | 5 + .../NewLineStyle-WrongArg.cmake | 6 + .../File_Configure/RunCMakeTest.cmake | 9 ++ 25 files changed, 253 insertions(+) create mode 100644 Help/release/dev/file_configure.rst create mode 100644 Tests/RunCMake/File_Configure/BadArg-result.txt create mode 100644 Tests/RunCMake/File_Configure/BadArg-stderr.txt create mode 100644 Tests/RunCMake/File_Configure/BadArg.cmake create mode 100644 Tests/RunCMake/File_Configure/BadArgGeneratorExpressionContent-result.txt create mode 100644 Tests/RunCMake/File_Configure/BadArgGeneratorExpressionContent-stderr.txt create mode 100644 Tests/RunCMake/File_Configure/BadArgGeneratorExpressionContent.cmake create mode 100644 Tests/RunCMake/File_Configure/BadArgGeneratorExpressionOutput-result.txt create mode 100644 Tests/RunCMake/File_Configure/BadArgGeneratorExpressionOutput-stderr.txt create mode 100644 Tests/RunCMake/File_Configure/BadArgGeneratorExpressionOutput.cmake create mode 100644 Tests/RunCMake/File_Configure/CMakeLists.txt create mode 100644 Tests/RunCMake/File_Configure/DirOutput-stderr.txt create mode 100644 Tests/RunCMake/File_Configure/DirOutput.cmake create mode 100644 Tests/RunCMake/File_Configure/DirOutput.txt create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-NoArg-result.txt create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-NoArg-stderr.txt create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-NoArg.cmake create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-ValidArg.cmake create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-WrongArg-result.txt create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-WrongArg-stderr.txt create mode 100644 Tests/RunCMake/File_Configure/NewLineStyle-WrongArg.cmake create mode 100644 Tests/RunCMake/File_Configure/RunCMakeTest.cmake diff --git a/Help/command/file.rst b/Help/command/file.rst index 5877d4345e..5a479d90de 100644 --- a/Help/command/file.rst +++ b/Help/command/file.rst @@ -19,6 +19,7 @@ Synopsis file({`WRITE`_ | `APPEND`_} ...) file({`TOUCH`_ | `TOUCH_NOCREATE`_} [...]) file(`GENERATE`_ OUTPUT [...]) + file(`CONFIGURE`_ OUTPUT CONTENT [...]) `Filesystem`_ file({`GLOB`_ | `GLOB_RECURSE`_} [...] [...]) @@ -484,6 +485,45 @@ generation phase. The output file will not yet have been written when the ``file(GENERATE)`` command returns, it is written only after processing all of a project's ``CMakeLists.txt`` files. +.. _CONFIGURE: + +.. code-block:: cmake + + file(CONFIGURE OUTPUT output-file + CONTENT content + [ESCAPE_QUOTES] [@ONLY] + [NEWLINE_STYLE [UNIX|DOS|WIN32|LF|CRLF] ]) + +Generate an output file using the input given by ``CONTENT`` and substitute +variable values referenced as ``@VAR@`` or ``${VAR}`` contained therein. The +substitution rules behave the same as the :command:`configure_file` command. +In order to match :command:`configure_file`'s behavior, generator expressions +are not supported for both ``OUTPUT`` and ``CONTENT``. + +The arguments are: + +``OUTPUT `` + Specify the output file name to generate. A relative path is treated with + respect to the value of :variable:`CMAKE_CURRENT_BINARY_DIR`. See policy + :policy:`CMP0070`. + ```` does not support generator expressions. + +``CONTENT `` + Use the content given explicitly as input. + ```` does not support generator expressions. + +``ESCAPE_QUOTES`` + Escape any substituted quotes with backslashes (C-style). + +``@ONLY`` + Restrict variable replacement to references of the form ``@VAR@``. + This is useful for configuring scripts that use ``${VAR}`` syntax. + +``NEWLINE_STYLE