[CMake] CPack DEB depends bug fix

Jess Morecroft jess.morecroft at gmail.com
Tue May 15 16:19:48 EDT 2012


Hi all,

I experienced problems recently trying to use the CPack DEB packager
with components and wanted to share my solution (thanks partly to Eric
Noulard). The problem was with dependency generation in the Debian
control file using the CPACK_DEBIAN_PACKAGE_SHLIBS flag. Dependencies
would be generated, however each component would be incorrectly
assigned all previously processed components' dependencies on top of
its own. This would occur regardless of whether the user explicitly
set any (additional) dependencies via CPACK_DEBIAN_PACKAGE_DEPENDS.

eg. 3 components,
   1 has dependencies A, B, C, 3
   2 has dependencies D, E, F, 3
   3 has dependencies G
relevant config:
set(CPACK_COMPONENTS_IGNORE_GROUPS TRUE)
set(CPACK_DEB_COMPONENT_INSTALL TRUE)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)

We have no way of expressing dependencies between components for the
purposes of Debian packaging (so far as I know) so 1 and 2 depending
on 3 is not achievable. That aside, if processed 1 then 2, then 3, the
resultant package 1 would depend on A, B, C, package 2 (incorrectly)
on A, B, C, D, E, F and package 3 (incorrectly) on A, B, C, D, E, F,
G.

To fix I patched the CPackDeb.cmake script as follows, introducing new
per-component user-defined dependency variable
CPACK_DEB_<component>_PACKAGE_DEPENDS, which should be used over
CPACK_DEBIAN_PACKAGE_DEPENDS if components are being used.

214,218c214,226
<     IF (CPACK_DEBIAN_PACKAGE_DEPENDS)
<       SET (CPACK_DEBIAN_PACKAGE_DEPENDS
"${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS},
${CPACK_DEBIAN_PACKAGE_DEPENDS}")
<     ELSE (CPACK_DEBIAN_PACKAGE_DEPENDS)
<       SET (CPACK_DEBIAN_PACKAGE_DEPENDS
"${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
<     ENDIF (CPACK_DEBIAN_PACKAGE_DEPENDS)
---
>     IF(CPACK_DEB_PACKAGE_COMPONENT)
>       IF (CPACK_DEB_${CPACK_DEB_PACKAGE_COMPONENT}_PACKAGE_DEPENDS)
>         SET (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEB_${CPACK_DEB_PACKAGE_COMPONENT}_PACKAGE_DEPENDS}")
>       ELSE (CPACK_DEB_${CPACK_DEB_PACKAGE_COMPONENT}_PACKAGE_DEPENDS)
>         SET (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
>       ENDIF (CPACK_DEB_${CPACK_DEB_PACKAGE_COMPONENT}_PACKAGE_DEPENDS)
>     ELSE (CPACK_DEB_PACKAGE_COMPONENT)
>       IF (CPACK_DEBIAN_PACKAGE_DEPENDS)
>         SET (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}")
>       ELSE (CPACK_DEBIAN_PACKAGE_DEPENDS)
>         SET (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}")
>       ENDIF (CPACK_DEBIAN_PACKAGE_DEPENDS)
>     ENDIF (CPACK_DEB_PACKAGE_COMPONENT)

This config then will do the trick, also allowing 1 and 2's dependency
on 3 to be expressed:

set(CPACK_COMPONENTS_IGNORE_GROUPS TRUE)
set(CPACK_DEB_COMPONENT_INSTALL TRUE)
set(CPACK_DEB_1_PACKAGE_DEPENDS "myproject-3")
set(CPACK_DEB_2_PACKAGE_DEPENDS "myproject-3")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS TRUE)

I shall submit a bug report with advised patch in the next few days.

Incidentally, I did stumble across another "bug" with the Debian
packager unable to deal with components not containing any exe or lib
files. Fortunately my final project layout avoided this scenario, but
you've been warned!

Regards,
Jess


More information about the CMake mailing list