| 1 | set(BIN ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE}) |
| 2 | |
| 3 | # For pipeline builds, use PACKAGE_INPUT_DIR if specified (contains signed binaries) |
| 4 | # For local builds, use bin directory |
| 5 | if(DEFINED PACKAGE_INPUT_DIR) |
| 6 | message(STATUS "Using signed binaries from ${PACKAGE_INPUT_DIR} for MSI packaging") |
| 7 | else() |
| 8 | set(PACKAGE_INPUT_DIR ${BIN}) |
| 9 | endif() |
| 10 | |
| 11 | # DCOM Access/Launch permission binary security descriptor. |
| 12 | # SDDL: O:BAG:BAD:(A;;CCDCSW;;;AU)(A;;CCDCSW;;;PS)(A;;CCDCSW;;;SY) |
| 13 | # Grants local launch/activate to Authenticated Users, Principal Self, and SYSTEM. |
| 14 | set(DCOM_PERMISSION "01000480580000006800000000000000140000000200440003000000000014000B00000001010000000000050B000000000014000B00000001010000000000050A000000000014000B0000000101000000000005120000000102000000000005200000002002000001020000000000052000000020020000") |
| 15 | |
| 16 | set(OUTPUT_PACKAGE ${BIN}/wsl.msi) |
| 17 | set(PACKAGE_WIX_IN ${CMAKE_CURRENT_LIST_DIR}/package.wix.in) |
| 18 | set(PACKAGE_WIX ${BIN}/package.wix) |
| 19 | set(CAB_CACHE ${BIN}/cab) |
| 20 | set(WINDOWS_BINARIES wsl.exe;wslg.exe;wslhost.exe;wslrelay.exe;wslservice.exe;wslserviceproxystub.dll;wsldevicehostproxystub.dll;wslinstall.dll;wslc.exe;wslcsession.exe) |
| 21 | if (WSL_BUILD_WSL_SETTINGS) |
| 22 | list(APPEND WINDOWS_BINARIES "wslsettings/wslsettings.dll;wslsettings/wslsettings.exe;libwsl.dll") |
| 23 | endif() |
| 24 | |
| 25 | set(BINARIES_DEPENDENCIES) |
| 26 | foreach(binary ${WINDOWS_BINARIES}) |
| 27 | list(APPEND BINARIES_DEPENDENCIES "${PACKAGE_INPUT_DIR}/${binary}") |
| 28 | endforeach() |
| 29 | |
| 30 | set(LINUX_BINARIES init;initrd.img) |
| 31 | foreach(binary ${LINUX_BINARIES}) |
| 32 | list(APPEND BINARIES_DEPENDENCIES "${BIN}/${binary}") |
| 33 | endforeach() |
| 34 | |
| 35 | if (${WSL_BUILD_THIN_PACKAGE}) |
| 36 | set(COMPRESS_PACKAGE "no") |
| 37 | else() |
| 38 | set(COMPRESS_PACKAGE "yes") |
| 39 | endif() |
| 40 | |
| 41 | configure_file(${PACKAGE_WIX_IN} ${PACKAGE_WIX}) |
| 42 | file(MAKE_DIRECTORY ${CAB_CACHE}) |
| 43 | |
| 44 | if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") |
| 45 | set(COMPRESSION "high") |
| 46 | else() |
| 47 | set(COMPRESSION "none") |
| 48 | endif() |
| 49 | |
| 50 | add_custom_command( |
| 51 | OUTPUT ${OUTPUT_PACKAGE} |
| 52 | COMMAND ${WIX_SOURCE_DIR}/wix.exe build ${PACKAGE_WIX} -o ${OUTPUT_PACKAGE} -arch ${TARGET_PLATFORM} -dcl ${COMPRESSION} -cc ${CAB_CACHE} -pdbtype none |
| 53 | COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/CmakeFiles/msipackage" |
| 54 | VERBATIM |
| 55 | DEPENDS ${PACKAGE_WIX} ${BINARIES_DEPENDENCIES} ${CMAKE_SOURCE_DIR}/NOTICE.txt # Make sure the package is rebuilt if any of the binaries or resources change |
| 56 | ) |
| 57 | |
| 58 | add_custom_target(msipackage DEPENDS ${OUTPUT_PACKAGE}) |
| 59 | set_target_properties(msipackage PROPERTIES EXCLUDE_FROM_ALL FALSE SOURCES ${PACKAGE_WIX_IN}) |
| 60 | add_dependencies(msipackage wsl wslg wslservice wslhost wslrelay wslserviceproxystub wsldevicehostproxystub init initramfs wslinstall msixgluepackage wslc wslcsession) |
| 61 | |
| 62 | if (WSL_BUILD_WSL_SETTINGS) |
| 63 | add_dependencies(msipackage wslsettings libwsl) |
| 64 | endif() |
| 65 | |
| 66 | set_source_files_properties(${OUTPUT_PACKAGE} PROPERTIES GENERATED TRUE) |
| 67 | |
| 68 | if (DEFINED WSL_POST_BUILD_COMMAND) |
| 69 | add_custom_command( |
| 70 | TARGET msipackage |
| 71 | POST_BUILD |
| 72 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR} |
| 73 | USES_TERMINAL |
| 74 | COMMAND ${WSL_POST_BUILD_COMMAND} -BuildType ${CMAKE_BUILD_TYPE}) |
| 75 | endif() |