# RPATH handling in the wiki -- bug?

**URL:** <https://discourse.cmake.org/t/rpath-handling-in-the-wiki-bug/6155>\
**Category:** Code\
**Created:** [July 27, 2022, 6:01am UTC](https://discourse.cmake.org/t/rpath-handling-in-the-wiki-bug/6155 "2022-07-27T06:01:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jirislaby](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jirislaby/32/2624_2.png) [@jirislaby](https://discourse.cmake.org/u/jirislaby)\
**Post date:** [July 27, 2022, 6:01am UTC](https://discourse.cmake.org/t/rpath-handling-in-the-wiki-bug/6155/1 "2022-07-27T06:01:44Z")

</div>

During debugging of this issue in stp’s cmake:

> <https://github.com/stp/stp/issues/437#issuecomment-1195340167>
>
> openSUSE build system defines:
> \`\`\`
> -DCMAKE\_INSTALL\_PREFIX:PATH=%{\_prefix}
> -…DCMAKE\_INSTALL\_LIBDIR:PATH=%{\_lib}
> \`\`\`
> where:
> \`\`\`
> $ rpm -E '%{\_prefix} XX %{\_lib}'
> /usr XX lib64
> \`\`\`
> I.e. \`CMAKE\_INSTALL\_LIBDIR\` is relative. Which is perfectly fine -- in fact https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html says:
> 
> \> It should typically be a path \*\*relative\*\* to the installation prefix so that it can be converted to an absolute path in a relocatable way (see CMAKE\_INSTALL\_FULL\_&lt;dir&gt;). However, an absolute path is also allowed.
> 
> So this test doesn't work properly:
> https://github.com/stp/stp/blob/e8d153f196dcdf609add70e867f2188d58ffcc97/CMakeLists.txt#L191-L194
> 
> and rpath is set to "lib64". If you used \`GNUInstallDirs\`, you could use \`CMAKE\_INSTALL\_FULL\_LIBDIR\` in the test above. I don't know how to solve it without \`GNUInstallDirs\`.
> 
> BTW. minisat has exactly the same problem:
> https://github.com/stp/minisat/blob/37158a35c62d448b3feccfa83006266e12e5acb7/CMakeLists.txt#L86

We’ve come back to:  
[https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath)

I don’t understand this part there:

```cmake
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
...
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
    set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")

```

What’s the purpose of the whole `if` given `CMAKE_INSTALL_RPATH` is set to `${CMAKE_INSTALL_PREFIX}/lib` above unconditionally?

---

<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:** [August 2, 2022, 11:16am UTC](https://discourse.cmake.org/t/rpath-handling-in-the-wiki-bug/6155/2 "2022-08-02T11:16:49Z")

</div>

I agree that it does look odd at least. I’d have to dig in more to figure out what it’s trying to do to figure it out myself though. It _seems_ like it’s trying to make sure that the destination is in the rpath set, but only if it isn’t already a system location.
