forked from OSchip/llvm-project
[CMake] Teach the build system to codesign built products
Automatically codesign all executables and dynamic libraries if a codesigning identity is given (via LLVM_CODESIGNING_IDENTITY). This option is darwin only for now. Also update platforms/iOS.cmake to pick up the right versions of codesign and codesign_allocate. llvm-svn: 336708
This commit is contained in:
parent
2ad2c18b82
commit
8fa2608493
|
@ -429,6 +429,9 @@ option(LLVM_USE_OPROFILE
|
|||
option(LLVM_EXTERNALIZE_DEBUGINFO
|
||||
"Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
|
||||
|
||||
option(LLVM_CODESIGNING_IDENTITY
|
||||
"Sign executables and dylibs with the given identity (Darwin Only)" OFF)
|
||||
|
||||
# If enabled, verify we are on a platform that supports oprofile.
|
||||
if( LLVM_USE_OPROFILE )
|
||||
if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
|
||||
|
|
|
@ -580,6 +580,7 @@ function(llvm_add_library name)
|
|||
|
||||
if(ARG_SHARED OR ARG_MODULE)
|
||||
llvm_externalize_debuginfo(${name})
|
||||
llvm_codesign(${name})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
@ -784,6 +785,8 @@ macro(add_llvm_executable name)
|
|||
# API for all shared libaries loaded by this executable.
|
||||
target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
|
||||
endif()
|
||||
|
||||
llvm_codesign(${name})
|
||||
endmacro(add_llvm_executable name)
|
||||
|
||||
function(export_executable_symbols target)
|
||||
|
@ -1590,6 +1593,32 @@ function(llvm_externalize_debuginfo name)
|
|||
endif()
|
||||
endfunction()
|
||||
|
||||
function(llvm_codesign name)
|
||||
if(NOT LLVM_CODESIGNING_IDENTITY)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
if(NOT CMAKE_CODESIGN)
|
||||
set(CMAKE_CODESIGN xcrun codesign)
|
||||
endif()
|
||||
if(NOT CMAKE_CODESIGN_ALLOCATE)
|
||||
execute_process(
|
||||
COMMAND xcrun -f codesign_allocate
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
|
||||
)
|
||||
endif()
|
||||
add_custom_command(
|
||||
TARGET ${name} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E
|
||||
env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
|
||||
${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY}
|
||||
$<TARGET_FILE:${name}>
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(llvm_setup_rpath name)
|
||||
if(CMAKE_INSTALL_RPATH)
|
||||
return()
|
||||
|
|
|
@ -80,3 +80,23 @@ IF(NOT CMAKE_LIBTOOL)
|
|||
SET(CMAKE_LIBTOOL ${CMAKE_LIBTOOL_val} CACHE FILEPATH "Libtool")
|
||||
message(STATUS "Using libtool ${CMAKE_LIBTOOL}")
|
||||
ENDIF()
|
||||
|
||||
IF(NOT CMAKE_CODESIGN)
|
||||
execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find codesign
|
||||
OUTPUT_VARIABLE CMAKE_CODESIGN_val
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
SET(CMAKE_CODESIGN ${CMAKE_CODESIGN_val} CACHE FILEPATH "Codesign")
|
||||
message(STATUS "Using codesign ${CMAKE_CODESIGN}")
|
||||
ENDIF()
|
||||
|
||||
IF(NOT CMAKE_CODESIGN_ALLOCATE)
|
||||
execute_process(
|
||||
COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find codesign_allocate
|
||||
OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE_val
|
||||
ERROR_QUIET
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
SET(CMAKE_CODESIGN_ALLOCATE ${CMAKE_CODESIGN_ALLOCATE_val} CACHE
|
||||
FILEPATH "Codesign_Allocate")
|
||||
message(STATUS "Using codesign_allocate ${CMAKE_CODESIGN_ALLOCATE}")
|
||||
ENDIF()
|
||||
|
|
Loading…
Reference in New Issue