# CPack and rpm specfile packages

**URL:** https://discourse.cmake.org/t/cpack-and-rpm-specfile-packages/1379
**Category:** Usage
**Created:** [June 12, 2020, 4:03pm UTC](https://discourse.cmake.org/t/cpack-and-rpm-specfile-packages/1379 "2020-06-12T16:03:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Boucher](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@David\_Boucher](https://discourse.cmake.org/u/David_Boucher)
#### Post date: [June 12, 2020, 4:03pm UTC](https://discourse.cmake.org/t/cpack-and-rpm-specfile-packages/1379/1 "2020-06-12T16:03:58Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jwm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jwm/32/654_2.png) [@jwm](https://discourse.cmake.org/u/jwm)
#### Post date: [June 12, 2020, 8:08pm UTC](https://discourse.cmake.org/t/cpack-and-rpm-specfile-packages/1379/2 "2020-06-12T20:08:25Z")

</div>

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:

```cmake
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

```cmake
# 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

```cmake
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,

```cmake
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.

---

<div class="post-metadata">

### Author: ![bouda1](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bouda1/32/684_2.png) [@bouda1](https://discourse.cmake.org/u/bouda1)
#### Post date: [June 17, 2020, 6:39pm UTC](https://discourse.cmake.org/t/cpack-and-rpm-specfile-packages/1379/3 "2020-06-17T18:39:45Z")

</div>

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.
