是否可以将 CMakeLists.txt 中的文本插入特定行的文件中(并将一行向下移动到其余行)。
我已阅读 FILE 函数文档 http://www.cmake.org/cmake/help/v3.0/command/file.html但我找不到任何东西。
目标:我想从 CMake 修改一个 HTML 文件,以便在这个 HTML 文件中写入 index.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>
关于html - CMake 在特定行中插入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30504100/