How to call a CMake function from add_custom_target/command?(如何从 add_custom_target/command 调用 CMake 函数?)
问题描述
是否可以从 add_custom_target
或 add_custom_command
中调用 CMake 函数?
Is it possible to call a CMake function out of an add_custom_target
or add_custom_command
?
我知道我可以将 CMake 函数移动到 Python(或其他)脚本并从 add_custom_target
/command
调用它,但我想避免大量脚本在现有的 CMake 基础设施旁边.
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.
我想要实现的是使用 CPack 生成二进制工件的 zip 包并将它们发布到工件存储库中.对于发布部分,我已经创建了 CMake 函数,但现在我需要将打包和发布结合在一起.
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.
推荐答案
我在为 BVLC/Caffe.我最终做的是将函数内容放入一个单独的 CMake 脚本中,并通过调用从 add_custom_target
中调用它:
I encountered this issue while writing a CMake build system for BVLC/Caffe. What I finally did is I put the function content into a separate CMake script and called it from within add_custom_target
by invoking:
add_custom_target(target_name
COMMAND ${CMAKE_COMMAND} -P path_to_script
)
使用 -P
标志调用 CMake 使其充当脚本语言.您可以在脚本中放置任何 CMake 函数.
Invoking CMake with -P
flag makes it act as a scripting language. You can put any CMake functions inside the script.
这篇关于如何从 add_custom_target/command 调用 CMake 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从 add_custom_target/command 调用 CMake 函数?
基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01