繁体   English   中英

CMake在文件中插入特定行

[英]CMake insert in file in a specific line

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

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

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

运行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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM