CMakeLists.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # We need to keep this code into separate directory so CMake will execute it after all other subdirectories install code
  2. # Otherwise we can't fix Mac bundle dependencies since binaries wouldn't be there when this code executed
  3. if(APPLE_MACOS)
  4. set(bundleDir "\${CMAKE_INSTALL_PREFIX}/${APP_BUNDLE_DIR}")
  5. set(bundleContentsDir "${bundleDir}/Contents")
  6. if(ENABLE_LAUNCHER OR ENABLE_EDITOR)
  7. if(USING_CONAN)
  8. # simulate macdeployqt behavior, main Qt libs are copied by conan
  9. get_target_property(qmakePath Qt5::qmake IMPORTED_LOCATION)
  10. execute_process(COMMAND
  11. "${qmakePath}" -query QT_INSTALL_PLUGINS
  12. OUTPUT_VARIABLE qtPluginsDir
  13. OUTPUT_STRIP_TRAILING_WHITESPACE
  14. )
  15. install(DIRECTORY
  16. ${qtPluginsDir}/
  17. DESTINATION ${APP_BUNDLE_DIR}/Contents/PlugIns
  18. )
  19. install(CODE "
  20. file(WRITE ${bundleContentsDir}/Resources/qt.conf
  21. \"[Paths]\nPlugins = PlugIns\"
  22. )
  23. ")
  24. else()
  25. # note: cross-compiled Qt 5 builds macdeployqt for target platform instead of host
  26. # deploy Qt dylibs with macdeployqt
  27. find_program(TOOL_MACDEPLOYQT NAMES macdeployqt PATHS ${qt_base_dir}/bin)
  28. if(TOOL_MACDEPLOYQT)
  29. install(CODE "
  30. execute_process(COMMAND
  31. \"${TOOL_MACDEPLOYQT}\" \"${bundleDir}\" -verbose=2
  32. )
  33. ")
  34. else()
  35. message(WARNING "macdeployqt not found, running cpack would result in broken package")
  36. endif()
  37. endif()
  38. endif()
  39. # deploy other dylibs with conan
  40. vcmi_install_conan_deps("${bundleContentsDir}")
  41. # perform ad-hoc codesigning
  42. set(executablesToSign vcmiserver)
  43. if(ENABLE_EDITOR)
  44. list(APPEND executablesToSign vcmieditor)
  45. endif()
  46. # main executable must be last
  47. list(APPEND executablesToSign vcmiclient)
  48. if(ENABLE_LAUNCHER)
  49. list(APPEND executablesToSign vcmilauncher)
  50. endif()
  51. set(codesignCommand "codesign --verbose=4 --force --options=runtime --timestamp=none --sign -")
  52. set(codesignCommandWithEntitlements "${codesignCommand} --entitlements \"${CMAKE_SOURCE_DIR}/osx/entitlements.plist\"")
  53. install(CODE "
  54. execute_process(COMMAND
  55. ${codesignCommand} \"${bundleContentsDir}/MacOS/vcmibuilder\"
  56. )
  57. foreach(executable ${executablesToSign})
  58. execute_process(COMMAND
  59. ${codesignCommandWithEntitlements} --identifier eu.vcmi.\${executable} \"${bundleContentsDir}/MacOS/\${executable}\"
  60. )
  61. endforeach()
  62. ")
  63. endif()