CMake 在特定行中插入文件

CMake insert in file in a specific line

是否可以将 CMakeLists.txt 中的文本插入到文件中的特定行中(并在其余行中向下移动一行)。

我已阅读 FILE 函数文档http://www.cmake.org/cmake/help/v3.0/command/file.html,但我找不到任何内容。

Objective:我想从 CMake 修改一个 HTML 文件,以便 index.html 的目录写入此 HTML 文件(可能作为link)。我正在创建一个文件来记录不同的东西(输出文件目录)。例如:

运行cmake 之前的文件:

<html>
    <head>
    </head>
    <body>
       <!-- Insert text here -->
    </body>
</html>

运行 CMakeLists.txt 之后的文件

file((insert in line 6) ${DOC_DIR}/log.txt "<p>Inserted text.</p>")

<html>
    <head>
    </head>
    <body>
       <!-- Insert text here -->
       <p>This text is normal.</p>
    </body>
</html>

您可以使用 configure_file 用 CMake 变量填充模板。

简单示例:

test.html.in

<html>
    <head>
    </head>
    <body>
    @html_string@
    </body>
</html>

CMakeLists.txt

project(test)
set(html_string "<p>Inserted text.</p>")
configure_file(test.html.in test.html)

运行 cmake 生成一个文件 test.html,其中包含以下内容:

<html>
    <head>
    </head>
    <body>
    <p>Inserted text.</p>
    </body>
</html>