@@ -973,8 +973,15 @@ function(ROOT_LINKER_LIBRARY library)
973
973
endforeach ()
974
974
endif ()
975
975
976
+ if (rpath )
977
+ ROOT_APPEND_LIBDIR_TO_BUILD_RPATH (${library} )
978
+ endif ()
979
+
976
980
#----Installation details-------------------------------------------------------
977
981
if (NOT ARG_TEST AND NOT ARG_NOINSTALL AND CMAKE_LIBRARY_OUTPUT_DIRECTORY )
982
+ if (rpath )
983
+ ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH (${library} ${CMAKE_INSTALL_LIBDIR} )
984
+ endif ()
978
985
if (ARG_CMAKENOEXPORT )
979
986
install (TARGETS ${library} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT libraries
980
987
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries
@@ -1435,8 +1442,16 @@ function(ROOT_EXECUTABLE executable)
1435
1442
set_property (TARGET ${executable}
1436
1443
APPEND PROPERTY LINK_LIBRARIES ROOT::ROOTStaticSanitizerConfig )
1437
1444
endif ()
1445
+
1446
+ if (rpath )
1447
+ ROOT_APPEND_LIBDIR_TO_BUILD_RPATH (${executable} )
1448
+ endif ()
1449
+
1438
1450
#----Installation details------------------------------------------------------
1439
1451
if (NOT ARG_NOINSTALL AND CMAKE_RUNTIME_OUTPUT_DIRECTORY )
1452
+ if (rpath )
1453
+ ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH (${executable} ${CMAKE_INSTALL_BINDIR} )
1454
+ endif ()
1440
1455
if (ARG_CMAKENOEXPORT )
1441
1456
install (TARGETS ${executable} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications )
1442
1457
else ()
@@ -2073,6 +2088,82 @@ function(generateManual name input output)
2073
2088
install (FILES ${output} DESTINATION ${CMAKE_INSTALL_MANDIR} /man1 )
2074
2089
endfunction ()
2075
2090
2091
+ #----------------------------------------------------------------------------
2092
+ # --- ROOT_APPEND_LIBDIR_TO_BUILD_RPATH(target)
2093
+ # Sets the BUILD_RPATH for a given target so that it can find the ROOT shared
2094
+ # libraries at runtime. The RPATH is set relative to the target's own location
2095
+ # using $ORIGIN (or @loader_path on macOS).
2096
+ #
2097
+ # Arguments:
2098
+ # target - The CMake target (e.g., a shared library or executable)
2099
+ #----------------------------------------------------------------------------
2100
+ function (ROOT_APPEND_LIBDIR_TO_BUILD_RPATH target )
2101
+ get_target_property (target_type ${target} TYPE )
2102
+
2103
+ if (target_type STREQUAL "EXECUTABLE" )
2104
+ get_target_property (output_dir ${target} RUNTIME_OUTPUT_DIRECTORY )
2105
+ elseif (target_type STREQUAL "STATIC_LIBRARY" )
2106
+ get_target_property (output_dir ${target} ARCHIVE_OUTPUT_DIRECTORY )
2107
+ elseif (target_type STREQUAL "SHARED_LIBRARY" )
2108
+ get_target_property (output_dir ${target} LIBRARY_OUTPUT_DIRECTORY )
2109
+ else ()
2110
+ message (FATAL_ERROR "${target} is of type ${target_type} , which is not supported by ROOT_APPEND_LIBDIR_TO_BUILD_RPATH" )
2111
+ endif ()
2112
+
2113
+ # If the output directory propert was not set, the output will default to the
2114
+ # current binary directory.
2115
+ if (output_dir STREQUAL "output_dir-NOTFOUND" )
2116
+ get_target_property (output_dir ${target} BINARY_DIR )
2117
+ endif ()
2118
+
2119
+ # Figure out the output directory of the main ROOT libraries. We can't use
2120
+ # any variables like CMAKE_LIBRARY_OUTPUT_DIRECTORY for this, because the
2121
+ # ROOT CMake code temporarily changes them in some cases (e.g. in roottest).
2122
+ get_target_property (main_libdir Core LIBRARY_OUTPUT_DIRECTORY )
2123
+
2124
+ file (RELATIVE_PATH to_libdir "${output_dir} " "${main_libdir} " )
2125
+
2126
+ # New path
2127
+ if (APPLE )
2128
+ set (new_rpath "@loader_path/${to_libdir} " )
2129
+ else ()
2130
+ set (new_rpath "$ORIGIN/${to_libdir} " )
2131
+ endif ()
2132
+
2133
+ # Append to existing RPATH
2134
+ get_target_property (existing_rpath ${target} BUILD_RPATH )
2135
+ list (APPEND existing_rpath "${new_rpath} " )
2136
+ set_target_properties (${target} PROPERTIES BUILD_RPATH "${existing_rpath} " )
2137
+ endfunction ()
2138
+
2139
+ #----------------------------------------------------------------------------
2140
+ # --- ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH(target install_dir)
2141
+ #
2142
+ # Sets the INSTALL_RPATH for a given target so that it can find the ROOT shared
2143
+ # libraries at runtime. The RPATH is set relative to the target's own location
2144
+ # using $ORIGIN (or @loader_path on macOS).
2145
+ #
2146
+ # Arguments:
2147
+ # target - The CMake target (e.g., a shared library or executable)
2148
+ # install_dir - The install subdirectory relative to CMAKE_INSTALL_PREFIX
2149
+ #----------------------------------------------------------------------------
2150
+ function (ROOT_APPEND_LIBDIR_TO_INSTALL_RPATH target install_dir )
2151
+ file (RELATIVE_PATH to_libdir "${CMAKE_INSTALL_PREFIX} /${install_dir} " "${CMAKE_INSTALL_FULL_LIBDIR} " )
2152
+
2153
+ # New path
2154
+ if (APPLE )
2155
+ set (new_rpath "@loader_path/${to_libdir} " )
2156
+ else ()
2157
+ set (new_rpath "$ORIGIN/${to_libdir} " )
2158
+ endif ()
2159
+
2160
+ # Append to existing RPATH
2161
+ get_target_property (existing_rpath ${target} INSTALL_RPATH )
2162
+ list (APPEND existing_rpath "${new_rpath} " )
2163
+ set_target_properties (${target} PROPERTIES INSTALL_RPATH "${existing_rpath} " )
2164
+ endfunction ()
2165
+
2166
+
2076
2167
#-------------------------------------------------------------------------------
2077
2168
#
2078
2169
# Former RoottestMacros.cmake starts here
0 commit comments