如何获取cmake在实际构建/链接后创建时间戳文件? (如果可执行没有改变,什么都不做) [英] How to get cmake to create timestamp file after an actual build/link? (do nothing if executable hasn't changed)
问题描述
我想要调用 date +%s>三个可执行文件
c $ c> myapp_sim ,我生成(即只创建时间戳,如果相应的可执行文件创建)。 myapp_data
, myapp_live
和<$三个可执行文件中的每一个都有$ {TIMESTAMP}
找出为什么我的自定义命令没有被执行,即使我删除二进制文件和重新链接。生成工作正常 - 只有时间戳生成无效。
MACRO(MY_APP TAG)
SET(BINARY_TGT myapp _ $ {TAG})
SET(TIMESTAMPTIMESTAMP _ $ {TAG})
ADD_EXECUTABLE($ {BINARY_TGT} $ {APP_SRCS})
ADD_CUSTOM_COMMAND b OUTPUT $ {TIMESTAMP}
COMMAND date
ARGS + \%s\> $ {TIMESTAMP}
DEPENDS $ {BINARY_TGT}
)
ENDMACRO(MY_APP)
SUBDIRS(data)
SUBDIRS(live)
SUBDIRS(sim)
在数据目录中,我有:
FILE(GLOB APP_SRCS RELATIVE $ { CMAKE_CURRENT_SOURCE_DIR} main_data.cpp)
SET(MY_TAG资料)
MY_APP($ {MY_TAG})
解决方案CMake不运行独立的自定义命令,除非某些东西取决于他们的输出。一个选项是将自定义命令更改为后构建:
add_custom_command(
TARGET $ {BINARY_TGT}
POST_BUILD
COMMAND日期+ \%s\> $ {TIMESTAMP}
VERBATIM
)
另一个选项是添加自定义目标来驱动自定义命令。一个目标对于所有自定义命令都是足够的。
add_custom_target(
GenerateTimestamps ALL
DEPENDS $ {yourListOfTimestampFiles}
)
确定重定向是否会按预期工作。当在shell /命令提示符下键入
>
时,它不是程序的参数,而是shell /命令处理器的指令。如果它不工作(我从来没有测试过),你必须将date
的调用放到脚本中。I would like to invoke
date +"%s" > ${TIMESTAMP}
for each of the three executables,myapp_data
,myapp_live
andmyapp_sim
that I generate (ie only create the timestamp if the respective executables are created).I can't seem to figure out why my custom command isn't being executed even after I remove the binaries and relink. Build works fine - only the timestamp generation doesn't work.
MACRO( MY_APP TAG ) SET( BINARY_TGT "myapp_${TAG}" ) SET( TIMESTAMP "TIMESTAMP_${TAG}" ) ADD_EXECUTABLE( ${BINARY_TGT} ${APP_SRCS} ) ADD_CUSTOM_COMMAND( OUTPUT ${TIMESTAMP} COMMAND date ARGS +\"%s\" > ${TIMESTAMP} DEPENDS ${BINARY_TGT} ) ENDMACRO( MY_APP ) SUBDIRS( data ) SUBDIRS( live ) SUBDIRS( sim )
Inside the data dir, I have:
FILE(GLOB APP_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} main_data.cpp) SET( MY_TAG data ) MY_APP( "${MY_TAG}" )
解决方案CMake does not run self-standing custom commands unless something depends on their output. One option is to change the custom command to a post-build:
add_custom_command( TARGET ${BINARY_TGT} POST_BUILD COMMAND date +\"%s\" > ${TIMESTAMP} VERBATIM )
The other option is to add a custom target to drive the custom command(s). One target is sufficient for all custom commands.
add_custom_target( GenerateTimestamps ALL DEPENDS ${yourListOfTimestampFiles} )
However, I am not sure if the redirecting will work as you expect. When you type
>
in a shell/command prompt, it's not an argument to the program, but an instruction to the shell/command processor. If it doesn't work (I've never tested), you'll have to put the invocation ofdate
into a script.这篇关于如何获取cmake在实际构建/链接后创建时间戳文件? (如果可执行没有改变,什么都不做)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!