[CMake] CPack: Create debian packge for each sub-project

Domen Vrankar domen.vrankar at gmail.com
Mon Dec 4 19:13:29 EST 2017


2017-12-04 20:35 GMT+01:00 DKLind <davidklind at gmail.com>:

> Domen Vrankar wrote
> > I'm a bit confused. Is there something missing in the patch?
> > Attached patch only adds per component version override - it doesn't even
> > touch the multiple calls to `include(CPack)` and naming of different
> > packages (not their components but different package names).
> >
> > Could you please provide a simple example of the intended use for
> > packaging
> > of multiple packages with multiple sub-packages?
>
> I have a macro that each sub-project calls. See package macro below.
>
> Each sub project calls CMake install for it's various pieces (.so, .conf,
> init.d, etc.) then:
>     For a simple library package:
>     package(${PROJECT_NAME}
>         ${LIBRARY_VERSION}
>         "My library description"
>     )
>
>     For a daemon package:
>     package(${PROJECT_NAME}
>         ${DAEMONX_VERSION}
>         "My daemonx description"
>         ${CMAKE_SOURCE_DIR}/daemonx/debian/DEBIAN/conffiles;
>         ${CMAKE_SOURCE_DIR}/daemonx/debian/DEBIAN/postinst;
>         ${CMAKE_SOURCE_DIR}/daemonx/debian/DEBIAN/postrm;
>         ${CMAKE_SOURCE_DIR}/daemonx/debian/DEBIAN/prerm
>     )
>
> The last thing the top level CMakeLists.txt does is:
>     string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
>     if(${CMAKE_BUILD_TYPE} STREQUAL release)
>         set(CPACK_STRIP_FILES TRUE)
>     endif()
>
>     string(REGEX REPLACE "([0-9]+).*$" "\\1" BUILD_MAJOR_VERSION
> ${BUILD_VERSION})
>     string(REGEX REPLACE "[0-9]+\\.([0-9]+).*$" "\\1" BUILD_MINOR_VERSION
> ${BUILD_VERSION})
>     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1"
> BUILD_PATCH_VERSION ${BUILD_VERSION})
>
>     set(CPACK_GENERATOR DEB)
>     set(CPACK_PACKAGE_VERSION_MAJOR ${BUILD_MAJOR_VERSION})
>     set(CPACK_PACKAGE_VERSION_MINOR ${BUILD_MINOR_VERSION})
>     set(CPACK_PACKAGE_VERSION_PATCH ${BUILD_PATCH_VERSION})
>     set(CPACK_PACKAGE_VERSION ${BUILD_VERSION})
>     set(CPACK_DEBIAN_PACKAGE_MAINTAINER "maintainer <maintainer at xyx.com>")
>     set(CPACK_PACKAGE_VENDOR xyz)
>
>     set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
>
>     set(CPACK_DEB_COMPONENT_INSTALL TRUE)
>     set(CPACK_DEB_PACKAGE_COMPONENT TRUE)
>
>
> In the macro, CPACK_DEBIAN_${TARGET}_PACKAGE_VERSION works because of the
> patch.
>
>
> macro(package target version description)
>     string(TOUPPER ${target} TARGET)
>
>     string(REGEX REPLACE "([0-9]+).*$" "\\1" BUILD_MAJOR_VERSION
> ${version})
>     string(REGEX REPLACE "[0-9]+\\.([0-9]+).*$" "\\1" BUILD_MINOR_VERSION
> ${version})
>     string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1"
> BUILD_PATCH_VERSION ${version})
>
>     set(CPACK_DEBIAN_${TARGET}_PACKAGE_NAME ${target} CACHE STRING
> "package
> ${target}")
>     set(CPACK_DEBIAN_${TARGET}_PACKAGE_VERSION ${version} CACHE STRING
> "package ${target}")
>     set(CPACK_DEBIAN_${TARGET}_PACKAGE_SECTION main CACHE STRING "package
> ${target}")
>     set(CPACK_DEBIAN_${TARGET}_PACKAGE_PRIORITY standard CACHE STRING
> "package ${target}")
>     set(CPACK_DEBIAN_${TARGET}_PACKAGE_ARCHITECTURE
> ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "package ${target}")
>     set(CPACK_COMPONENT_${TARGET}_DESCRIPTION ${description} CACHE STRING
> "package ${target}")
>     set(CPACK_DEBIAN_${TARGET}_PACKAGE_CONTROL_EXTRA ${ARGN} CACHE STRING
> "package ${target}")
>
>     set(CPACK_DEBIAN_${TARGET}_FILE_NAME
> ${target}_${version}_${CMAKE_PACKAGE_PLATFORM}.deb CACHE STRING "package
> ${target}")
> endmacro()
>

Try using this on CPackRPM with debuginfo packages or rpm default naming
convention enabled (with this second part it's the same with CPackDeb
apckages) - these are just two parts that you break that immediately come
to mind.
Now you have to rename every package by hand, require a non standard macro
just to set things up, you forfeit instead of gain automation (e.g. auto
component deduction from install commands, package naming...). And you
still cant override all the variables (e.g. maintainer).

While this might be enough for your use case and CPackDeb it wouldn't play
nice with all CPackRPM features so it would cause them to diverge even
further.

I'm still not convinced that it's worth it.

Regards,
Domen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171205/e8b19780/attachment.html>


More information about the CMake mailing list