Question: wrong syntax with add_custom_command but cmake runs without errors?

Hi,

According to the documentation, the syntax for add_custom_command is:

add_custom_command(OUTPUT output1 [output2 ...]
                   COMMAND command1 [ARGS] [args1...]
                   [COMMAND command2 [ARGS] [args2...] ...]
                   [MAIN_DEPENDENCY depend]
                   [DEPENDS [depends...]]
                   [BYPRODUCTS [files...]]
                   [IMPLICIT_DEPENDS <lang1> depend1
                                    [<lang2> depend2] ...]
                   [WORKING_DIRECTORY dir]
                   [COMMENT comment]
                   [DEPFILE depfile]
                   [JOB_POOL job_pool]
                   [VERBATIM] [APPEND] [USES_TERMINAL]
                   [COMMAND_EXPAND_LISTS]
                   [DEPENDS_EXPLICIT_ONLY])add_custom_command(OUTPUT output1 [output2 ...]
                   COMMAND command1 [ARGS] [args1...]
                   [COMMAND command2 [ARGS] [args2...] ...]
                   [MAIN_DEPENDENCY depend]
                   [DEPENDS [depends...]]
                   [BYPRODUCTS [files...]]
                   [IMPLICIT_DEPENDS <lang1> depend1
                                    [<lang2> depend2] ...]
                   [WORKING_DIRECTORY dir]
                   [COMMENT comment]
                   [DEPFILE depfile]
                   [JOB_POOL job_pool]
                   [VERBATIM] [APPEND] [USES_TERMINAL]
                   [COMMAND_EXPAND_LISTS]
                   [DEPENDS_EXPLICIT_ONLY])

but I am wondering how does the following work:

add_custom_command(
    OUTPUT ${DOXYGEN_INDEX_FILE}
    DEPENDS ${HEADER_FILES}
    COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
    MAIN_DEPENDENCY ${DOXYFILE_OUT} ${DOXYFILE_IN}
    COMMENT "Generating documentation"
)

considering that MAIN_DEPENDENCY receives only one argument, “${DOXYGEN_IN}” isn’t matched to any of the “add_custom_command” attributes, correct?

Correct, the ${DOXYFILE_IN} is most likely wrongly placed in that custom command.
I guess the ${DOXYFILE_IN} is a template of the doxyfile, which has been filled out to create ${DOXYFILE_OUT}. Maybe there is a configure_file which does that. So it does not need to be added at all to that custom_command because CMake is recalled if that file changes.

1 Like

The implementation is an older parser. It parses multiple, but only the last one is actually stored. Fixing it would involve a new policy.

1 Like