CMake 3.17.5 cmake_policy(SET CMP0095 NEW) not working

Hi All,

In our project, the main CMakeLists.txt has the below two lines at the very beginning -
cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0095 NEW)

Also, we are setting CMAKE_INSTALL_RPATH

set(CMAKE_INSTALL_RPATH “${ORIGIN}”)

the cmake_install.cmake file has the below lines:
file(RPATH_CHANGE
FILE “${file}”
OLD_RPATH “lib::::”
NEW_RPATH “$ORIGIN”)

The final shared library that gets built also has the escape '' character

The escaping '' does not help. Can anyone help in understanding as to how we can have only “${ORIGIN}” without the ''

Does this work?

set(CMAKE_INSTALL_RPATH “\${ORIGIN}”)

hey @ben.boeckel - thank you so much for a quick reply and apologies from me for being late in responding.

I did try your suggestion - but i still do not see the desired behaviour.

[root@d_server my_project_dir]# grep ORIGIN CMakeLists.txt
set(CMAKE_INSTALL_RPATH “${ORIGIN};${ORIGIN}/…/…/”)
[root@d_server my_project_dir]# readelf -d /path/to/mylibrary.so | grep -i rpath
0x000000000000000f (RPATH) Library rpath: [:/…/…/]
[root@d_server pbspro_dev_oss]#

Thanks,
Prakash

You need to escape the $ so that it doesn’t get expanded as a CMake variable (probably undefined, so therefore empty).

Hi Ben,

I have added the escape character “\” in my message and CMakeLists.txt - but it is not working.

Thanks,
Prakash

This should be:

set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/…/…)

Note the removal of the {}. The $ORIGIN is meant for the linker to interpret, it is not substituted by CMake.

The linker supports both ${ORIGIN} and $ORIGIN.

I know some runtime loaders support ${ORIGIN}, but I’m not sure if that is universally supported on all unix systems where $ORIGIN is supported. It is very rare to see ${ORIGIN} used, the only place I’ve seen it mentioned is in the ld.so man page on Linux.

thank you @craig.scott and @ben.boeckel - using $ORIGIN (without the {}) works for me.

[root@d_server pbspro_dev_oss]# readelf -d /path/to/mylib.so.0.0.0 | grep -i rpath
0x000000000000000f (RPATH) Library rpath: [$ORIGIN:$ORIGIN/…/lib/:$ORIGIN/…/…/]
[root@d_server pbspro_dev_oss]# grep -i rpath CMakeLists.txt
set(CMAKE_INSTALL_RPATH “$ORIGIN;$ORIGIN/…/lib/;$ORIGIN/…/…/”)
[root@d_server pbspro_dev_oss]#