For my project, I'd like to run a command which generates a file that is installed (in other words, the generated file is just a data file, not source code).
I currently have the following in my CMakeLists.txt
add_custom_command(
OUTPUT outputfile.txt
COMMAND dosomething ${CMAKE_CURRENT_SOURCE_DIR}/inputfile.txt
${CMAKE_CURRENT_BINARY_DIR}/output.txt
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/inputfile.txt
)
add_custom_target(
run_gen_command
ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/output.txt
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/output.txt
DESTINATION ${CMAKE_INSTALL_DATADIR}/somewhere
)
This works fine, but because ALL is passed to add_custom_target(), the command gets executed every time I run make.
Is there any way I could change this so that the command is only run when the input file is changed? The command may take a while to complete, so ideally, it wouldn't be run unless it needed to.
Thanks in advance!
OUTPUT outputfile.txtmay beOUTPUT output.txt?dosomethingdepends oninputfile.txtand generatesoutput.txt, thusoutput.txtis only re-generated ifinputfile.txthas changed. Is this not the case? Or did I miss something.