# Question: wrong syntax with add\_custom\_command but cmake runs without errors?

**URL:** https://discourse.cmake.org/t/question-wrong-syntax-with-add-custom-command-but-cmake-runs-without-errors/9174
**Category:** Usage
**Created:** [October 11, 2023, 11:41am UTC](https://discourse.cmake.org/t/question-wrong-syntax-with-add-custom-command-but-cmake-runs-without-errors/9174 "2023-10-11T11:41:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![berthin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/berthin/32/3902_2.png) [@berthin](https://discourse.cmake.org/u/berthin)
#### Post date: [October 11, 2023, 11:41am UTC](https://discourse.cmake.org/t/question-wrong-syntax-with-add-custom-command-but-cmake-runs-without-errors/9174/1 "2023-10-11T11:41:55Z")

</div>

Hi,

According to the documentation, the syntax for `add_custom_command` is:

```auto
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:

```auto
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?

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [October 11, 2023, 4:03pm UTC](https://discourse.cmake.org/t/question-wrong-syntax-with-add-custom-command-but-cmake-runs-without-errors/9174/2 "2023-10-11T16:03:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 11, 2023, 4:05pm UTC](https://discourse.cmake.org/t/question-wrong-syntax-with-add-custom-command-but-cmake-runs-without-errors/9174/3 "2023-10-11T16:05:37Z")

</div>

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