2015-02-12 61 views
0

我的CMake的代码中的CMake add_custom_command如下所示:运行此的宏观

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指出宏中的参数行为与函数中的行为不同。

如何正确引用宏参数来实现这个功能?

回答

0

我设法找出原因:在我的情况下,错误的目录被用作宏里面的$ {CMAKE_CURRENT_BINARY_DIR}。修复路径允许获得理想的结果

+1

创建http://sscce.org/可帮助您发现此类问题。 – steveire 2015-02-13 18:35:18

+0

你可以复制粘贴整个解决方案吗?这个答案有点无用。 – TarmoPikaro 2017-08-03 11:59:05