如何从add_custom_target/命令调用CMake函数

How to call a CMake function from add_custom_target/command?

本文关键字:命令 调用 CMake 函数 custom add target      更新时间:2023-10-16

是否可以从add_custom_targetadd_custom_command中调用CMake函数?

我知道我可以将CMake函数移到Python(或其他)脚本中,并从add_custom_target/command调用它,但我希望避免在现有的CMake基础结构旁边有大量的脚本。

我想要实现的是使用CPack生成二进制工件的zip包,并将它们发布在工件存储库中。对于发布部分,我已经创建了CMake函数,但现在我需要将打包和发布结合在一起。

感谢您提前提供的任何帮助/提示。

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

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

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

相关文章: