Friday, May 6, 2022

[SOLVED] CPack adds system directories to generated RPM

Issue

I have a CMake project and I use CPack to generate RPMs for my CentOS YUM repository. However, when I attempt to install my generated RPM, I get this error:

file /usr from install of clstrd-0.1.0-1.x86_64 conflicts with file from package filesystem-3.2-20.el7.x86_64
file /usr/bin from install of clstrd-0.1.0-1.x86_64 conflicts with file from package filesystem-3.2-20.el7.x86_64
file /usr/lib from install of clstrd-0.1.0-1.x86_64 conflicts with file from package filesystem-3.2-20.el7.x86_64

Further inspecting the RPM's contents, I see that it includes these files and directories:

$ rpm -qlp clstrd-0.1.0-Linux.rpm
/usr
/usr/bin
/usr/bin/clstrd
/usr/lib
/usr/lib/libclstrd.a

My question is: How do I force CMake to exclude common directories like /usr or /usr/bin from the RPM? Shouldn't this be done automatically?

I have tried CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION with no luck.

Edit: Here are the relevant parts of my CMakeLists.txt

# Targets
add_library(clstrd_lib ${SOURCE_FILES})
...
add_executable(clstrd main.cpp)
target_link_libraries(clstrd clstrd_lib)
...
# Installation configuration.
install(TARGETS clstrd_lib clstrd
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin)

# CPack configuration.
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyAwesomePackage")
set(CPACK_PACKAGE_VENDOR "MyAwesomeVendor")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "1")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
set(CPACK_PACKAGE_EXECUTABLES "clstrd", "MyAwesomeExecutable")
set(CPACK_RPM_PACKAGE_AUTOREQPROV " no")
set(CPACK_RPM_PACKAGE_REQUIRES, "libpqxx, gtest, gflags, root,     root-netx, xrootd-client-libs")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION, "/usr /usr/bin /usr/lib")
set(CPACK_SOURCE_GENERATOR "RPM")
include(CPack)

Solution

It seems this was a bug in cmake 2.8.9, which was fixed in cmake 2.8.12:

https://public.kitware.com/Bug/view.php?id=13609



Answered By - Chris Maes
Answer Checked By - Willingham (WPSolving Volunteer)