# With multiple configurations, is it possible to add\_custom\_command as a final step?

**URL:** https://discourse.cmake.org/t/with-multiple-configurations-is-it-possible-to-add-custom-command-as-a-final-step/2704
**Category:** Code
**Tags:** gen:ninja
**Created:** [February 5, 2021, 3:26pm UTC](https://discourse.cmake.org/t/with-multiple-configurations-is-it-possible-to-add-custom-command-as-a-final-step/2704 "2021-02-05T15:26:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![jice73](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jice73/32/111_2.png) [@jice73](https://discourse.cmake.org/u/jice73)
#### Post date: [February 5, 2021, 3:26pm UTC](https://discourse.cmake.org/t/with-multiple-configurations-is-it-possible-to-add-custom-command-as-a-final-step/2704/1 "2021-02-05T15:26:25Z")

</div>

This is on a build box, where the generator is `"Ninja Multi-Config"`, and `-DCMAKE_CONFIGURATION_TYPES="Release;Debug" -DCMAKE_DEFAULT_CONFIGS=all`. After the project is built (it has multiple libraries), I want to run a custom command to tar up a couple directories (that contain Debug and Release artifacts).

In the CMakeLists.txt of the last library built (renamed to LastTargetBuilt for this example), I currently have:

> add\_custom\_command(TARGET LastTargetBuilt POST\_BUILD  
> COMMAND ${CMAKE\_COMMAND} -E tar “cf” “${CMAKE\_BINARY\_DIR}/${ZIP\_FILENAME}” --format=zip – “\*”  
> WORKING\_DIRECTORY ${CMAKE\_BINARY\_DIR}/dist  
> COMMENT “Creating archive ${CMAKE\_BINARY\_DIR}/${ZIP\_FILENAME}.”  
> )

However, in the generated .zip, I am only seeing a single library built by the Debug (the second in the list of configuration types), where I see all the Release libraries.

I also tried:

> add\_custom\_command(OUTPUT ${CMAKE\_BINARY\_DIR}/${ZIP\_FILENAME}  
> COMMAND ${CMAKE\_COMMAND} -E tar “cf” “${CMAKE\_BINARY\_DIR}/${ZIP\_FILENAME}” --format=zip – “\*”  
> DEPENDS LastTargetBuilt  
> WORKING\_DIRECTORY ${CMAKE\_BINARY\_DIR}/dist  
> COMMENT “Creating archive ${CMAKE\_BINARY\_DIR}/${ZIP\_FILENAME}.”  
> )
> 
> add\_custom\_target(ArchiveProject ALL  
> ${CMAKE\_BINARY\_DIR}/${ZIP\_FILENAME}  
> )

And this does not generate an archive at all.

---

<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 5, 2021, 7:57pm UTC](https://discourse.cmake.org/t/with-multiple-configurations-is-it-possible-to-add-custom-command-as-a-final-step/2704/2 "2021-02-05T19:57:22Z")

</div>

When attaching to `LastTargetBuilt`, that is actually a per-configuration thing because that target exists independently in each configuration. I don’t know if there’s a vetted way of doing this in multi-config generators at all at the moment.

Cc: @brad.king @kyle.edwards
