23

Is it possible to call a CMake function out of an add_custom_target or add_custom_command?

I know I could move the CMake function to a Python (or whatever) script and call it from add_custom_target/command but I would like to avoid having tons of script next to the existing CMake infra.

What I want to achieve is to use CPack for generating a zip package of binary artifacts and publish them in an artifact repository. For the publishing part I have already the CMake function created but now I need to combine the packaging and publishing together.

Thanks for any help/hints in advance.

4

2 回答 2

34

我在为BVLC/Caffe编写 CMake 构建系统时遇到了这个问题。我最终所做的是将函数内容放入一个单独的 CMake 脚本中,并add_custom_target通过调用从内部调用它:

add_custom_target(target_name
    COMMAND ${CMAKE_COMMAND} -P path_to_script
)

使用标志调用 CMake-P使其充当脚本语言。您可以将任何 CMake 函数放入脚本中。

于 2014-09-24T19:22:40.587 回答
1

我找了同样的东西,几分钟后我意识到这是不可能的,因为 cmake 是一个构建生成器生成器。

当 cmake 不存在时,此命令将在不同的时间运行,例如从您的 IDE 中运行。

于 2018-12-18T15:04:25.303 回答