Skip to content

Instantly share code, notes, and snippets.

@ligfx
Created October 26, 2016 02:13
Show Gist options
  • Save ligfx/d7946c60565f9cbbb25223ada06d5602 to your computer and use it in GitHub Desktop.
Save ligfx/d7946c60565f9cbbb25223ada06d5602 to your computer and use it in GitHub Desktop.
include(GetPrerequisites)
function(STARTSWITH string prefix outvar)
string(FIND "${string}" "${prefix}" _prefix_location)
if("${_prefix_location}" EQUAL 0)
set("${outvar}" TRUE PARENT_SCOPE)
else()
set("${outvar}" FALSE PARENT_SCOPE)
endif()
endfunction()
function(MICHAEL binary outvar)
set(EXCLUDE_SYSTEM FALSE)
set(RECURSE FALSE)
get_prerequisites("${binary}" _prereqs ${EXCLUDE_SYSTEM} ${RECURSE} "${binary}" "")
get_filename_component(binary_name "${binary}" NAME)
message("${binary_name}:")
set(_my_prereqs)
foreach (p IN LISTS _prereqs)
startswith("${p}" "/System/" SYSTEM_LIBRARY)
startswith("${p}" "/usr/lib/" USR_LIBRARY)
startswith("${p}" "/Users/michaelmaltese/Downloads/dolphin/" LOCAL_LIBRARY)
if(NOT SYSTEM_LIBRARY AND NOT USR_LIBRARY)
if(LOCAL_LIBRARY)
message(" ${p} (built)")
else()
message(" ${p} (other)")
endif()
list(APPEND _my_prereqs "${p}")
endif()
endforeach()
set("${outvar}" "${_my_prereqs}" PARENT_SCOPE)
endfunction()
set(working "${CMAKE_SOURCE_DIR}/Binaries/Dolphin.app/Contents/MacOS/Dolphin")
set(processed)
set(LIBDIR "Frameworks")
set(BINDIR "MacOS")
while(working)
list(GET working 0 current)
list(REMOVE_AT working 0)
get_filename_component(current "${current}" REALPATH)
get_filename_component(binary_name "${current}" NAME)
list(FIND processed "${binary_name}" processed_index)
if(processed_index GREATER -1)
continue()
endif()
michael("${current}" prereqs)
foreach(p IN LISTS prereqs)
list(APPEND working "${p}")
endforeach()
list(APPEND processed "${binary_name}")
is_file_executable("${current}" executable)
if(executable)
file(COPY "${current}" DESTINATION "${BINDIR}")
foreach(p IN LISTS prereqs)
get_filename_component(prereq_realpath "${p}" REALPATH)
get_filename_component(prereq_name "${prereq_realpath}" NAME)
execute_process(COMMAND install_name_tool -change "${p}" "@executable_path/../${LIBDIR}/${prereq_name}" "${BINDIR}/${binary_name}")
endforeach()
else()
file(INSTALL "${current}" DESTINATION "${LIBDIR}")
execute_process(COMMAND install_name_tool -id "${binary_name}" "${LIBDIR}/${binary_name}")
foreach(p IN LISTS prereqs)
get_filename_component(prereq_realpath "${p}" REALPATH)
get_filename_component(prereq_name "${prereq_realpath}" NAME)
execute_process(COMMAND install_name_tool -change "${p}" "@loader_path/${prereq_name}" "${LIBDIR}/${binary_name}")
endforeach()
endif()
endwhile()
# list_prerequisites("${CMAKE_SOURCE_DIR}/Binaries/Dolphin.app/Contents/MacOS/Dolphin" ${EXCLUDE_SYSTEM} ${RECURSE} 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment