[英]CMake insert in file in a specific line
Is it possible to inser text from a CMakeLists.txt into a file in a specific line (and move one line down the rest of the lines). 是否可以将CMakeLists.txt中的文本插入到特定行中的文件中(并在其余各行中向下移动一行)。
I have read the FILE function documentation http://www.cmake.org/cmake/help/v3.0/command/file.html but I cannot find anything. 我已经阅读了FILE函数文档http://www.cmake.org/cmake/help/v3.0/command/file.html,但是找不到任何东西。
Objective: From CMake, I want to modify a HTML file so that the directory of the index.html is wrote in this HTML file (potentially as a link). 目标:我想从CMake修改HTML文件,以便将index.html的目录写入此HTML文件中(可能作为链接)。 I am creating a file to log different things (output files directories).
我正在创建一个文件来记录不同的东西(输出文件目录)。 For example:
例如:
File before running cmake: 运行cmake之前的文件:
<html>
<head>
</head>
<body>
<!-- Insert text here -->
</body>
</html>
File after runing a CMakeLists.txt with something like 运行类似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>
You can use configure_file
to fill a template with CMake variables. 您可以使用
configure_file
用CMake变量填充模板。
Simple example: 简单的例子:
test.html.in test.html.in
<html>
<head>
</head>
<body>
@html_string@
</body>
</html>
CMakeLists.txt 的CMakeLists.txt
project(test)
set(html_string "<p>Inserted text.</p>")
configure_file(test.html.in test.html)
Running cmake
results in a file test.html with the following contents to be created: 运行
cmake
会生成一个文件test.html,其中包含以下内容:
<html>
<head>
</head>
<body>
<p>Inserted text.</p>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.