【问题标题】:CMake add_custom_command inside of a macroCMake add_custom_command 在宏内
【发布时间】:2015-02-12 09:04:39
【问题描述】:

我的 CMake 代码如下所示:

macro(macro_name target_name)
    add_custom_command(TARGET ${target_name}
        POST_BUILD
        COMMAND MyCommand)
endmacro()

运行此程序,我收到以下消息:

CMake Warning (dev) at ... (add_custom_command):
Policy CMP0040 is not set: The target in the TARGET signature of
add_custom_command() must exist.  Run "cmake --help-policy CMP0040" for
policy details.  Use the cmake_policy command to set the policy and
suppress this warning.

The target name "target_name" is unknown in this context.

函数内部的相同代码效果很好,但我需要宏来处理其他事情。

CMake 政策 (http://www.cmake.org/cmake/help/v3.0/policy/CMP0040.html) 建议忽略此警告(并完全忽略添加后期构建步骤)或根据设置将其视为错误。

这:http://www.cmake.org/cmake/help/v3.0/command/macro.html 声明宏中的参数行为与函数中的行为不同。

如何正确参考宏参数来完成这项工作?

【问题讨论】:

    标签: macros cmake post-build-event


    【解决方案1】:

    我已经设法找出原因:在我的例子中,错误的目录被用作宏内部的 ${CMAKE_CURRENT_BINARY_DIR}。修复路径以获得理想的结果

    【讨论】:

    • 你能复制粘贴整个解决方案吗?这个答案有点没用。
    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    相关资源
    最近更新 更多