-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodesigner.cmake
96 lines (73 loc) · 3.6 KB
/
Codesigner.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This file is part of DylibDeployer.cmake.
# DylibDeployer.cmake is free software: you can redistribute it and/or modify it under the terms
# of the GNU General Public License as published by the Free Software Foundation, either version
# 3 of the License, or (at your option) any later version.
# DylibDeployer.cmake is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with DylibDeployer.cmake.
# If not, see <https://www.gnu.org/licenses/>.
# Copyright 2023 ToKiNoBug
if (DEFINED CMAKE_GENERATOR)
#message(STATUS "Codesigner running at configuration time")
option(RCS_configure_time "Whether this script is running at configuration time" ON)
else ()
# Otherwise we guess that it's running at build or installation time.
#message(STATUS "Codesigner running at build/install time")
option(RCS_configure_time "Whether this script is running at configuration time" OFF)
endif ()
if(RCS_configure_time)
set(RCS_source_file ${CMAKE_CURRENT_LIST_FILE})
else()
set(RCS_this_file @rcs_this_file@)
set(RCS_bundle_name @rcs_bundle_name@)
set(RCS_bundle_version @rcs_bundle_version@)
set(RCS_working_dir . CACHE FILEPATH "")
set(RCS_install_dest @rcs_install_dest@)
if(NOT CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX @CMAKE_INSTALL_PREFIX@)
endif()
option(RCS_run_directly "" OFF)
endif()
function(RCS_add_codesign target)
cmake_parse_arguments(RCSac "" "INSTALL_DESTINATION" "" ${ARGN})
if(NOT RCSac_INSTALL_DESTINATION)
set(RCSac_INSTALL_DESTINATION .)
endif()
set(rcs_install_dest ${RCSac_INSTALL_DESTINATION})
set(rcs_this_file "${CMAKE_CURRENT_BINARY_DIR}/Codesigner_${target}.cmake")
set(rcs_bundle_name ${target})
get_target_property(rcs_bundle_version ${target} VERSION)
configure_file(${RCS_source_file}
${rcs_this_file}
@ONLY)
install(SCRIPT ${rcs_this_file}
DESTINATION .)
endfunction()
function(RCS_sign_configtime bundle working_dir)
message(STATUS "Signning \"${bundle}.app\"")
execute_process(COMMAND codesign --force --deep --sign=- "${bundle}.app"
WORKING_DIRECTORY "${working_dir}"
COMMAND_ERROR_IS_FATAL ANY)
endfunction()
if(NOT RCS_configure_time)
#message(STATUS "RCS_working_dir = \"${RCS_working_dir}\"")
if(NOT RCS_run_directly)
execute_process(COMMAND ${CMAKE_COMMAND} -DRCS_run_directly:BOOL=ON -DRCS_working_dir=${CMAKE_INSTALL_PREFIX}/${RCS_install_dest} -P ${RCS_this_file}
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/${RCS_install_dest}
COMMAND_ERROR_IS_FATAL ANY)
return()
endif()
set(bundle_prefix "${RCS_working_dir}/${RCS_bundle_name}.app/Contents/MacOS")
if(IS_SYMLINK "${bundle_prefix}/${RCS_bundle_name}")
message(STATUS "Found symlink file ${bundle_prefix}/${RCS_bundle_name}")
file(REMOVE "${bundle_prefix}/${RCS_bundle_name}")
file(RENAME "${bundle_prefix}/${RCS_bundle_name}-${RCS_bundle_version}" "${bundle_prefix}/${RCS_bundle_name}")
endif ()
if(IS_SYMLINK "${bundle_prefix}/${RCS_bundle_name}")
message(WARNING "\"${bundle_prefix}/${RCS_bundle_name}\" is a symlink, but it should be regular file.")
endif ()
execute_process(COMMAND codesign --force --deep --sign=- "${RCS_bundle_name}.app"
WORKING_DIRECTORY ${RCS_working_dir}
COMMAND_ERROR_IS_FATAL ANY)
endif()