Skip to content

Commit 19640d1

Browse files
committed
[CMake] Add path to Fortran libraries to RPATH for h2root on macOS
So far, we have only solved this problem by adding the path to `DYLD_LIBRARY_PATH` when running the test, but this is not a complete solution, as the libraries won't be found automatically if this is not set. That affects in particular the users that want to use `h2root` from the install tree. Using the RPATH mechanism is more appropriate here.
1 parent 0aec11a commit 19640d1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

hist/hbook/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Hbook
3131
TreePlayer
3232
RIO
3333
)
34+
35+
# This is needed in particular for macOS, where the path of the GNU Fortran
36+
# library might not be in the default DYLD_LIBRARY_PATH, but it gets picked
37+
# up with enable_language(Fortran).
38+
if(APPLE AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
39+
# Compute path to quadmath
40+
execute_process(
41+
COMMAND ${CMAKE_Fortran_COMPILER} -print-file-name=libgfortran.dylib
42+
OUTPUT_VARIABLE LIBGFORTRAN_PATH
43+
OUTPUT_STRIP_TRAILING_WHITESPACE)
44+
get_filename_component(LIBGFORTRAN_DIR "${LIBGFORTRAN_PATH}" DIRECTORY)
45+
set_property(TARGET Hbook APPEND PROPERTY BUILD_RPATH "${LIBGFORTRAN_DIR}")
46+
set_property(TARGET Hbook APPEND PROPERTY INSTALL_RPATH "${LIBGFORTRAN_DIR}")
47+
endif()

main/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ if(fortran AND CMAKE_Fortran_COMPILER)
5555
ROOT_EXECUTABLE(g2root g2root.f LIBRARIES minicern CMAKENOEXPORT)
5656
set_target_properties(g2root PROPERTIES COMPILE_FLAGS "-w")
5757
ROOT_EXECUTABLE(h2root h2root.cxx LIBRARIES Core RIO Net Hist Graf Graf3d Gpad Tree Matrix MathCore Thread minicern CMAKENOEXPORT)
58+
59+
# This is needed in particular for macOS, where the path of the GNU Fortran
60+
# library might not be in the default DYLD_LIBRARY_PATH, but it gets picked
61+
# up with enable_language(Fortran).
62+
if(APPLE AND CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
63+
# Compute path to quadmath
64+
execute_process(
65+
COMMAND ${CMAKE_Fortran_COMPILER} -print-file-name=libgfortran.dylib
66+
OUTPUT_VARIABLE LIBGFORTRAN_PATH
67+
OUTPUT_STRIP_TRAILING_WHITESPACE)
68+
get_filename_component(LIBGFORTRAN_DIR "${LIBGFORTRAN_PATH}" DIRECTORY)
69+
set_property(TARGET h2root APPEND PROPERTY BUILD_RPATH "${LIBGFORTRAN_DIR}")
70+
set_property(TARGET h2root APPEND PROPERTY INSTALL_RPATH "${LIBGFORTRAN_DIR}")
71+
endif()
5872
endif()
5973

6074
file(GLOB utils RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} python/root*)

0 commit comments

Comments
 (0)