cmakedependenciesrpmdebcpack

Is there a similiar function to %global __requires_exclude_from in cpack for rpm / deb?


We made the transition from regular spec files (for rpm) to cpack and also added .deb packages to our build.

I was able to replicate everything we had in our rpm spec files, besides __requires_exclude_from. We have a file that requires an optional lib. (the included binary is optional and only called when the user wants to) but the resulting rpm / deb package requires the dependency nonetheless.

In the RPM spec, we excluded this specific binary completely from dependency scanning which worked great, but i'm not able to reproduce this in cpack for RPM and DEB generators.

The only way i could image is to create / use my own spec files as template, but i'm not really sure if i want to do this, as this seems to defeat the whole purpose of cpack...

Does anyone know if it's possible to exclude a single file from depdenency scanning?


Solution

  • Looking through the CPackRPM.cmake file it seems this functionality is not available yet in CPack.

    I made a short diff (untested), which should help you for your immediate problem.

    --- C:\Program Files\CMake\share\cmake-3.15\Modules\Internal\CPack\CPackRPM - Kopie.cmake   2019-09-04 09:59:20.000000000 +0200
    +++ C:\Program Files\CMake\share\cmake-3.15\Modules\Internal\CPack\CPackRPM.cmake   2020-07-17 11:57:19.000000000 +0200
    @@ -1094,12 +1094,22 @@
         if(CPACK_RPM_PACKAGE_DEBUG)
           message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}")
         endif()
         set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}")
       endif()
     
    +  # CPACK_RPM_REQUIRES_EXCLUDE_FROM
    +  # May be defined to keep the dependency generator from
    +  # scanning specific files or directories for deps.
    +  if(CPACK_RPM_REQUIRES_EXCLUDE_FROM)
    +    if(CPACK_RPM_PACKAGE_DEBUG)
    +      message("CPackRPM:Debug: User defined CPACK_RPM_REQUIRES_EXCLUDE_FROM = ${CPACK_RPM_REQUIRES_EXCLUDE_FROM}")
    +    endif()
    +    set(TMP_RPM_REQUIRES_EXCLUDE_FROM "%global __requires_exclude_from ${CPACK_RPM_REQUIRES_EXCLUDE_FROM}")
    +  endif()
    +
       # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_INSTALL_SCRIPT_FILE)
       # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM_<COMPONENT>_POST_UNINSTALL_SCRIPT_FILE)
       # May be used to embed a post (un)installation script in the spec file.
       # The referred script file(s) will be read and directly
       # put after the %post or %postun section
       # ----------------------------------------------------------------
    @@ -1574,12 +1584,13 @@
     
     %define _rpmdir %_topdir/RPMS
     %define _srcrpmdir %_topdir/SRPMS
     \@FILE_NAME_DEFINE\@
     %define _unpackaged_files_terminate_build 0
     \@TMP_RPM_SPEC_INSTALL_POST\@
    +\@TMP_RPM_REQUIRES_EXCLUDE_FROM\@
     \@CPACK_RPM_SPEC_MORE_DEFINE\@
     \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
     
     %description
     \@CPACK_RPM_PACKAGE_DESCRIPTION\@
     
    @@ -1696,12 +1707,13 @@
     
     %define _rpmdir %_topdir/RPMS
     %define _srcrpmdir %_topdir/SRPMS
     \@FILE_NAME_DEFINE\@
     %define _unpackaged_files_terminate_build 0
     \@TMP_RPM_SPEC_INSTALL_POST\@
    +\@TMP_RPM_REQUIRES_EXCLUDE_FROM\@
     \@CPACK_RPM_SPEC_MORE_DEFINE\@
     \@CPACK_RPM_COMPRESSION_TYPE_TMP\@
     
     %description
     \@CPACK_RPM_PACKAGE_DESCRIPTION\@
     
    
    

    Hope it helps and suit your needs.