CMakeInstallSignTool.cmake.in 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # The signtool. Default to PATH.
  2. set(CMake_INSTALL_SIGNTOOL "@CMake_INSTALL_SIGNTOOL@")
  3. if(NOT CMake_INSTALL_SIGNTOOL)
  4. set(CMake_INSTALL_SIGNTOOL signtool)
  5. endif()
  6. # Select a certificate by Subject Name. Default to automatic selection.
  7. set(CMake_INSTALL_SIGNTOOL_SUBJECT_NAME "@CMake_INSTALL_SIGNTOOL_SUBJECT_NAME@")
  8. if(CMake_INSTALL_SIGNTOOL_SUBJECT_NAME)
  9. set(select_cert -n "${CMake_INSTALL_SIGNTOOL_SUBJECT_NAME}")
  10. else()
  11. set(select_cert -a)
  12. endif()
  13. # Timestamp URL. Default to a common provider.
  14. set(CMake_INSTALL_SIGNTOOL_TIMESTAMP_URL "@CMake_INSTALL_SIGNTOOL_TIMESTAMP_URL@")
  15. if(NOT CMake_INSTALL_SIGNTOOL_TIMESTAMP_URL)
  16. set(CMake_INSTALL_SIGNTOOL_TIMESTAMP_URL "http://timestamp.digicert.com")
  17. endif()
  18. # Glob files that need a signature.
  19. file(GLOB files "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/bin/*.exe")
  20. # Sign all files at once.
  21. if(files)
  22. # Run the signtool through 'cmd /c' to enable password prompt popup.
  23. # Some providers have trouble when signtool is invoked with SW_HIDE.
  24. set(cmd cmd /c "${CMake_INSTALL_SIGNTOOL}" sign -v ${select_cert})
  25. # Sign with SHA-1 for Windows 7 and below.
  26. execute_process(
  27. COMMAND ${cmd} -t "${CMake_INSTALL_SIGNTOOL_TIMESTAMP_URL}" ${files}
  28. RESULT_VARIABLE result
  29. ERROR_VARIABLE stderr
  30. )
  31. if(NOT result EQUAL 0)
  32. string(REPLACE "\n" "\n " stderr " ${stderr}")
  33. message(WARNING "signtool failed:\n${stderr}")
  34. endif()
  35. # Sign with SHA-256 for Windows 8 and above.
  36. execute_process(
  37. COMMAND ${cmd} -tr "${CMake_INSTALL_SIGNTOOL_TIMESTAMP_URL}" -fd sha256 -td sha256 -as ${files}
  38. RESULT_VARIABLE result
  39. ERROR_VARIABLE stderr
  40. )
  41. if(NOT result EQUAL 0)
  42. string(REPLACE "\n" "\n " stderr " ${stderr}")
  43. message(WARNING "signtool failed:\n${stderr}")
  44. endif()
  45. endif()