有没有办法让自定义目标依赖于CPack?

时间:2017-01-27 11:48:23

标签: cmake cpack

假设我使用CPack:

包括(CPack)

这可能会增加两个额外的目标:packagepackage_source,但是如果我想制作一个依赖于它的后包目标:

add_custom_target(do_something_to_package ...)
add_dependencies(do_something_to_package package)

我在构建时遇到错误,如下所示:

make[2]: *** No rule to make target `CMakeFiles/package.dir/all', needed by `CMakeFiles/do_something_to_package.dir/all'.  Stop.

有没有办法让这项工作?

1 个答案:

答案 0 :(得分:1)

啊,按照How to add_custom_target that depends on "make install" question,这似乎有效:

add_custom_target(package_target
    COMMAND "${CMAKE_COMMAND}" --build . --target package
    WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
    COMMENT "Building package"
    DEPENDS stuff_required_for_package
    VERBATIM
)

不完全优雅,但可能会更糟!此外,它似乎并没有特别好地与并行构建。不完全确定为什么,但是为了安全,我会做一个非并行构建。