2021-01-02 17:57:29 +00:00
|
|
|
include(BundleUtilities)
|
2020-12-06 18:00:13 +00:00
|
|
|
|
|
|
|
set(MACDEPLOYQT_PATH "@MACDEPLOYQT_PATH@")
|
|
|
|
set(INFO_PLIST_PATH "@CPACK_BUNDLE_PLIST@")
|
|
|
|
set(ADJUST_RIZIN_LIBS "@ADJUST_RIZIN_LIBS@")
|
2021-01-02 17:57:29 +00:00
|
|
|
set(CUTTER_PACKAGE_DEPENDENCIES "@CUTTER_PACKAGE_DEPENDENCIES@")
|
|
|
|
set(CUTTER_ENABLE_PYTHON "@CUTTER_ENABLE_PYTHON@")
|
2020-12-06 18:00:13 +00:00
|
|
|
|
|
|
|
macro(run_or_die)
|
|
|
|
execute_process(${ARGV} RESULT_VARIABLE PROC_RESULT)
|
|
|
|
if(PROC_RESULT)
|
|
|
|
message(FATAL_ERROR "Failed to run ${ARGV}")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
get_filename_component(BUNDLE_PATH "${CMAKE_INSTALL_PREFIX}/../.." ABSOLUTE)
|
|
|
|
set(EXECUTABLE_DIR "${BUNDLE_PATH}/Contents/MacOS")
|
2021-01-02 17:57:29 +00:00
|
|
|
set(FRAMEWORK_DIR "${BUNDLE_PATH}/Contents/Frameworks")
|
2020-12-06 18:00:13 +00:00
|
|
|
|
|
|
|
# Copying the Info.plist will be done later again by CPack but we need it a bit earlier
|
|
|
|
# so macdeployqt has enough info.
|
|
|
|
file(COPY "${INFO_PLIST_PATH}" DESTINATION "${BUNDLE_PATH}/Contents")
|
|
|
|
|
2021-01-02 17:57:29 +00:00
|
|
|
# replace absolute path from build directory in rizin pkgconfig files with relative ones
|
|
|
|
file(GLOB RZ_PCFILES "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig/rz_*.pc")
|
|
|
|
foreach (_pcfile ${RZ_PCFILES})
|
|
|
|
file(READ "${_pcfile}" _text)
|
|
|
|
string(REGEX REPLACE "^prefix=[^\n]*\n" "prefix=\${pcfiledir}/../..\n" _text "${_text}")
|
|
|
|
file(WRITE "${_pcfile}" "${_text}")
|
|
|
|
endforeach()
|
2020-12-06 18:00:13 +00:00
|
|
|
# macdeployqt would put the rz libraries into Contents/Frameworks by default, but we want to have them
|
|
|
|
# only in the prefix, so we fix the paths manually.
|
|
|
|
foreach(_lib ${ADJUST_RIZIN_LIBS})
|
|
|
|
get_filename_component(_lib "${_lib}" REALPATH)
|
|
|
|
get_filename_component(_name "${_lib}" NAME)
|
2021-01-02 17:57:29 +00:00
|
|
|
# Cutter reference to lib
|
2020-12-06 18:00:13 +00:00
|
|
|
run_or_die(COMMAND install_name_tool
|
|
|
|
-change "${_lib}" "@rpath/${_name}"
|
2021-01-23 10:26:01 +00:00
|
|
|
"${EXECUTABLE_DIR}/cutter")
|
2021-01-02 17:57:29 +00:00
|
|
|
# lib LC_ID_DYLIB
|
|
|
|
run_or_die(COMMAND install_name_tool
|
|
|
|
-id "@rpath/${_name}"
|
|
|
|
"${CMAKE_INSTALL_PREFIX}/lib/${_name}")
|
2020-12-06 18:00:13 +00:00
|
|
|
# Fix every lib for every lib too
|
|
|
|
foreach(_lib2 ${ADJUST_RIZIN_LIBS})
|
|
|
|
get_filename_component(_lib2 "${_lib2}" REALPATH)
|
|
|
|
get_filename_component(_name2 "${_lib2}" NAME)
|
|
|
|
run_or_die(COMMAND install_name_tool
|
|
|
|
-change "${_lib2}" "@rpath/${_name2}"
|
|
|
|
"${CMAKE_INSTALL_PREFIX}/lib/${_name}")
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# Add rpaths because macdeployqt fails to do that properly
|
|
|
|
run_or_die(COMMAND install_name_tool
|
|
|
|
-add_rpath "@executable_path/../Frameworks"
|
2021-01-23 10:26:01 +00:00
|
|
|
"${EXECUTABLE_DIR}/cutter")
|
2020-12-06 18:00:13 +00:00
|
|
|
run_or_die(COMMAND install_name_tool
|
|
|
|
-add_rpath "@executable_path/../Resources/lib"
|
2021-01-23 10:26:01 +00:00
|
|
|
"${EXECUTABLE_DIR}/cutter")
|
2022-06-07 23:18:43 +00:00
|
|
|
run_or_die(COMMAND install_name_tool
|
|
|
|
-add_rpath "@executable_path/../Resources/lib/rizin/plugins"
|
|
|
|
"${EXECUTABLE_DIR}/cutter")
|
2020-12-06 18:00:13 +00:00
|
|
|
|
2021-01-02 17:57:29 +00:00
|
|
|
set(MACDEPLOYQT_COMMAND "${MACDEPLOYQT_PATH}" "${BUNDLE_PATH}" "-verbose=2" "-libpath=${CMAKE_INSTALL_PREFIX}/lib")
|
2020-12-06 18:00:13 +00:00
|
|
|
message("Running macdeployqt \"${MACDEPLOYQT_COMMAND}\"")
|
2021-01-02 17:57:29 +00:00
|
|
|
run_or_die(COMMAND ${MACDEPLOYQT_COMMAND}) # First run
|
|
|
|
if (CUTTER_PACKAGE_DEPENDENCIES AND CUTTER_ENABLE_PYTHON)
|
|
|
|
file(REAL_PATH "${FRAMEWORK_DIR}/Python.framework/Python" _python_lib_path)
|
|
|
|
message("Python lib ${_python_lib_path}")
|
|
|
|
list(APPEND MACDEPLOYQT_COMMAND "-executable=${_python_lib_path}")
|
|
|
|
endif()
|
|
|
|
# Qt plugins are not getting deployed on first macdeployqt run. Runing twice helps.
|
|
|
|
# If python is added as additional executable in first run it also breaks plugin copying.
|
|
|
|
run_or_die(COMMAND ${MACDEPLOYQT_COMMAND}) # Second run
|
2020-12-06 18:00:13 +00:00
|
|
|
|
|
|
|
# Clean up the mess that macdeployqt made (duplicate rz libs, we only want the ones in the prefix)
|
|
|
|
foreach(_lib ${ADJUST_RIZIN_LIBS})
|
|
|
|
get_filename_component(_lib "${_lib}" REALPATH)
|
|
|
|
get_filename_component(_name "${_lib}" NAME)
|
|
|
|
file(REMOVE "${BUNDLE_PATH}/Contents/Frameworks/${_name}")
|
|
|
|
endforeach()
|