Search code examples
cmakelinkerdynamic-libraryrpath

How to set CMAKE_INSTALL_RPATH with multiple directories?


On the question CMAKE RPATH not working - could not find shared object file I see how to set CMAKE_INSTALL_RPATH for a single path, but I need it for multiple paths. I tried these using but I did not worked:

SET( CMAKE_INSTALL_RPATH "/opt/my/lib;/other/lib" )
SET( CMAKE_INSTALL_RPATH "/opt/my/lib:/other/lib" )

On the question How to set multiple RPATH directories using CMake on MacOS I see I can set multiple paths with semicolon ; for a target, but I would like to set it for all targets instead of setting it for each one. Is there a equivalent of set_target_properties for all targets (including subprojects) ? For example:

set_target_properties(alltargets
    PROPERTIES
    INSTALL_RPATH "/opt/my/lib;/other/lib"
)

Solution

  • Snippet:

    # note: macOS is APPLE and also UNIX !
    if(APPLE)
      set_target_properties(foo PROPERTIES
        INSTALL_RPATH "@loader_path;@loader_path/...")
    elseif(UNIX)
      set_target_properties(foo PROPERTIES
        INSTALL_RPATH "$ORIGIN:$ORIGIN/...")
    endif()
    

    Related CMake variable:

    Related CMP: