CPackRPM incorrectly sets DESTDIR for the pre-installation step (2023.06.21.)
This issue started out its life under: https://discourse.cmake.org/t/cpackrpm-installing-unnecessary-files But by now I'm pretty sure that there's an issue in the CMake code, so it seems better to put this into a ticket.
The back-story of how I came across this issue is a bit complicated. But the simplest reproducer that I could come up with for the issue is the following:
# Set up the project.
cmake_minimum_required(VERSION 3.10)
project(CPackWithExternalProject VERSION 1.0.0 LANGUAGES C)
# CMake include(s).
include(CPack)
include(ExternalProject)
# Build GoogleTest as an external package.
ExternalProject_Add(Eigen
INSTALL_DIR "${CMAKE_BINARY_DIR}/eigen"
URL "https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz"
URL_MD5 "9e30f67e8531477de4117506fe44669b"
CMAKE_CACHE_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_TESTING:BOOL=FALSE
-DEIGEN_BUILD_DOC:BOOL=FALSE
-DEIGEN_TEST_NOQT:BOOL=TRUE)
When I build it with the "normal" configure->build->package chain of commands, I correctly get an empty RPM file.
Singularity> cmake ../source/
-- The C compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /cvmfs/sft.cern.ch/lcg/releases/gcc/11.2.0-8a51a/x86_64-centos7/bin/gcc - skipped
...
Singularity> make
[ 12%] Creating directories for 'Eigen'
[ 25%] Performing download step (download, verify and extract) for 'Eigen'
-- Downloading...
dst='/srv/build/Eigen-prefix/src/eigen-3.3.7.tar.gz'
timeout='none'
...
[100%] Completed 'Eigen'
[100%] Built target Eigen
Singularity> cpack -G RPM
CPack: Create package using RPM
CPack: Install projects
CPack: - Run preinstall target for: CPackWithExternalProject
CPack: - Install project: CPackWithExternalProject []
CPack: Create package
CPackRPM: Will use GENERATED spec file: /srv/build/_CPack_Packages/Linux/RPM/SPECS/cpackwithexternalproject.spec
CPack: - package: /srv/build/CPackWithExternalProject-1.0.0-Linux.rpm generated.
Singularity> ls -l CPackWithExternalProject-1.0.0-Linux.rpm
-rw-rw-r-- 1 krasznaa krasznaa 1812 Jun 20 20:19 CPackWithExternalProject-1.0.0-Linux.rpm
Singularity>
But if I try to do a not-completelt-standard configure->package series of commands, I get the following:
Singularity> cmake ../source/
-- The C compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /cvmfs/sft.cern.ch/lcg/releases/gcc/11.2.0-8a51a/x86_64-centos7/bin/gcc - skipped
...
-- Configuring done
-- Generating done
-- Build files have been written to: /srv/build
Singularity> cpack -G RPM
CPack: Create package using RPM
CPack: Install projects
CPack: - Run preinstall target for: CPackWithExternalProject
CPack: - Install project: CPackWithExternalProject []
CPack: Create package
CMake Warning (dev) at /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Cmake/3.24.3/Linux-x86_64/share/cmake-3.24/Modules/Internal/CPack/CPackRPM.cmake:188 (message):
CPackRPM:Warning: Path /srv/build/eigen/include/eigen3/Eigen/Cholesky is
not on one of the relocatable paths! Package will be partially relocatable.
Call Stack (most recent call first):
/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Cmake/3.24.3/Linux-x86_64/share/cmake-3.24/Modules/Internal/CPack/CPackRPM.cmake:1056 (cpack_rpm_prepare_relocation_paths)
/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Cmake/3.24.3/Linux-x86_64/share/cmake-3.24/Modules/Internal/CPack/CPackRPM.cmake:1968 (cpack_rpm_generate_package)
This warning is for project developers. Use -Wno-dev to suppress it.
...
CMake Warning (dev) at /cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Cmake/3.24.3/Linux-x86_64/share/cmake-3.24/Modules/Internal/CPack/CPackRPM.cmake:188 (message):
CPackRPM:Warning: Path /srv/build/eigen/share/pkgconfig/eigen3.pc is not on
one of the relocatable paths! Package will be partially relocatable.
Call Stack (most recent call first):
/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Cmake/3.24.3/Linux-x86_64/share/cmake-3.24/Modules/Internal/CPack/CPackRPM.cmake:1056 (cpack_rpm_prepare_relocation_paths)
/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/Cmake/3.24.3/Linux-x86_64/share/cmake-3.24/Modules/Internal/CPack/CPackRPM.cmake:1968 (cpack_rpm_generate_package)
This warning is for project developers. Use -Wno-dev to suppress it.
CPackRPM: Will use GENERATED spec file: /srv/build/_CPack_Packages/Linux/RPM/SPECS/cpackwithexternalproject.spec
CPack: - package: /srv/build/CPackWithExternalProject-1.0.0-Linux.rpm generated.
Singularity> ls -l CPackWithExternalProject-1.0.0-Linux.rpm
-rw-rw-r-- 1 krasznaa krasznaa 1014476 Jun 20 20:22 CPackWithExternalProject-1.0.0-Linux.rpm
Singularity>
In this case a whole lot of unwanted files end up in the RPM file. Files that were meant to end up in ${CMAKE_BINARY_DIR}/eigen
, but because $DESTDIR
is set by CPackRPM for the preinstall step, they rather end up in the directory that the RPM is built out of.
Note that I don't see anything like this when generating TGZ packages. Even when using
if( "${CPACK_GENERATOR}" STREQUAL "TGZ" )
# CPACK_SET_DESTDIR is necessary for the TGZ generator when using the custom
# cpack_install.sh.in script, but must not be set for the RPM generator.
set( CPACK_SET_DESTDIR TRUE )
endif()
inside of CPACK_PROJECT_CONFIG_FILE. So I have a very strong suspicion that the source of all of these issues is in:
https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.4/Source/CPack/cmCPackRPMGenerator.cxx#L26-28