CPack and rpm specfile packages

Hi,

I have a big RPM spec file for a project that I would like to use with CPack. I can change things in that file if needed. This specfile contains several %package tags I would like to keep. I tried to use CPack with those packages but failed. To simplify my issue, I wrote a little project with a little specfile containing two packages:

The project builds a program with a shared library:
/usr/bin/test
/usr/lib64/liblll.so

and I would like to get two rpm files, one test-test.rpm and another test-lll.rpm

In my CMakeLists.txt, I set those two lines:
install(TARGETS test COMPONENT test DESTINATION β€œ${CMAKE_INSTALL_BINDIR}”)
install(TARGETS lll COMPONENT lll DESTINATION β€œ${CMAKE_INSTALL_LIBDIR}”)

The idea is to have one component for one package.

In the specfile, I defined
%package test and also %package lll with

%files test
%{_bindir}/test

%files lll
%{libdir}/liblll.so

My CMakeCPack.cmake file contains:

set(CPACK_PACKAGE_NAME β€œ${PROJECT_NAME}”)

set(CPACK_COMPONENTS_ALL test lll)
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

set(CPACK_GENERATOR RPM)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_USER_BINARY_SPECFILE β€œ${CMAKE_SOURCE_DIR}/test.spec”)

After a β€œmake package”: I get a tree that looks like:

_CPack_Packages/Linux/RPM/test-0.1.1-Linux/
β”œβ”€β”€ lll
β”‚ └── usr
β”‚ └── lib64
β”‚ └── liblll.so
└── test
└── usr
└── bin
└── test

But I cannot get my two rpm files.
CPackRPM is complaining about /usr/bin/test that does not exist in lll or usr/lib64/liblll.so that does not exist in test.

Since I specified %files for each one, I don’t understand this error. What am I doing wrong?

Regards, thank you
David.

David,

Not an expert by any means, but I have mostly wrangled CPack into submission for my project.

I can’t say this is right or not, but I install my targets in the β€œnormal” places:

install(TARGETS test COMPONENT test DESTINATION bin)
install(TARGETS lll COMPONENT lll DESTINATION lib64)

In my RPM, we install in /opt, so I also add

# Since we are putting things in /etc and /opt, don't make this package relocatable
set(CPACK_PACKAGE_RELOCATABLE OFF)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "/opt/foo")
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/foo")

You might also want to assert that this is a binary (not source) RPM. I don’t know how/if this interacts with specifying the binary spec file

set(CPACK_BINARY_RPM "ON")

I haven’t used my own specfile; I rather found that things are a bit easier if I let CPack do what it wants to do. When I do need to exert some control,

set(CPACK_RPM_FILE_NAME RPM-DEFAULT)

# Control the %files section
set(CPACK_RPM_USER_FILELIST
        "%config(noreplace) /etc/opt/foo/foo.cfg"
        "%config /etc/systemd/system/foo.service"
        )
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
        /opt
        /etc/opt
        /etc/systemd /etc/systemd/system
        /usr/lib/python /usr/lib/python2.7 /usr/lib/python2.7/site-packages
        )

Everything else is pretty automagic.

1 Like

Hi Jim,

Thank you very much for your suggestions. It is not exactly what I was thinking about but looks very interesting.
I’ll give it a try.