推迟自定义目标,直到安装 [英] Postpone making custom target until install
问题描述
我的项目中有这样的东西:
add_custom_command(OUTPUT somefile)
add_custom_target(tgt ALL DEPENDS somefile)
install(FILES $ {CMAKE_CURRENT_BINARY_DIR} / somefile DESTINATION somedir)
这个工作正常,但我的命令是在 make
中运行,因为add_custom_target()中的 ALL
关键字。我想要的是使CMake只有在 make install
时发出,而不是在构建期间运行此命令。
如果我删除ALL关键字,整个目标没有正在建设默认情况下,所以不生成somefile并且 make install
失败。
add_custom_command(OUTPUT somefile)
add_custom_target(tgt DEPENDS somefile)
install(CODEexecute_process(COMMAND \$ {CMAKE_COMMAND} \--build \$ {CMAKE_CURRENT_BINARY_DIR} \--target tgt))
install(FILES $ {CMAKE_CURRENT_BINARY_DIR} / somefile DESTINATION somedir)
execute_process
调用cmake以在之前创建目标
tgt
I have something like this in my project:
add_custom_command(OUTPUT somefile)
add_custom_target(tgt ALL DEPENDS somefile)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/somefile DESTINATION somedir)
This works OK, but my command is being run during make
because of ALL
keyword in add_custom_target(). What i want is to make CMake to run this command only when make install
is issued, not during build.
If i remove ALL keyword, whole target is not being built by default, so somefile is not produced and make install
fails.
A possible solution is to have the make install
command invoke the make tgt
as a side effect. This can be done by using the CODE
signature of the install command:
add_custom_command(OUTPUT somefile)
add_custom_target(tgt DEPENDS somefile)
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_CURRENT_BINARY_DIR}\" --target tgt)")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/somefile DESTINATION somedir)
The execute_process
invokes cmake to build the target tgt
before somefile
is installed.
这篇关于推迟自定义目标,直到安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!