# add\_custom\_custom multiple output and multiple directories.

**URL:** https://discourse.cmake.org/t/add-custom-custom-multiple-output-and-multiple-directories/15474
**Category:** Usage
**Created:** [January 22, 2026, 11:10pm UTC](https://discourse.cmake.org/t/add-custom-custom-multiple-output-and-multiple-directories/15474 "2026-01-22T23:10:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pcanal](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pcanal/32/5413_2.png) [@pcanal](https://discourse.cmake.org/u/pcanal)
#### Post date: [January 22, 2026, 11:10pm UTC](https://discourse.cmake.org/t/add-custom-custom-multiple-output-and-multiple-directories/15474/1 "2026-01-22T23:10:10Z")

</div>

Hi,

We have a situation where for each libraries of our project we need to call an executable that generates:

- a source file that is compiled and included in the library
- an auxiliary `pcm` file (similar to a C++ precompile module files)

As input to each invocation of the executable we have

- The header files of the library and a steering file
- The generated `pcm` files corresponding all the libraries the ‘current’ library depends on.

To do so we use something like:

```auto
add_custom_command(
   OUTPUT dict${modulename}.cxx ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${modulename}.pcm
   COMMAND ${generator} ${generator_args}
   IMPLICIT_DEPENDS
      CXX ${full_path_to_header_1}
      CXX ${full_path_to_header_2}
      etc ...
   DEPENDS
      ${full_path_to_header_1}
      ${full_path_to_header_2}
      etc ...
      ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${dependent_modulename_a}.pcm
      ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${dependent_modulename_b}.pcm
      etc ...
)

```

This has two majors problems:

1. With `Ninja` support `IMPLICIT_DEPENDS` is (not yet?) implemented and thus the command is not re-run if one of the indirect header file inclusion is changed
2. With `Unix Makefiles` `IMPLICIT_DEPENDS` work as intended for the header file depedencies  
_ **BUT** _ it does not properly support the dependencies on the secondary `OUTPUT` of the `add_custom_command` (the `pcm` files).

The exact mechanism of the odd behavior in 2. is described at [https://gitlab.kitware.com/cmake/cmake/-/issues/27521](https://gitlab.kitware.com/cmake/cmake/-/issues/27521) ( [GitHub - pcanal/cmake\_custom\_command: Demonstrate a potential issue in cmake\_custom\_command](https://github.com/pcanal/cmake_custom_command) ). In the issue @craig.scott mentions that this is not surprising as the documentation hints that ‘cross directory’ dependencies involving the `add_custom_command` is not really supported and instead of the `pcm` files the downstream custom command should be depending on the whole dependent library. This solution feels a bit odd (as the library is not an actual input to the custom command) and may increase (a bit) the serialization of the build process (now each generation step needs to wait until the full libraries it depends on are built instead of ‘just’ waiting for the corresponding generation steps). In the issue, I mention a fix to the files produced by `Unix Makefiles` generator to enhance the support `IMPLICIT_DEPENDS` to work correctly in the case I have.

So two questions:

1. Would there be any objections to change proposed in the issue ? (i.e. I would prepare a patch implementing the suggestion if that is helpful).

2. Is there a way to emulate the support for `IMPLICIT_DEPENDS` with the Ninja generator (and/or is support for it planned)?

Thanks,  
Philippe

---

<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: [February 9, 2026, 2:42am UTC](https://discourse.cmake.org/t/add-custom-custom-multiple-output-and-multiple-directories/15474/2 "2026-02-09T02:42:25Z")

</div>

Skip `IMPLICIT_DEPENDS`. It is hacky and inaccurate anyways. Instead, teach the generator to write a `DEPFILE` and use that to communicate the dependencies. See [this MR](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10624) for adding support to VTK’s code generators.

`DEPFILE` is supported by every generator AFAIK.

---

<div class="post-metadata">

### Author: ![pcanal](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pcanal/32/5413_2.png) [@pcanal](https://discourse.cmake.org/u/pcanal)
#### Post date: [February 9, 2026, 12:46pm UTC](https://discourse.cmake.org/t/add-custom-custom-multiple-output-and-multiple-directories/15474/3 "2026-02-09T12:46:10Z")

</div>

Thanks.
