KPXCMacDeployHelpers.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Running macdeployqt on a POST_BUILD copied binaries is pointless when using CPack because
  2. # the copied binaries will be overridden by the corresponding install(TARGETS) commands.
  3. # That's why we run macdeployqt using install(CODE) on the already installed binaries.
  4. # The precondition is that all install(TARGETS) calls have to be called before this function is
  5. # called.
  6. # macdeloyqt is called only once, but it is given all executables that should be processed.
  7. function(kpxc_run_macdeployqt_at_install_time)
  8. set(NO_VALUE_OPTIONS)
  9. set(SINGLE_VALUE_OPTIONS
  10. APP_NAME
  11. )
  12. set(MULTI_VALUE_OPTIONS
  13. EXTRA_BINARIES
  14. )
  15. cmake_parse_arguments(PARSE_ARGV 0 ARG
  16. "${NO_VALUE_OPTIONS}" "${SINGLE_VALUE_OPTIONS}" "${MULTI_VALUE_OPTIONS}"
  17. )
  18. set(ESCAPED_PREFIX "\${CMAKE_INSTALL_PREFIX}")
  19. set(APP_BUNDLE_NAME "${ARG_APP_NAME}.app")
  20. set(APP_BUNDLE_PATH "${ESCAPED_PREFIX}/${APP_BUNDLE_NAME}")
  21. # Collect extra binaries and plugins that should be handled by macdpeloyqt.
  22. set(EXTRA_BINARIES "")
  23. foreach(EXTRA_BINARY ${ARG_EXTRA_BINARIES})
  24. set(INSTALLED_BINARY_PATH "${ESCAPED_PREFIX}/${EXTRA_BINARY}")
  25. list(APPEND EXTRA_BINARIES "-executable=${INSTALLED_BINARY_PATH}")
  26. endforeach()
  27. list(JOIN EXTRA_BINARIES " " EXTRA_BINARIES_STR)
  28. if(CMAKE_VERSION VERSION_GREATER "3.14")
  29. set(COMMAND_ECHO "COMMAND_ECHO STDOUT")
  30. else()
  31. set(COMMAND_ECHO "")
  32. endif()
  33. set(COMMAND_ARGS
  34. ${MACDEPLOYQT_EXE}
  35. ${APP_BUNDLE_PATH}
  36. # Adjusts dependency rpaths of extra binaries
  37. ${EXTRA_BINARIES_STR}
  38. # Silences warnings on subsequent re-installations
  39. -always-overwrite
  40. )
  41. install(CODE
  42. "
  43. execute_process(
  44. COMMAND ${COMMAND_ARGS}
  45. ${COMMAND_ECHO}
  46. RESULT_VARIABLE EXIT_CODE
  47. )
  48. if(NOT EXIT_CODE EQUAL 0)
  49. message(FATAL_ERROR
  50. \"Running ${COMMAND_ARGS} failed with exit code \${EXIT_CODE}.\")
  51. endif()
  52. ")
  53. endfunction()