WindowsInstaller.cmake 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. find_program(WIX_HEAT heat)
  2. find_program(WIX_CANDLE candle)
  3. find_program(WIX_LIGHT light)
  4. find_program(WIX_INSIGNIA insignia)
  5. get_filename_component(WIX_BIN_DIR ${WIX_CANDLE} DIRECTORY)
  6. configure_file(${PROJECT_SOURCE_DIR}/bundle/win/Version.wxi.in Version.wxi)
  7. set(WIX_VARIABLES -dDeploymentPath="${CMAKE_INSTALL_PREFIX}" -dOutputPath="${CMAKE_BINARY_DIR}")
  8. include(CMakeParseArguments)
  9. function(wix_harvest_directory dir fragment)
  10. set(ARGS REFVARIABLE CGROUP DEPENDS)
  11. cmake_parse_arguments(_WHD "" "${ARGS}" "" ${ARGN})
  12. if(NOT _WHD_REFVARIABLE)
  13. set(_WHD_REFVARIABLE INSTALLLOCATION)
  14. endif()
  15. if(_WHD_CGROUP)
  16. set(CGROUP -cg ${_WHD_CGROUP})
  17. endif()
  18. add_custom_command(OUTPUT ${fragment}
  19. DEPENDS ${_WHD_DEPENDS}
  20. COMMAND ${WIX_HEAT} dir "${dir}" -srd -nologo -sw5150 ${CGROUP} -dr ${_WHD_REFVARIABLE} -ag -out ${fragment} -var var.DeploymentPath
  21. COMMENT "Harvesting dir ${dir} to ${fragment}")
  22. add_custom_target(heat_${fragment} DEPENDS ${fragment})
  23. endfunction()
  24. function(wix_get_extension VARIABLE)
  25. foreach(f ${ARGN})
  26. find_file(${f}_PATH ${f}.dll PATHS ${WIX_BIN_DIR})
  27. set(EXTS ${EXTS} -ext ${${f}_PATH})
  28. endforeach()
  29. set(${VARIABLE} ${EXTS} PARENT_SCOPE)
  30. endfunction()
  31. function(wix_candle wsxfile)
  32. set(ARGS OUTPUT ARCH)
  33. set(MARGS EXTENSIONS)
  34. cmake_parse_arguments(_WC "" "${ARGS}" "${MARGS}" ${ARGN})
  35. if(NOT _WC_OUTPUT)
  36. get_filename_component(WC_BASENAME ${wsxfile} NAME_WE)
  37. set(_WC_OUTPUT ${WC_BASENAME}.wixobj)
  38. endif()
  39. if(NOT _WC_ARCH)
  40. set(_WC_ARCH x64)
  41. endif()
  42. if(_WC_EXTENSIONS)
  43. wix_get_extension(WIX_EXTENSIONS ${_WC_EXTENSIONS})
  44. endif()
  45. add_custom_command(OUTPUT ${_WC_OUTPUT}
  46. DEPENDS ${wsxfile}
  47. COMMAND ${WIX_CANDLE} -nologo ${WIX_VARIABLES} -I${CMAKE_CURRENT_BINARY_DIR} -arch ${_WC_ARCH} ${wsxfile} ${WIX_EXTENSIONS} -out ${_WC_OUTPUT}
  48. COMMENT "Candle file ${_WC_OUTPUT}"
  49. )
  50. endfunction()
  51. function(wix_light)
  52. set(MARGS OBJS DEPENDS EXTENSIONS)
  53. set(ARGS OUTPUT BASEDIR TARGET)
  54. cmake_parse_arguments(_WL "" "${ARGS}" "${MARGS}" ${ARGN})
  55. if(NOT _WL_OUTPUT)
  56. message(FATAL_ERROR "Need OUTPUT")
  57. endif()
  58. if(_WL_EXTENSIONS)
  59. wix_get_extension(WIX_EXTENSIONS ${_WL_EXTENSIONS})
  60. endif()
  61. if(_WL_BASEDIR)
  62. set(_WL_BASEDIR -b ${_WL_BASEDIR})
  63. endif()
  64. if(NOT _WL_TARGET)
  65. set(_WL_TARGET wix_${_WL_OUTPUT})
  66. endif()
  67. add_custom_command(OUTPUT ${_WL_OUTPUT}
  68. DEPENDS ${_WL_OBJS} ${_WL_DEPENDS}
  69. COMMAND ${WIX_LIGHT} -nologo ${_WL_BASEDIR} ${_WL_OBJS} ${WIX_VARIABLES} ${WIX_EXTENSIONS} -out ${_WL_OUTPUT}
  70. COMMENT "Light it up: ${_WL_OUTPUT}")
  71. add_custom_target(${_WL_TARGET} DEPENDS ${_WL_OUTPUT})
  72. if(CODE_SIGN)
  73. if(_WL_OUTPUT MATCHES ".*exe")
  74. add_custom_command(TARGET ${_WL_TARGET} POST_BUILD
  75. COMMAND ${WIX_INSIGNIA} -ib ${_WL_OUTPUT} -o engine.exe
  76. COMMAND ${CMAKE_SOURCE_DIR}/scripts/WindowsSign.cmd engine.exe
  77. COMMAND ${WIX_INSIGNIA} -ab engine.exe ${_WL_OUTPUT} -o ${_WL_OUTPUT}
  78. COMMENT "Doing insignia dance"
  79. )
  80. endif()
  81. add_custom_command(TARGET ${_WL_TARGET} POST_BUILD
  82. COMMAND ${CMAKE_SOURCE_DIR}/scripts/WindowsSign.cmd ${_WL_OUTPUT}
  83. COMMENT Signing ${_WL_OUTPUT}
  84. )
  85. endif()
  86. endfunction()
  87. function(wix_create_installer output)
  88. set(MARGS WXS_FILES EXTENSIONS DEPENDS)
  89. set(ARGS ARCH BASEDIR TARGET)
  90. cmake_parse_arguments(_WCI "" "${ARGS}" "${MARGS}" ${ARGN})
  91. foreach(wxs ${_WCI_WXS_FILES})
  92. get_filename_component(WXSBASE ${wxs} NAME_WE)
  93. wix_candle(${wxs} OUTPUT ${WXSBASE}.wixobj EXTENSIONS ${_WCI_EXTENSIONS} ARCH ${_WCI_ARCH})
  94. list(APPEND WIXOBJS ${WXSBASE}.wixobj)
  95. endforeach()
  96. wix_light(OBJS ${WIXOBJS}
  97. EXTENSIONS ${_WCI_EXTENSIONS}
  98. OUTPUT ${output}
  99. DEPENDS ${_WCI_DEPENDS}
  100. BASEDIR ${_WCI_BASEDIR}
  101. TARGET ${_WCI_TARGET})
  102. endfunction()
  103. add_custom_target(wix_install
  104. COMMAND ${CMAKE_COMMAND} -P cmake_install.cmake
  105. COMMENT "Copying files..."
  106. DEPENDS PMPHelper PlexMediaPlayer)
  107. wix_harvest_directory("${CMAKE_INSTALL_PREFIX}" files.wxs CGROUP ProgramFilesComponentGroup DEPENDS wix_install)
  108. wix_create_installer(PMP.msi
  109. WXS_FILES files.wxs "${PROJECT_SOURCE_DIR}/bundle/win/PMP.wxs"
  110. EXTENSIONS WixUtilExtension WixFirewallExtension
  111. BASEDIR "${PROJECT_SOURCE_DIR}/bundle/win"
  112. )
  113. wix_create_installer(PlexMediaPlayer-${VERSION_STRING}-windows-x64.exe
  114. TARGET PlexMediaPlayerInstaller
  115. WXS_FILES "${PROJECT_SOURCE_DIR}/bundle/win/Bundle.wxs"
  116. EXTENSIONS WixUtilExtension WixBalExtension
  117. DEPENDS wix_PMP.msi
  118. BASEDIR "${PROJECT_SOURCE_DIR}/bundle/win"
  119. )
  120. add_custom_target(windows_package DEPENDS PlexMediaPlayerInstaller)