If I include non-existent files in DEPENDS
section of add_custom_command
, it fails. Is there a way to specify the dependency may not exist, but if it's created the command should be rerun?
Specifically, I am using Coco/R, which requires Parser.frame
and Scanner.frame
file to exist either in the same directory as the grammar file or one specified by a command line argument, and Copyright.frame
which can exist or not. So I do this:
foreach(FRAME_DIR IN ITEMS ${GRAMMAR_DIR} ${ARG_FRAME_DIR})
foreach(FRAME_FILE_NAME IN ITEMS Copyright Scanner Parser)
set(FULL_FRAME_FILE ${FRAME_DIR}/${FRAME_FILE_NAME}.frame)
if(EXISTS ${FULL_FRAME_FILE})
list(APPEND FRAME_FILES ${FULL_FRAME_FILE})
endif()
endforeach()
endforeach()
...
set(GEN_SOURCES ${ARG_OUTPUT_DIR}/Scanner.h ${ARG_OUTPUT_DIR}/Parser.h ${ARG_OUTPUT_DIR}/Scanner.cpp ${ARG_OUTPUT_DIR}/Parser.cpp)
add_custom_command(OUTPUT ${GEN_SOURCES}
COMMAND ${COCOCPP} ${COCOCPP_ARGS}
MAIN_DEPENDENCY ${ARG_GRAMMAR}
DEPENDS ${FRAME_FILES}
VERBATIM)
add_library(${ARG_TARGET} ${GEN_SOURCES})
If I comment out if
inside foreach
, I get
ninja: error: '../verification/debug/config/Copyright.frame', needed by 'verification/gen/config/Parser.h', missing and no known rule to make it
at build time. With this if
, the files are generated but if I create Copyright.frame
later, of course the build program will not know about it.