cmake: Windows codesigning refactor.

Quote variables containing the HOME or USERPROFILE, as they may have
spaces.

Check for both osslsigncode and signtool regardless of platform, and
prefer osslsigncode.

The reason for this being that osslsigncode is more reliable and does
not depend on system configuration in any way, while signtool can fail
under more conditions.

The other reason being that you can use either program on both windows
and linux. E.g. the mingw version of osslsigncode or the signtool from
mono distributions on linux.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2020-03-13 00:30:26 +00:00
parent 7a4a7d148c
commit 6c64db0794
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 21 additions and 26 deletions

View File

@ -1007,42 +1007,37 @@ endif()
option(UPSTREAM_RELEASE "do some release automation tasks" OFF) option(UPSTREAM_RELEASE "do some release automation tasks" OFF)
if(UPSTREAM_RELEASE AND WIN32) if(UPSTREAM_RELEASE AND WIN32)
set(home $ENV{HOME}) set(home "$ENV{HOME}")
if(NOT CMAKE_CROSSCOMPILING AND NOT DEFINED ENV{MSYSTEM_PREFIX}) if(NOT CMAKE_CROSSCOMPILING AND NOT DEFINED ENV{MSYSTEM_PREFIX})
set(home $ENV{USERPROFILE}) set(home "$ENV{USERPROFILE}")
endif() endif()
# rewrite backslashes to slashes, needed for msys osslsigncode # rewrite backslashes to slashes, needed for msys osslsigncode
string(REGEX REPLACE "\\\\" "/" home ${home}) string(REGEX REPLACE "\\\\" "/" home "${home}")
set(cert ${home}/.codesign/windows_comodo.pkcs12) set(cert "${home}/.codesign/windows_comodo.pkcs12")
if(EXISTS ${cert}) if(EXISTS "${cert}")
if(MSVC) find_program(OSSLSIGNCODE_PROGRAM osslsigncode)
find_program(SIGNTOOL_PROGRAM signtool) find_program(SIGNTOOL_PROGRAM signtool)
if(SIGNTOOL_PROGRAM) if(OSSLSIGNCODE_PROGRAM)
add_custom_command( add_custom_command(
TARGET visualboyadvance-m TARGET visualboyadvance-m
POST_BUILD POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy visualboyadvance-m.exe visualboyadvance-m-unsigned.exe COMMAND ${CMAKE_COMMAND} -E rename visualboyadvance-m.exe visualboyadvance-m-unsigned.exe
COMMAND ${SIGNTOOL_PROGRAM} sign /f ${cert} /p "vbam3!13" /tr http://timestamp.digicert.com /du https://github.com/visualboyadvance-m/visualboyadvance-m /a visualboyadvance-m.exe COMMAND ${OSSLSIGNCODE_PROGRAM} sign -pkcs12 ${cert} -pass "vbam3!13" -t http://timestamp.digicert.com -n visualboyadvance-m -i https://github.com/visualboyadvance-m/visualboyadvance-m -in visualboyadvance-m-unsigned.exe -out visualboyadvance-m.exe
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
) )
endif() elseif(SIGNTOOL_PROGRAM)
else() add_custom_command(
find_program(OSSLSIGNCODE_PROGRAM osslsigncode) TARGET visualboyadvance-m
POST_BUILD
if(OSSLSIGNCODE_PROGRAM) COMMAND ${CMAKE_COMMAND} -E copy visualboyadvance-m.exe visualboyadvance-m-unsigned.exe
add_custom_command( COMMAND ${SIGNTOOL_PROGRAM} sign /f ${cert} /p "vbam3!13" /tr http://timestamp.digicert.com /du https://github.com/visualboyadvance-m/visualboyadvance-m /a visualboyadvance-m.exe
TARGET visualboyadvance-m WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename visualboyadvance-m.exe visualboyadvance-m-unsigned.exe
COMMAND ${OSSLSIGNCODE_PROGRAM} sign -pkcs12 ${cert} -pass "vbam3!13" -t http://timestamp.digicert.com -n visualboyadvance-m -i https://github.com/visualboyadvance-m/visualboyadvance-m -in visualboyadvance-m-unsigned.exe -out visualboyadvance-m.exe
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
) )
endif()
endif() endif()
endif() endif()