Package: cmake
Version: 3.31.6-2
Severity: normal
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).
________________________________________
# XXX CMake ignore les dépendances aux modules inclus, modifier ce fichier ne
relance pas la configuration...
# XXX Autre anomalie : bien que fichier et cible soient semble-t-il des espaces
de noms distincts, utiliser le nom de fichier produit par add_custom_command
comme nom de cible pour le add_custom_target correspondant bloque la génération
de la règle de génération. On contourne avec le préfixe dbk_ dans le noms de
cible.
find_program(XSLTPROC xsltproc DOC "Chemin du processeur XSLT 1" REQUIRED)
if (NOT TARGET manMANS)
add_custom_target(manMANS ALL)
endif()
if (NOT TARGET docDATA)
add_custom_target(docDATA ALL)
endif()
function(composer_DocBook_troff src)
add_custom_command(
OUTPUT "${src}.1"
COMMAND ${XSLTPROC} --xinclude --nonet --param make.year.ranges 1 --param
make.single.year.ranges 1 --param man.charmap.use.subset 0 --stringparam
man.base.url.for.relative.links "${CMAKE_INSTALL_FULL_DOCDIR}" -o ./
http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
${CMAKE_CURRENT_SOURCE_DIR}/${src}.dbk
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${src}.dbk
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Composition de ${src}.dbk en TROFF"
)
add_custom_target(dbk_${src}.1 ALL DEPENDS "${src}.1")
set_property(TARGET dbk_${src}.1 PROPERTY SOURCES "${src}.dbk")
add_dependencies(manMANS "dbk_${src}.1")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${src}.1" DESTINATION
${CMAKE_INSTALL_MANDIR}/man1)
endfunction()
function(composer_DocBook_XHTML src)
add_custom_command(
OUTPUT "${src}.xhtml"
COMMAND ${XSLTPROC} --xinclude --nonet -o ${src}.xhtml
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}_html.xsl
${CMAKE_CURRENT_SOURCE_DIR}/${src}.dbk
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${src}.dbk
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}_html.xsl
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Composition de ${src}.dbk en HTML")
add_custom_target(dbk_${src}.xhtml ALL DEPENDS "${src}.xhtml")
target_sources(dbk_${src}.xhtml PRIVATE "${src}.dbk"
"${PROJECT_NAME}_html.xsl")
add_dependencies(docDATA "dbk_${src}.xhtml")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${src}.xhtml" TYPE DOC)
endfunction()
macro(install_DocBook_CSS)
# XXX la commande suivante préserve les liens symboliques alors qu'il faut
plutôt copier le contenu
# pas de problème pour le make distcheck car make distdir fait une copie,
mais pour l'installation depuis le dossier source amont...
# le problème se pose pour "pour_DocBook.css".
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/docbook.css" pour_DocBook.css TYPE
DOC)
# On a besoin de cette feuille de style aussi dans le dossier de
construction, mais il ne faut pas faire la copie pour chaque document HTML.
endmacro()
________________________________________
-- System Information:
Debian Release: 13.4
APT prefers stable-updates
APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)
Kernel: Linux 6.12.85+deb13-amd64 (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages cmake depends on:
ii cmake-data 3.31.6-2
ii libarchive13t64 3.7.4-4
ii libc6 2.41-12+deb13u2
ii libcurl4t64 8.14.1-2+deb13u2
ii libexpat1 2.7.1-2
ii libgcc-s1 14.2.0-19
ii libjsoncpp26 1.9.6-3
ii librhash1 1.4.5-1
ii libstdc++6 14.2.0-19
ii libuv1t64 1.50.0-2
ii procps 2:4.0.4-9
ii zlib1g 1:1.3.dfsg+really1.3.1-1+b1
Versions of packages cmake recommends:
ii gcc 4:14.2.0-1
ii make 4.4.1-2
Versions of packages cmake suggests:
ii cmake-doc 3.31.6-2
pn cmake-format <none>
ii elpa-cmake-mode 4.0.1+ds-1
ii ninja-build 1.12.1-1
-- no debconf information