自定义命令不会在cmake中使用--target选项执行

时间:2019-08-12 10:10:28

标签: cmake cmake-language

此问题的后续问题:StackBlitz

我编写了一个自定义目标,因此每次我在项目中编译某些东西时它将运行。现在,按照上面的问题中的要求,我调用了一个明确的目标,此自定义命令不再执行。 代码:

const service = new TestService(); service.property = {...};
service.property.keyOne // works
service.property.keyTwo // works

我已经尝试删除add_custom_target( custom_command ALL DEPENDS hash.h WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "[INFO] CMake generating special *.h file from custom command magic." ) 指令,但是它没有任何改变。

忘记添加:我正在使用从源代码编译的ALL

1 个答案:

答案 0 :(得分:0)

很抱歉稍后提供答案,但是工作太疯狂了。因此,在我阅读@ Th.Thielemann和@squareskittles的评论后,我重新阅读了cmake文档并找到了解决方案。以下代码是在cmake/3.0.0下编写的:

add_custom_command( 
    OUTPUT some_header.h
    COMMAND cat ${BISON_HEADER} other_header.h | awk -f some_wak_file.awk > some_header.h
    DEPENDS ${BISON_HEADER}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_custom_target(
    custom_command
    ALL
    DEPENDS some_header.h
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "[INFO] CMake generating special *.h file from custom command magic."
)

在再次阅读cmake/3.13的文档后,很明显可以用更简单的形式编写它:

add_custom_target(
    timex_utilities_hash 
    ALL
    COMMAND cat ${BISON_HEADER} other_header.h | awk -f some_wak_file.awk > some_header.h
    DEPENDS ${BISON_HEADER}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

再次感谢您@Th。 Thielemann和@squareskittles为患者和inut再次检查!

相关问题