-
Notifications
You must be signed in to change notification settings - Fork 4
/
sign_target.cmake
61 lines (56 loc) · 1.42 KB
/
sign_target.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
get_filename_component(
WINDOWS_10_KITS_ROOT
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]"
ABSOLUTE CACHE
)
set(WINDOWS_10_KIT_DIR "${WINDOWS_10_KITS_ROOT}/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" CACHE PATH "Current Windows 10 kit directory")
set(SIGNTOOL_KEY_ARGS "" CACHE STRING "Key arguments for signtool.exe - separate with ';'")
find_program(
SIGNTOOL_EXE
signtool
PATHS
"${WINDOWS_10_KIT_DIR}/x64"
"${WINDOWS_10_KIT_DIR}/x86"
DOC "Path to signtool.exe if SIGNTOOL_KEY_ARGS is set"
)
function(sign_target_file TARGET FILE)
if(SIGNTOOL_KEY_ARGS AND WIN32)
add_custom_command(
TARGET ${TARGET} POST_BUILD
COMMAND
"${SIGNTOOL_EXE}"
ARGS
sign
${SIGNTOOL_KEY_ARGS}
/t http://timestamp.digicert.com
/fd SHA256
"${FILE}"
)
endif()
endfunction()
function(sign_target TARGET)
sign_target_file("${TARGET}" "$<TARGET_FILE:${TARGET}>")
endfunction()
macro(add_signed_script TARGET SOURCE)
add_custom_target(
${TARGET}
ALL
COMMAND
"${CMAKE_COMMAND}"
-E
copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}"
"${CMAKE_CURRENT_BINARY_DIR}/${SOURCE}"
SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}"
)
sign_target_file(
${TARGET}
"${CMAKE_CURRENT_BINARY_DIR}/${SOURCE}"
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${SOURCE}"
${ARGN}
)
endmacro()