Skip to content

Commit

Permalink
Add option to fix Mac OS libs
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Dec 24, 2022
1 parent e7d5ea1 commit c26ddbd
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,35 @@ macro(FIX_LIBRARY_ID DYLIB_NAME CURRENT_DYLIB_FILENAME LIBRARY_DISPLAY_NAME)
# Once the issue is resolved, we can renable the the macro
execute_process(COMMAND bash "-c" "otool -D ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME} | tail -n 1 | tr -d '\n'" OUTPUT_VARIABLE DYLIB_ID)
if (NOT ${DYLIB_ID} STREQUAL "@rpath/${DYLIB_NAME}.dylib")
message (FATAL_ERROR
"The Mac library ${DYLIB_NAME}.dylib in the ${LIBRARY_DISPLAY_NAME} source folder has the ID ${DYLIB_ID} which could cause linking problems."
"Please let the maintainer for ${LIBRARY_DISPLAY_NAME} know about the issue."
"Changing the library ${DYLIB_NAME}.dylib to have the id @rpath/${DYLIB_NAME}.dylib so it links properly with rpaths."
)
# execute_process(COMMAND bash "-c" "install_name_tool -id @rpath/${DYLIB_NAME}.dylib ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME}")
if (FIX_MACOS_LIBS)
execute_process(COMMAND bash "-c" "install_name_tool -id @rpath/${DYLIB_NAME}.dylib ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME}")
else()
message (FATAL_ERROR
"The Mac library ${DYLIB_NAME}.dylib in the ${LIBRARY_DISPLAY_NAME} source folder has the ID ${DYLIB_ID} which could cause linking problems."
"Please let the maintainer for ${LIBRARY_DISPLAY_NAME} know about the issue."
"Changing the library ${DYLIB_NAME}.dylib to have the id @rpath/${DYLIB_NAME}.dylib so it links properly with rpaths."
)
endif()
endif (NOT ${DYLIB_ID} STREQUAL "@rpath/${DYLIB_NAME}.dylib")

# # This section corrects absolute or bad links to libusb
# execute_process(COMMAND bash "-c" "otool -L ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME} | cut -d ' ' -f1" OUTPUT_VARIABLE LINKS_LIST)
# string (REPLACE "\t" "" LINKS_LIST "${LINKS_LIST}")
# string (REPLACE "\n" ";" LINKS_LIST "${LINKS_LIST}")
# foreach(LINK IN LISTS LINKS_LIST)
# if("${LINK}" MATCHES "libusb-1.0.0")
# if (NOT "${LINK}" STREQUAL "@rpath/libusb-1.0.0.dylib")
# message (WARNING
# "The mac library ${DYLIB_NAME}.dylib in the ${LIBRARY_DISPLAY_NAME} source folder has a link to "
# "${LINK} which could cause issues if libusb-1.0.0 is not actually at that location. "
# "Changing the link to @rpath/libusb-1.0.0.dylib for better compatibility."
# )
# execute_process(COMMAND bash "-c" "install_name_tool -change ${LINK} @rpath/libusb-1.0.0.dylib ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME}")
# endif (NOT "${LINK}" STREQUAL "@rpath/libusb-1.0.0.dylib")
# endif("${LINK}" MATCHES "libusb-1.0.0")
# endforeach(LINK IN LISTS LINKS_LIST)
if (FIX_MACOS_LIBS)
execute_process(COMMAND bash "-c" "otool -L ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME} | cut -d ' ' -f1" OUTPUT_VARIABLE LINKS_LIST)
string (REPLACE "\t" "" LINKS_LIST "${LINKS_LIST}")
string (REPLACE "\n" ";" LINKS_LIST "${LINKS_LIST}")
foreach(LINK IN LISTS LINKS_LIST)
if("${LINK}" MATCHES "libusb-1.0.0")
if (NOT "${LINK}" STREQUAL "@rpath/libusb-1.0.0.dylib")
message (WARNING
"The mac library ${DYLIB_NAME}.dylib in the ${LIBRARY_DISPLAY_NAME} source folder has a link to "
"${LINK} which could cause issues if libusb-1.0.0 is not actually at that location. "
"Changing the link to @rpath/libusb-1.0.0.dylib for better compatibility."
)
execute_process(COMMAND bash "-c" "install_name_tool -change ${LINK} @rpath/libusb-1.0.0.dylib ${CMAKE_CURRENT_SOURCE_DIR}/${CURRENT_DYLIB_FILENAME}")
endif (NOT "${LINK}" STREQUAL "@rpath/libusb-1.0.0.dylib")
endif("${LINK}" MATCHES "libusb-1.0.0")
endforeach(LINK IN LISTS LINKS_LIST)
endif(FIX_MACOS_LIBS)
endmacro(FIX_LIBRARY_ID)

endif(APPLE)
Expand Down Expand Up @@ -104,6 +109,11 @@ ENDIF ()
# It is a good idea to run with this option before the 3rd Party build so all the libraries are built first.
option(BUILD_LIBS "Build 3rd Party Libraries, not 3rd Party Drivers" Off)

# Fix MacOS libraries linking
# Do not ENABLE on production! Should be enabled by INDI core developers only
# to fix the affected libraries and push a fix to the repo after a binary update.
option(FIX_MACOS_LIBS "Fix MacOS Libraries links" Off)

# Define standard set of drivers to build (default linux target)
option(WITH_EQMOD "Install EQMod Driver" On)
option(WITH_STARBOOK "Install Starbook Driver" On)
Expand Down

0 comments on commit c26ddbd

Please sign in to comment.