#1136017 cmake: confusion between filenames and target names

Package:
cmake
Source:
cmake
Description:
cross-platform, open-source make system
Submitter:
Christophe Delahaye
Date:
2026-05-08 14:15:02 UTC
Severity:
normal
#1136017#5
Date:
2026-05-08 14:12:32 UTC
From:
To:
Dear Maintainer,

Unlike make, cmake uses 2 distinct namespaces for targets and filenames, hence the existence of add_custom_target, which link target and files. The manual does not state whether one can use the same string both as a target name and as a filename. This would be convenient when one defines custom rules. But we can't.

Is the use of a given name both for a filename and the related target is allowed?
If yes, the bug is that at least one generation rule is missing in the generated Makefile.
If no, the bug is that cmake should reject the code without the workaround, and of course stating why it is invalid.

As an example, let us consider the following small module, which includes a workaround for the bug, that typesets DocBook man page to HTML and TROFF with the stylesheets from Norman Walsh.
Without the workaround, I use the name of the file created by the add_custom_command() also as the target name in add_custom_target(). But when I do that the make rule is NOT generated, none of the created Makefile include any rule that call the program xlstproc, one can find only a variable definition. So the corresponding target always fail and so the whole build.

As a workaround, I put a prefix on the filename to make the target name. So I get 2 distinct but predictable names.

This bug also applies to cmake 3.28 as found in Ubuntu 24.04 LTS (Noble).