1# If timestamping is used, it can (rarely) fail, when public timestamping service has issues. 2# 3# To handle the error gracefully and tranparently, we'll retry the signtool command, 4# second time without "/t URL" parameter 5SET(SIGNTOOL_PARAMETERS_NO_TIMESTAMP "@SIGNTOOL_PARAMETERS@") 6LIST(FIND SIGNTOOL_PARAMETERS_NO_TIMESTAMP /t idx) 7IF(NOT(idx EQUAL -1)) 8 LIST(REMOVE_AT SIGNTOOL_PARAMETERS_NO_TIMESTAMP ${idx}) 9 #remove the URL following /t , as well 10 LIST(REMOVE_AT SIGNTOOL_PARAMETERS_NO_TIMESTAMP ${idx}) 11ENDIF() 12 13GET_FILENAME_COMPONENT(SIGNTOOL_DIR "@SIGNTOOL_EXECUTABLE@" DIRECTORY) 14GET_FILENAME_COMPONENT(SIGNTOOL_NAME "@SIGNTOOL_EXECUTABLE@" NAME) 15 16FILE(GLOB_RECURSE files "@CMAKE_BINARY_DIR@/*.signme") 17MESSAGE(STATUS "signing files") 18 19 20FOREACH(f ${files}) 21 STRING(REPLACE ".signme" "" exe_location "${f}") 22 23 string (REPLACE ";" " " params "@SIGNTOOL_PARAMETERS@") 24 25 EXECUTE_PROCESS(COMMAND 26 cmd /c "${SIGNTOOL_NAME}" sign @SIGNTOOL_PARAMETERS@ "${exe_location}" 2>NUL 27 || "${SIGNTOOL_NAME}" sign ${SIGNTOOL_PARAMETERS_NO_TIMESTAMP} "${exe_location}" 28 WORKING_DIRECTORY ${SIGNTOOL_DIR} 29 RESULT_VARIABLE ERR) 30 IF(NOT ${ERR} EQUAL 0) 31 MESSAGE( "Error ${ERR} signing ${exe_location}") 32 ELSE() 33 FILE(REMOVE ${f}) 34 ENDIF() 35 36ENDFOREACH() 37