# Installing a symlink with a relative path for RPM

**URL:** https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895
**Category:** Usage
**Created:** [April 1, 2020, 12:32am UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895 "2020-04-01T00:32:12Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![atn34](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@atn34](https://discourse.cmake.org/u/atn34)
#### Post date: [April 1, 2020, 12:32am UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895/1 "2020-04-01T00:32:12Z")

</div>

```auto
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
set(CPACK_PACKAGING_INSTALL_PREFIX "/")
execute_process(COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/foo)
install(FILES ${CMAKE_BINARY_DIR}/foo DESTINATION usr/bin)
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../bin/foo ${CMAKE_BINARY_DIR}/bar)
install(FILES ${CMAKE_BINARY_DIR}/bar DESTINATION usr/lib)
include(CPack)

# $ mkdir build && cd build && cmake .. && make && cpack -G RPM && rpm2cpio *.rpm | cpio -dimv && ls -al usr/lib/bar
# ...
# ... usr/lib/bar -> /usr/bin/foo

# I expected a relative symlink, usr/lib/bar -> ../bin/foo
$ cmake --version
cmake3 version 3.14.6

CMake suite maintained and supported by Kitware (kitware.com/cmake).

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 1, 2020, 4:57am UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895/2 "2020-04-01T04:57:14Z")

</div>

Is it a valid relative symlink in the install destdir under `_CPack_Packages` as well or just in the RPM?

---

<div class="post-metadata">

### Author: ![atn34](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@atn34](https://discourse.cmake.org/u/atn34)
#### Post date: [April 1, 2020, 4:45pm UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895/3 "2020-04-01T16:45:58Z")

</div>

For RPM, the symlink is absolute under \_CPack\_Packages. What’s weird is that for TGZ the symlink is relative.

```auto
$ tree -a
...
── _CPack_Packages
│ └── Linux
│ ├── RPM
│ │ ├── BUILD
│ │ ├── BUILDROOT
│ │ ├── Project-0.1.1-Linux
│ │ │ └── usr
│ │ │ ├── bin
│ │ │ │ └── foo
│ │ │ └── lib
│ │ │ └── bar -> /usr/bin/foo
│ │ ├── rpmbuildproject.err
│ │ ├── rpmbuildproject.out
│ │ ├── RPMS
│ │ │ └── Project-0.1.1-Linux.rpm
│ │ ├── SOURCES
│ │ ├── SPECS
│ │ │ ├── project.spec
│ │ │ └── project.spec.in
│ │ ├── SRPMS
│ │ └── tmp
│ └── TGZ
│ ├── Project-0.1.1-Linux
│ │ └── usr
│ │ ├── bin
│ │ │ └── foo
│ │ └── lib
│ │ └── bar -> ../bin/foo
│ └── Project-0.1.1-Linux.tar.gz

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 1, 2020, 5:10pm UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895/4 "2020-04-01T17:10:16Z")

</div>

Hmm. Tracing where that resolution is happening would be really nice. I wonder if `rpmbuild` is making it absolute somehow? `cmake_install.cmake` doesn’t differ between the two I think, so it’d have to be the other step which is converting it somewhere. Does `CPACK_RPM_PACKAGE_RELOCATABLE` make a difference?

---

<div class="post-metadata">

### Author: ![atn34](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/2acd7d/32.png) [@atn34](https://discourse.cmake.org/u/atn34)
#### Post date: [April 1, 2020, 5:28pm UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895/5 "2020-04-01T17:28:41Z")

</div>

I tried cpack with --trace-expand, it appears that CPackRPM.cmake is creating the absolute symlink:

```auto
/usr/share/cmake3/Modules/Internal/CPack/CPackRPM.cmake(537): execute_process(COMMAND /usr/bin/cmake3 -E create_symlink /usr/bin/foo /home/anoyes/tmp/build/_CPack_Packages/Linux/RPM/Project-0.1.1-Linux//usr/lib/bar )

```

`CPACK_RPM_PACKAGE_RELOCATABLE` does not make a difference

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 1, 2020, 5:55pm UTC](https://discourse.cmake.org/t/installing-a-symlink-with-a-relative-path-for-rpm/895/6 "2020-04-01T17:55:57Z")

</div>

That sounds like an issue to me. Though I don’t know who’s maintaining CPackRPM lately.
