<NME> tropter_install_mac_dependency_libraries.cmake.in
<BEF> # Temporary hack to package dependencies on Macs.

set(libdir "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")
message(STATUS "Editing RPATH of tropter dependency libraries")

macro(install_name_tool_change lib dep_name dep_oldpath)
    execute_process(COMMAND install_name_tool
            -change ${dep_oldpath}/lib${dep_name}.dylib
            @rpath/lib${dep_name}.dylib
            "${libdir}/lib${lib}.dylib")
endmacro()

macro(install_name_tool_change_gfortran lib)
    execute_process(COMMAND bash "-c"
        "otool -L ${libdir}/lib${lib}.dylib | grep 'libgfortran.*version' | perl -pe 's/^\\s+(.*)\\/libg.*/\\1/gc'"
        OUTPUT_VARIABLE libgfortran_dir
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process(COMMAND bash "-c"
        "otool -L ${libdir}/lib${lib}.dylib | grep 'libgfortran.*version' | perl -pe 's/.*lib(.*).dylib.*/\\1/gc'"
        OUTPUT_VARIABLE libgfortran_name
        OUTPUT_STRIP_TRAILING_WHITESPACE)
    install_name_tool_change(${lib} "${libgfortran_name}" "${libgfortran_dir}")
endmacro()

macro(install_name_tool_change_quadmath lib)
execute_process(COMMAND bash "-c"
    "otool -L ${libdir}/lib${lib}.dylib | grep 'libquadmath' | perl -pe 's/^\\s+(.*)\\/libq.*/\\1/gc'"
    OUTPUT_VARIABLE libquadmath_dir
    OUTPUT_STRIP_TRAILING_WHITESPACE)

execute_process(COMMAND bash "-c"
    "otool -L ${libdir}/lib${lib}.dylib | grep 'libquadmath' | perl -pe 's/.*lib(.*).dylib.*/\\1/gc'"
    OUTPUT_VARIABLE libquadmath_name
    OUTPUT_STRIP_TRAILING_WHITESPACE)
    install_name_tool_change(${lib} "${libquadmath_name}" "${libquadmath_dir}")
endmacro()

macro(install_name_tool_id lib)
    execute_process(COMMAND install_name_tool
            -id @rpath/lib${lib}.dylib
            "${libdir}/lib${lib}.dylib")
endmacro()

macro(install_name_tool_add_rpath lib)
    execute_process(COMMAND install_name_tool
            -add_rpath "@loader_path/"
            "${libdir}/lib${lib}.dylib")
endmacro()

macro(install_name_tool_delete_rpath lib rpath)
    execute_process(COMMAND install_name_tool
            -delete_rpath ${rpath}
            "${libdir}/lib${lib}.dylib")
endmacro()

# Get the directory containing libgcc_s.1.dylib.
# otool: Get the list of dependencies of gfortran, which includes libgcc_s.
# grep: Isolate the line containing libgcc.
# perl: Extract only the directory, without the filename.
#    ^\\s+     matches all spaces at the start of the string.
#   (.*)       matches everything up to libgcc, and captures it as match gorup #1
#   \\/libg.*  matches the rest of the line.
#   \\1        replaces the contents of the entire match with match group #1
execute_process(COMMAND bash "-c"
    "otool -L ${libdir}/libgfortran.dylib | grep 'libgcc' | perl -pe 's/^\\s+(.*)\\/libg.*/\\1/gc'"
    OUTPUT_VARIABLE libgcc_dir
    OUTPUT_STRIP_TRAILING_WHITESPACE)

# tropter
install_name_tool_change(tropter adolc.2 "@ADOLC_DIR@/lib64")
install_name_tool_change(tropter ipopt.1 "@IPOPT_LIBDIR@")
install_name_tool_change(tropter coinmumps.1 "@IPOPT_LIBDIR@")
install_name_tool_change(tropter coinmetis.1 "@IPOPT_LIBDIR@")
install_name_tool_change_gfortran(tropter)
install_name_tool_change_quadmath(tropter)
install_name_tool_add_rpath(tropter)

# adol-c
install_name_tool_id(adolc.2)
# install_name_tool_change(adolc.2 boost_system /usr/local/opt/boost/lib)
# install_name_tool_change(adolc.2 ColPack.0 /usr/local/opt/colpack/lib)
install_name_tool_add_rpath(adolc.2)
install_name_tool_delete_rpath(adolc.2 "@ColPack_ROOT_DIR@/lib")

# ipopt
install_name_tool_id(ipopt.1)
install_name_tool_change(ipopt.1 coinmumps.1 "@IPOPT_LIBDIR@")
install_name_tool_change(ipopt.1 coinmetis.1 "@IPOPT_LIBDIR@")
install_name_tool_change_gfortran(ipopt.1)
install_name_tool_change_quadmath(ipopt.1)

# coinmumps
install_name_tool_id(coinmumps.1)
install_name_tool_change(coinmumps.1 coinmetis.1 "@IPOPT_LIBDIR@")
install_name_tool_change_gfortran(coinmumps.1)
install_name_tool_change(coinmumps.1 gcc_s.1 "${libgcc_dir}")
install_name_tool_change_quadmath(coinmumps.1)
install_name_tool_add_rpath(coinmumps.1)

# coinmetis
install_name_tool_id(coinmetis.1)
install_name_tool_add_rpath(coinmetis.1)

# boost_system
# install_name_tool_id(boost_system)

# Colpack.0
# install_name_tool_id(ColPack.0)

# gfortran
install_name_tool_id(gfortran)
install_name_tool_change(gfortran gcc_s.1 "${libgcc_dir}")
install_name_tool_change_quadmath(gfortran)
install_name_tool_add_rpath(gfortran)
install_name_tool_add_rpath(gfortran.5)

# gcc_s
install_name_tool_id(gcc_s.1)

# quadmath
install_name_tool_id(quadmath.0)
install_name_tool_change(quadmath.0 gcc_s.1 "${libgcc_dir}")
install_name_tool_add_rpath(quadmath.0)

<MSG> Update tropter_install_mac_dependency_libraries.cmake.in (#2927)

* Update tropter_install_mac_dependency_libraries.cmake.in

Make libgfortran dependency on libquadmath.0 more robust

* Move line to modify rpath for libgfortran
<DFF> @@ -111,6 +111,7 @@ install_name_tool_add_rpath(coinmetis.1)
 install_name_tool_id(gfortran)
 install_name_tool_change(gfortran gcc_s.1 "${libgcc_dir}")
 install_name_tool_change_quadmath(gfortran)
+install_name_tool_change_quadmath(gfortran.5)
 install_name_tool_add_rpath(gfortran)
 install_name_tool_add_rpath(gfortran.5)
 

{'commit': 'diff --git a/Vendors/tropter/cmake/tropter_install_mac_dependency_libraries.cmake.in b/Vendors/tropter/cmake/tropter_install_mac_dependency_libraries.cmake.in\nindex 932328f11..b6965a828 100644\n--- a/Vendors/tropter/cmake/tropter_install_mac_dependency_libraries.cmake.in\n+++ b/Vendors/tropter/cmake/tropter_install_mac_dependency_libraries.cmake.in\n@@ -111,6 +111,7 @@ install_name_tool_add_rpath(coinmetis.1)\n install_name_tool_id(gfortran)\n install_name_tool_change(gfortran gcc_s.1 "${libgcc_dir}")\n install_name_tool_change_quadmath(gfortran)\n+install_name_tool_change_quadmath(gfortran.5)\n install_name_tool_add_rpath(gfortran)\n install_name_tool_add_rpath(gfortran.5)\n \n', 'commit_subject': 'Update tropter_install_mac_dependency_libraries.cmake.in (#2927)', 'repo_name': 'opensim-org/opensim-core', 'committer': {'name': 'GitHub', 'email': '1505422b2465e9a84f6fdfaa161078890c593f06@github.com', 'time_sec': '1610130220', 'tz_offset': '-480', 'date': {'seconds': '1610130220'}}, 'commit_tree': 'd21023c90e11f2212550c04522899b5e09bac2c0', 'commit_message': 'Update tropter_install_mac_dependency_libraries.cmake.in (#2927)\n\n* Update tropter_install_mac_dependency_libraries.cmake.in\r\n\r\nMake libgfortran dependency on libquadmath.0 more robust\r\n\r\n* Move line to modify rpath for libgfortran', 'language_name': 'HTML', 'license': 'apache-2.0', 'hunks': '@@ -111,6 +111,7 @@ install_name_tool_add_rpath(coinmetis.1)\n install_name_tool_id(gfortran)\n install_name_tool_change(gfortran gcc_s.1 "${libgcc_dir}")\n install_name_tool_change_quadmath(gfortran)\n+install_name_tool_change_quadmath(gfortran.5)\n install_name_tool_add_rpath(gfortran)\n install_name_tool_add_rpath(gfortran.5)\n \n', 'addition_count': 1, 'deletion_count': 0, 'src_file': 'a/Vendors/tropter/cmake/tropter_install_mac_dependency_libraries.cmake.in', 'tgt_file': 'b/Vendors/tropter/cmake/tropter_install_mac_dependency_libraries.cmake.in', 'file_extension': '.in', 'before_file': '# Temporary hack to package dependencies on Macs.\n\nset(libdir "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")\nmessage(STATUS "Editing RPATH of tropter dependency libraries")\n\nmacro(install_name_tool_change lib dep_name dep_oldpath)\n    execute_process(COMMAND install_name_tool\n            -change ${dep_oldpath}/lib${dep_name}.dylib\n            @rpath/lib${dep_name}.dylib\n            "${libdir}/lib${lib}.dylib")\nendmacro()\n\nmacro(install_name_tool_change_gfortran lib)\n    execute_process(COMMAND bash "-c"\n        "otool -L ${libdir}/lib${lib}.dylib | grep \'libgfortran.*version\' | perl -pe \'s/^\\\\s+(.*)\\\\/libg.*/\\\\1/gc\'"\n        OUTPUT_VARIABLE libgfortran_dir\n        OUTPUT_STRIP_TRAILING_WHITESPACE)\n    execute_process(COMMAND bash "-c"\n        "otool -L ${libdir}/lib${lib}.dylib | grep \'libgfortran.*version\' | perl -pe \'s/.*lib(.*).dylib.*/\\\\1/gc\'"\n        OUTPUT_VARIABLE libgfortran_name\n        OUTPUT_STRIP_TRAILING_WHITESPACE)\n    install_name_tool_change(${lib} "${libgfortran_name}" "${libgfortran_dir}")\nendmacro()\n\nmacro(install_name_tool_change_quadmath lib)\nexecute_process(COMMAND bash "-c"\n    "otool -L ${libdir}/lib${lib}.dylib | grep \'libquadmath\' | perl -pe \'s/^\\\\s+(.*)\\\\/libq.*/\\\\1/gc\'"\n    OUTPUT_VARIABLE libquadmath_dir\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\n\nexecute_process(COMMAND bash "-c"\n    "otool -L ${libdir}/lib${lib}.dylib | grep \'libquadmath\' | perl -pe \'s/.*lib(.*).dylib.*/\\\\1/gc\'"\n    OUTPUT_VARIABLE libquadmath_name\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\n    install_name_tool_change(${lib} "${libquadmath_name}" "${libquadmath_dir}")\nendmacro()\n\nmacro(install_name_tool_id lib)\n    execute_process(COMMAND install_name_tool\n            -id @rpath/lib${lib}.dylib\n            "${libdir}/lib${lib}.dylib")\nendmacro()\n\nmacro(install_name_tool_add_rpath lib)\n    execute_process(COMMAND install_name_tool\n            -add_rpath "@loader_path/"\n            "${libdir}/lib${lib}.dylib")\nendmacro()\n\nmacro(install_name_tool_delete_rpath lib rpath)\n    execute_process(COMMAND install_name_tool\n            -delete_rpath ${rpath}\n            "${libdir}/lib${lib}.dylib")\nendmacro()\n\n# Get the directory containing libgcc_s.1.dylib.\n# otool: Get the list of dependencies of gfortran, which includes libgcc_s.\n# grep: Isolate the line containing libgcc.\n# perl: Extract only the directory, without the filename.\n#    ^\\\\s+     matches all spaces at the start of the string.\n#   (.*)       matches everything up to libgcc, and captures it as match gorup #1\n#   \\\\/libg.*  matches the rest of the line.\n#   \\\\1        replaces the contents of the entire match with match group #1\nexecute_process(COMMAND bash "-c"\n    "otool -L ${libdir}/libgfortran.dylib | grep \'libgcc\' | perl -pe \'s/^\\\\s+(.*)\\\\/libg.*/\\\\1/gc\'"\n    OUTPUT_VARIABLE libgcc_dir\n    OUTPUT_STRIP_TRAILING_WHITESPACE)\n\n# tropter\ninstall_name_tool_change(tropter adolc.2 "@ADOLC_DIR@/lib64")\ninstall_name_tool_change(tropter ipopt.1 "@IPOPT_LIBDIR@")\ninstall_name_tool_change(tropter coinmumps.1 "@IPOPT_LIBDIR@")\ninstall_name_tool_change(tropter coinmetis.1 "@IPOPT_LIBDIR@")\ninstall_name_tool_change_gfortran(tropter)\ninstall_name_tool_change_quadmath(tropter)\ninstall_name_tool_add_rpath(tropter)\n\n# adol-c\ninstall_name_tool_id(adolc.2)\n# install_name_tool_change(adolc.2 boost_system /usr/local/opt/boost/lib)\n# install_name_tool_change(adolc.2 ColPack.0 /usr/local/opt/colpack/lib)\ninstall_name_tool_add_rpath(adolc.2)\ninstall_name_tool_delete_rpath(adolc.2 "@ColPack_ROOT_DIR@/lib")\n\n# ipopt\ninstall_name_tool_id(ipopt.1)\ninstall_name_tool_change(ipopt.1 coinmumps.1 "@IPOPT_LIBDIR@")\ninstall_name_tool_change(ipopt.1 coinmetis.1 "@IPOPT_LIBDIR@")\ninstall_name_tool_change_gfortran(ipopt.1)\ninstall_name_tool_change_quadmath(ipopt.1)\n\n# coinmumps\ninstall_name_tool_id(coinmumps.1)\ninstall_name_tool_change(coinmumps.1 coinmetis.1 "@IPOPT_LIBDIR@")\ninstall_name_tool_change_gfortran(coinmumps.1)\ninstall_name_tool_change(coinmumps.1 gcc_s.1 "${libgcc_dir}")\ninstall_name_tool_change_quadmath(coinmumps.1)\ninstall_name_tool_add_rpath(coinmumps.1)\n\n# coinmetis\ninstall_name_tool_id(coinmetis.1)\ninstall_name_tool_add_rpath(coinmetis.1)\n\n# boost_system\n# install_name_tool_id(boost_system)\n\n# Colpack.0\n# install_name_tool_id(ColPack.0)\n\n# gfortran\ninstall_name_tool_id(gfortran)\ninstall_name_tool_change(gfortran gcc_s.1 "${libgcc_dir}")\ninstall_name_tool_change_quadmath(gfortran)\ninstall_name_tool_add_rpath(gfortran)\ninstall_name_tool_add_rpath(gfortran.5)\n\n# gcc_s\ninstall_name_tool_id(gcc_s.1)\n\n# quadmath\ninstall_name_tool_id(quadmath.0)\ninstall_name_tool_change(quadmath.0 gcc_s.1 "${libgcc_dir}")\ninstall_name_tool_add_rpath(quadmath.0)\n', 'message': 'Update tropter_install_mac_dependency_libraries.cmake.in (#2927)\n\n* Update tropter_install_mac_dependency_libraries.cmake.in\r\n\r\nMake libgfortran dependency on libquadmath.0 more robust\r\n\r\n* Move line to modify rpath for libgfortran', 'author_name': 'GitHub', 'lang': 'cmake'}