add_custom_command OUTPUT problem (absolute path + ninja generator)

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:

#############################################
# 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.

Can you publish a CMakeLists.txt showing the problem?

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.

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.

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.