html - CMake 在特定行中插入文件

标签 html cmake

是否可以将 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/

相关文章:

c# - 如何解析此 HTML 以获得我想要的内容?

html - 如何创建这种交替布局?

opencv - 如何将 OpenCV DLL 文件复制到 cmake 调试/发布文件夹中?

c++ - CMake 解析错误函数缺少结尾 ")"。相反,发现未终止的字符串带有文本“)

html - 打印预览表堆叠不良?

javascript - 点击 'a'打开两个链接

c++ - 链接器错误:无法解析构造函数

cmake - 从 cmake 到 autotools 的翻译?

c++ - CMake 无法在 Clion 的 Windows 上找到 freeglut

jquery - 改变不同屏幕尺寸的动画