For my project, I would like to run a command that generates the installed file (in other words, the generated file is just a data file, not the source code).
I currently have 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 since ALL is passed to add_custom_target() , the command is run every time make run.
Is there a way to change this so that the command runs only when the input file changes? A team may take some time, so ideally it will not be launched if it is not needed.
Thanks in advance!
source share