append null character at the end of file using cmake

我的梦境 提交于 2019-12-25 05:07:27

问题


I am trying to concatenate files using cmake and append a null character(\0) at the end of output file. Does anyone know how to append null at the end? The code for concat is :

function(cat in_file1 in_file2 out_file)
     file(READ   ${in_file1} CONTENTS)
     file(WRITE  ${out_file} "${CONTENTS}")
     file(READ   ${in_file2} CONTENTS)
     file(APPEND ${out_file} "${CONTENTS}")
endfunction()

To append '\0' at the end I've tried following approaches :

file(APPEND ${out_file} NULL)
file(APPEND ${out_file} "\\0")
file(APPEND ${out_file} "\0" HEX)

But none of these 3 work. Can anyone help here ?


回答1:


Could you try the following instead of what you have?

function(cat in_file1 in_file2 out_file)
        file(READ   ${in_file1} CONTENTS HEX)
        file(WRITE  ${out_file} "${CONTENTS}")
        file(READ   ${in_file2} CONTENTS HEX)
        file(APPEND ${out_file} "${CONTENTS}00")
endfunction()

this should append a null byte at the end of the generated hex string. Then I don't know how to go from there.
There is some work in this direction but I don't know other examples. I think both the linked examples can be useful to solve your case:

binary_to_hex
embed_binary_files



来源:https://stackoverflow.com/questions/41514723/append-null-character-at-the-end-of-file-using-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!