PackagingCodeSign_windows.cmake 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. function(ly_sign_binaries in_path in_path_type)
  9. message(STATUS "Executing package signing...")
  10. file(REAL_PATH "${CPACK_SOURCE_DIR}/.." _root_path)
  11. unset(_signing_command)
  12. cmake_path(SET _sign_script "${_root_path}/scripts/signer/Platform/Windows/signer.ps1")
  13. find_program(_psiexec_path psexec.exe)
  14. if(_psiexec_path)
  15. list(APPEND _signing_command
  16. ${_psiexec_path}
  17. -accepteula
  18. -nobanner
  19. -s
  20. )
  21. endif()
  22. find_program(_powershell_path powershell.exe REQUIRED)
  23. list(APPEND _signing_command
  24. ${_powershell_path}
  25. -NoLogo
  26. -ExecutionPolicy Bypass
  27. -File ${_sign_script}
  28. )
  29. # This requires to have a valid local certificate. In continuous integration, these certificates are stored
  30. # in the machine directly.
  31. # You can generate a test certificate to be able to run this in a PowerShell elevated promp with:
  32. # New-SelfSignedCertificate -DnsName foo.o3de.com -Type CodeSigning -CertStoreLocation Cert:\CurrentUser\My
  33. # Export-Certificate -Cert (Get-ChildItem Cert:\CurrentUser\My\<cert thumbprint>) -Filepath "c:\selfsigned.crt"
  34. # Import-Certificate -FilePath "c:\selfsigned.crt" -Cert Cert:\CurrentUser\TrustedPublisher
  35. # Import-Certificate -FilePath "c:\selfsigned.crt" -Cert Cert:\CurrentUser\Root
  36. message(STATUS "Signing ${in_path_type} files in ${in_path}")
  37. execute_process(
  38. COMMAND ${_signing_command} -${in_path_type} ${in_path}
  39. RESULT_VARIABLE _signing_result
  40. ERROR_VARIABLE _signing_errors
  41. OUTPUT_VARIABLE _signing_output
  42. ECHO_OUTPUT_VARIABLE
  43. )
  44. if(NOT ${_signing_result} EQUAL 0)
  45. message(FATAL_ERROR "An error occurred during signing files for ${in_path_type}. ${_signing_errors}")
  46. else()
  47. message(STATUS "Signing complete!")
  48. endif()
  49. endfunction()