# Custom path at the end of RPATH

**URL:** <https://discourse.cmake.org/t/custom-path-at-the-end-of-rpath/7080>\
**Category:** Code\
**Created:** [December 15, 2022, 1:16pm UTC](https://discourse.cmake.org/t/custom-path-at-the-end-of-rpath/7080 "2022-12-15T13:16:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gzauhar](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/g/7c8e57/32.png) [@gzauhar](https://discourse.cmake.org/u/gzauhar)\
**Post date:** [December 15, 2022, 1:16pm UTC](https://discourse.cmake.org/t/custom-path-at-the-end-of-rpath/7080/1 "2022-12-15T13:16:49Z")

</div>

Hi there!

I kindly ask assistance with RPATH control in CMake. I would like to add custom path **at the end of RPATH in every executable** which gets produced (e.g. unittest executables) at build time (e.g. _make_ and not install time e.g. _make install_).

This simple example demonstrates my wish:

```auto
cmake_minimum_required(VERSION 3.25)
project(rpath)

# This will place "/foo/bar" at the front of RPATH but I need it at the end
set(CUSTOM_RPATH_VAR "/foo/bar")
set(CMAKE_BUILD_RPATH ${CUSTOM_RPATH_VAR})

find_package(Qt5 5.15 COMPONENTS Core REQUIRED)

file(WRITE "main.c" "int main() { return 0; }")

add_executable(test1 main.c)
target_link_libraries(test1 Qt5::Core)

add_executable(test2 main.c)
target_link_libraries(test2 Qt5::Core)

```

After compilation RPATH of generated executables, as expected, looks like this:

```auto
$ chrpath -l test1
test1: RUNPATH=/foo/bar:/opt/Qt5.15.5/lib

```

What can I do to put my custom path at the end of RPATH via CMake? What options do I have?

Thank you so much,  
Goran

---

<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:** [December 15, 2022, 2:26pm UTC](https://discourse.cmake.org/t/custom-path-at-the-end-of-rpath/7080/2 "2022-12-15T14:26:43Z")

</div>

I don’t think there’s a mechanism for rpath ordering yet. Probably worth a [feature request](https://gitlab.kitware.com/cmake/cmake/-/issues) (or searching for an existing one).
