自定义命令不会在 cmake 中使用 --target 选项执行
Custom command does not get executed with --target option in cmake
此问题的后续问题:
我编写了一个自定义目标,所以每次我在我的项目中编译某些东西时它都会 运行。现在我按照上面的问题调用了一个显式目标,这个自定义命令不再执行。
代码:
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
指令,但没有任何改变。
忘记补充:我使用的是cmake/3.13.4
从源代码编译的
抱歉后来的回答,但工作太疯狂了。因此,在我阅读了@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 再次检查!
此问题的后续问题:
我编写了一个自定义目标,所以每次我在我的项目中编译某些东西时它都会 运行。现在我按照上面的问题调用了一个显式目标,这个自定义命令不再执行。 代码:
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
指令,但没有任何改变。
忘记补充:我使用的是cmake/3.13.4
从源代码编译的
抱歉后来的回答,但工作太疯狂了。因此,在我阅读了@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 再次检查!