# Custom command output location

**URL:** https://discourse.cmake.org/t/custom-command-output-location/2571
**Category:** Code
**Created:** [January 19, 2021, 1:35am UTC](https://discourse.cmake.org/t/custom-command-output-location/2571 "2021-01-19T01:35:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [January 19, 2021, 1:35am UTC](https://discourse.cmake.org/t/custom-command-output-location/2571/1 "2021-01-19T01:35:27Z")

</div>

When using a multi-config generator like Visual Studio, objects and libraries are (by default) placed in `${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>`. Now, suppose I have a library target, `myLib` and I want to process it with some script `${PROJECT_SOURCE_DIR}/tools/process.bat` and place its output next to `myLib`. I try:

```auto
add_custom_command(
    OUTPUT $<TARGET_FILE_DIR:myLib>/myLib.txt
    COMMAND ${PROJECT_SOURCE_DIR}/tools/process.bat $<TARGET_FILE:myLib> myLib.txt
    DEPENDS myLib
    WORKING_DIRECTORY $<TARGET_FILE_DIR:myLib>
    VERBATIM)

```

But then I get:

```auto
add_custom_command called with OUTPUT containing a "<". This character is not allowed.

```

How am I supposed to get per-configuration custom command outputs?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 19, 2021, 8:42am UTC](https://discourse.cmake.org/t/custom-command-output-location/2571/2 "2021-01-19T08:42:49Z")

</div>

> [@alex](#):
>
> How am I supposed to get per-configuration custom command outputs?

For some cases, you can use the variable [`CMAKE_CFG_INTDIR`](https://cmake.org/cmake/help/latest/variable/CMAKE_CFG_INTDIR.html) containing a buildtool-specific string which expands to the active configuration at build time.

For more complex cases, sometimes you have to bite the bullet and create a separate custom command for each configuration and then “assign” it to the appropriate configuration by other means (such as a config-conditional genex in the list of sources, or creating a custom target for each config, or …)

---

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [January 19, 2021, 7:16pm UTC](https://discourse.cmake.org/t/custom-command-output-location/2571/3 "2021-01-19T19:16:42Z")

</div>

Thank you, that worked for me!

I also saw that `OUTPUT` is getting support for generator expressions in 3.20, so that’s cool!

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 20, 2021, 8:35am UTC](https://discourse.cmake.org/t/custom-command-output-location/2571/4 "2021-01-20T08:35:39Z")

</div>

> [@alex](#):
>
> I also saw that `OUTPUT` is getting support for generator expressions in 3.20, so that’s cool!

That’s not just “cool”, that’s **absolutely fantastic!** , at least in my view. Thanks for letting me know. Oh, the number of workarounds I had to write around that one…

Now, I can just hope I will be given the time to reverse them all 🙂
