Set relative INSTALL_RPATH on shared libceres Abseil sets INSTALL_RPATH to @loader_path on Apple and $ORIGIN on other Unix systems for all of its shared libraries so they can find sibling libraries in the same install directory. libceres is installed into the same directory and links privately against Abseil (and potentially other co-installed shared libraries), but did not set INSTALL_RPATH. On Linux, DT_RUNPATH on a downstream executable is not transitive, so running a binary against a non-system install prefix failed to find libabsl_*.so. On macOS, installed consumers or dlopen callers face the same issue. Append @loader_path on Apple and $ORIGIN on other Unix systems to ceres's INSTALL_RPATH when BUILD_SHARED_LIBS is enabled. Using APPEND preserves any user-specified CMAKE_INSTALL_RPATH, and packagers using CMAKE_SKIP_INSTALL_RPATH=ON remain unaffected. Change-Id: I9336b63f14fada7db883f0aa5bf3955a8bae8941
diff --git a/internal/ceres/CMakeLists.txt b/internal/ceres/CMakeLists.txt index 543417e..03150e3 100644 --- a/internal/ceres/CMakeLists.txt +++ b/internal/ceres/CMakeLists.txt
@@ -304,6 +304,17 @@ VERSION ${CERES_VERSION} SOVERSION 4) +if (BUILD_SHARED_LIBS) + # Allow installed shared libceres to locate co-installed shared dependencies + # (such as bundled libabsl_*) in the same directory without requiring + # LD_LIBRARY_PATH or DYLD_LIBRARY_PATH, matching Abseil's own INSTALL_RPATH. + if (APPLE) + set_property(TARGET ceres APPEND PROPERTY INSTALL_RPATH "@loader_path") + elseif (UNIX) + set_property(TARGET ceres APPEND PROPERTY INSTALL_RPATH "$ORIGIN") + endif () +endif () + target_link_libraries(ceres PUBLIC ${CERES_LIBRARY_PUBLIC_DEPENDENCIES} PRIVATE ${CERES_LIBRARY_PRIVATE_DEPENDENCIES})