在 cmake 中应用 editbin
Apply editbin in cmake
我正在尝试在构建可执行文件后使用 cmake
脚本中的一些选项自动调用 editbin
。到目前为止没有任何运气。
- 有没有在
cmake
中使用editbin
的例子?
- 是否有在构建可执行文件后在
cmake
中使用任何可执行文件的示例?
您可以使用 add_custom_command 构建事件,也就是说,它会在您每次构建目标时执行。
来自文档:
POST_BUILD 事件可用于 post-process 链接后的二进制文件。例如代码:
add_executable(myExe myExe.c)
add_custom_command(
TARGET myExe POST_BUILD
COMMAND someHasher -i "$<TARGET_FILE:myExe>"
-o "$<TARGET_FILE:myExe>.hash"
VERBATIM)
将 运行 someHasher 在链接后在可执行文件旁边生成一个 .hash 文件。
至于VERBATIM
:
All arguments to the commands will be escaped properly for the build tool so that the invoked command receives each argument unchanged. Note that one level of escapes is still used by the CMake language processor before add_custom_command even sees the arguments. Use of VERBATIM is recommended as it enables correct behavior. When VERBATIM is not given the behavior is platform specific because there is no protection of tool-specific special characters.
所以在你的情况下,你首先需要为 editbin
找到一个可执行文件,然后添加你的命令:
add_custom_command(TARGET target_name POST_BUILD
COMMAND "${editbin_exe} $<TARGET_FILE:target_name>")
其中 $<TARGET_FILE:target_name>
是一个 generator expression,它生成目标 target_name
.
的输出二进制文件的路径
我正在尝试在构建可执行文件后使用 cmake
脚本中的一些选项自动调用 editbin
。到目前为止没有任何运气。
- 有没有在
cmake
中使用editbin
的例子? - 是否有在构建可执行文件后在
cmake
中使用任何可执行文件的示例?
您可以使用 add_custom_command 构建事件,也就是说,它会在您每次构建目标时执行。
来自文档:
POST_BUILD 事件可用于 post-process 链接后的二进制文件。例如代码:
add_executable(myExe myExe.c)
add_custom_command(
TARGET myExe POST_BUILD
COMMAND someHasher -i "$<TARGET_FILE:myExe>"
-o "$<TARGET_FILE:myExe>.hash"
VERBATIM)
将 运行 someHasher 在链接后在可执行文件旁边生成一个 .hash 文件。
至于VERBATIM
:
All arguments to the commands will be escaped properly for the build tool so that the invoked command receives each argument unchanged. Note that one level of escapes is still used by the CMake language processor before add_custom_command even sees the arguments. Use of VERBATIM is recommended as it enables correct behavior. When VERBATIM is not given the behavior is platform specific because there is no protection of tool-specific special characters.
所以在你的情况下,你首先需要为 editbin
找到一个可执行文件,然后添加你的命令:
add_custom_command(TARGET target_name POST_BUILD
COMMAND "${editbin_exe} $<TARGET_FILE:target_name>")
其中 $<TARGET_FILE:target_name>
是一个 generator expression,它生成目标 target_name
.