# add\_custom\_command OUTPUT problem (absolute path + ninja generator)

**URL:** <https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727>\
**Category:** Code\
**Created:** [December 22, 2021, 1:07pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727 "2021-12-22T13:07:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mbee](https://discourse.cmake.org/u/mbee)\
**Post date:** [December 22, 2021, 1:07pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727/1 "2021-12-22T13:07:51Z")

</div>

I’m creating custom commands with outputs, defined as:

`C:/Projects/git/_obj/XXXX/gccarm/$<IF:$<CONFIG:RelWithDebInfo>,Release,$<CONFIG>>/BoardMix.hex`

This triggers the following ninja error:

`ninja : error : FindFirstFileExA(boardmix.hex ...): The filename, directory name, or volume label syntax is incorrect.`

It seems, that it cannot find `BoardMix.hex` (but converts the name to lowercase). The generated `build.ninja` contains:

```auto
#############################################
# Custom command for CMakeFiles\XXXX_leaf_gccarm

build CMakeFiles/XXXX_leaf_gccarm | ${cmake_ninja_workdir}CMakeFiles/XXXX_leaf_gccarm: CUSTOM_COMMAND BoardMix.hex$ ...

```

I’m no expert in build.ninja’s syntax, but it seems, that the generator replaces my absolute path by an invalid relative one.

The documentation to add\_custom\_command also mentions restrictions when using genexps in OUTPUT. But 1) it seems to be related to target-specific ones and 2) in my case the genexp forms only a part of the whole output path, so it should not be cut off completely.

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [December 22, 2021, 1:36pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727/2 "2021-12-22T13:36:33Z")

</div>

Can you publish a `CMakeLists.txt` showing the problem?

---

<div class="post-metadata">

**Author:** ![mbee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mbee](https://discourse.cmake.org/u/mbee)\
**Post date:** [December 22, 2021, 4:12pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727/3 "2021-12-22T16:12:54Z")

</div>

Up to now, I wasn’t able to reduce the problem to something minimalistic.The custom commands and targets are generated in code from complex transformations of variables in a whole hierarchy of cmake projects.

---

<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:** [December 23, 2021, 12:08pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727/4 "2021-12-23T12:08:59Z")

</div>

Unfortunately, without more detail it’s hard to recommend anything specific. Things I would look for:

- where does the filename first show up as lowercase?
- have you tried using absolute paths everywhere?
- have you tried removing some of the genex complexity to rule errors in their usage?
- are slashes uses consistently?

That’s what comes to mind right now at least.

---

<div class="post-metadata">

**Author:** ![mbee](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mbee](https://discourse.cmake.org/u/mbee)\
**Post date:** [December 23, 2021, 7:38pm UTC](https://discourse.cmake.org/t/add-custom-command-output-problem-absolute-path-ninja-generator/4727/5 "2021-12-23T19:38:48Z")

</div>

PIFOM (problem in front of monitor):

As I said, I create custom commands/targets programmatically. To do this, I need to precompute the dependencies for both by recording the respective mix of files and targets in cmake lists. For some reason, I thought that these lists had to be converted to some string with spaces as separators (I even handled the spaces inside the paths without thinking twice). This is wrong, of course, since DEPENDS simply expects the arguments to be a cmake list. Debug messages look quite innocent, of course.  
The hard part was that the error occurred after configuration and before build (during build system generation) and was hard to nail down.

Sorry for bothering you all.
