RPATH via LINK_OPTIONS or per default?

We have CMake code like this:

    set(link_flags "--disable-new-dtags,-rpath,\$ORIGIN/../lib")
    set_target_properties(${executable_name} PROPERTIES LINK_OPTIONS ${link_flags})

Is this needed? The CMake docs indicate that RPATHS are set by default anyway??

Does our code influence only the built or also the installed library?

You shouldn’t need to add -rpath flags directly. CMake has direct support for specifying RPATH details, and it has separate controls for binaries in the build tree versus binaries you install. See the BUILD_RPATH and INSTALL_RPATH target properties for details. You would normally use CMAKE_BUILD_RPATH and CMAKE_INSTALL_RPATH to set the details globally rather than on each individual target.

You may want to still keep the --disable-new-dtags flag though. That provides behavior that CMake doesn’t control.

1 Like