Skip to content

Commit

Permalink
CMake: Add windows codesigning support
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Nov 25, 2020
1 parent b4ba317 commit 7e52cb8
Showing 1 changed file with 61 additions and 8 deletions.
69 changes: 61 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1089,17 +1089,70 @@ if (APPLE)
execute_process(COMMAND chmod +x "${CMAKE_CURRENT_BINARY_DIR}/run-mixxx.sh")
endif()
else()
include(InstallRequiredSystemLibraries)
install(
FILES
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
DESTINATION
"${MIXXX_INSTALL_BINDIR}"
COMPONENT
Libraries
include(InstallRequiredSystemLibraries)
install(
FILES
${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
DESTINATION
"${MIXXX_INSTALL_BINDIR}"
COMPONENT
Libraries
)
endif()

option(WINDOWS_CODESIGN "Sign executables and libraries with digital certificate" OFF)
mark_as_advanced(WINDOWS_CODESIGN)
if(WINDOWS_CODESIGN)
set(WINDOWS_CODESIGN_ARGS /a /t http://timestamp.verisign.com/scripts/timstamp.dll CACHE STRING "parameters for signtool (list)")
find_program(SIGNTOOL_EXECUTABLE signtool)
if(NOT SIGNTOOL_EXECUTABLE)
message(FATAL_ERROR "signtool is not found. Signing executables not possible")
endif()

# Check if we're able to sign an executable
if(NOT DEFINED WINDOWS_CODESIGN_OK)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/testsign.c "int main(){return 0;}")
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testsign)
try_compile(
RESULT ${CMAKE_CURRENT_BINARY_DIR}/testsign ${CMAKE_CURRENT_BINARY_DIR}/testsign.c
COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/testsign.exe
)
execute_process(
COMMAND ${SIGNTOOL_EXECUTABLE} sign ${SIGNTOOL_PARAMETERS} ${CMAKE_CURRENT_BINARY_DIR}/testsign.exe
RESULT_VARIABLE ERR ERROR_QUIET OUTPUT_QUIET
)
if(ERR EQUAL 0)
message(STATUS "Windows codesigning via signtool enabled")
set(WINDOWS_CODESIGN_OK 1 CACHE INTERNAL "Can sign executables")
else()
message(WARNING "Windows codesigning via signtool is not working and has been disabled")
set(WINDOWS_CODESIGN_OK 0 CACHE INTERNAL "Invalid or missing certificate")
endif()
endif()
mark_as_advanced(SIGNTOOL_EXECUTABLE SIGNTOOL_ARGS)
endif()

macro(windows_codesign_target TARGET)
get_target_property(TARGET_TYPE ${target} TYPE)
if(TARGET_TYPE AND NOT TARGET_TYPE MATCHES "STATIC")
get_target_property(TARGET_LOCATION ${target} LOCATION)
if(CMAKE_GENERATOR MATCHES "Visual Studio")
string(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}" TARGET_LOCATION ${TARGET_LOCATION})
endif()
install(CODE
"execute_process(COMMAND ${SIGNTOOL_EXECUTABLE} sign ${WINDOWS_CODESIGN_ARGS} ${TARGET_LOCATION} RESULT_VARIABLE ERR)
if(NOT \${ERR} EQUAL 0)
message(FATAL_ERROR \"Error signing ${TARGET_LOCATION}\")
endif()
")
endif()
ENDMACRO()

if(WINDOWS_CODESIGN AND WINDOWS_CODESIGN_OK)
windows_codesign_target(mixxx)
endif()


install(
TARGETS
mixxx
Expand Down

0 comments on commit 7e52cb8

Please sign in to comment.