簡體   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