llvm.org GIT mirror llvm / 7613264
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336708 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 1 year, 3 months ago
3 changed file(s) with 52 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
428428 option(LLVM_EXTERNALIZE_DEBUGINFO
429429 "Generate dSYM files and strip executables and libraries (Darwin Only)" OFF)
430430
431 option(LLVM_CODESIGNING_IDENTITY
432 "Sign executables and dylibs with the given identity (Darwin Only)" OFF)
433
431434 # If enabled, verify we are on a platform that supports oprofile.
432435 if( LLVM_USE_OPROFILE )
433436 if( NOT CMAKE_SYSTEM_NAME MATCHES "Linux" )
579579
580580 if(ARG_SHARED OR ARG_MODULE)
581581 llvm_externalize_debuginfo(${name})
582 llvm_codesign(${name})
582583 endif()
583584 endfunction()
584585
783784 # API for all shared libaries loaded by this executable.
784785 target_link_libraries(${name} PRIVATE ${LLVM_PTHREAD_LIB})
785786 endif()
787
788 llvm_codesign(${name})
786789 endmacro(add_llvm_executable name)
787790
788791 function(export_executable_symbols target)
15891592 endif()
15901593 endfunction()
15911594
1595 function(llvm_codesign name)
1596 if(NOT LLVM_CODESIGNING_IDENTITY)
1597 return()
1598 endif()
1599
1600 if(APPLE)
1601 if(NOT CMAKE_CODESIGN)
1602 set(CMAKE_CODESIGN xcrun codesign)
1603 endif()
1604 if(NOT CMAKE_CODESIGN_ALLOCATE)
1605 execute_process(
1606 COMMAND xcrun -f codesign_allocate
1607 OUTPUT_STRIP_TRAILING_WHITESPACE
1608 OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE
1609 )
1610 endif()
1611 add_custom_command(
1612 TARGET ${name} POST_BUILD
1613 COMMAND ${CMAKE_COMMAND} -E
1614 env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
1615 ${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY}
1616 $
1617 )
1618 endif()
1619 endfunction()
1620
15921621 function(llvm_setup_rpath name)
15931622 if(CMAKE_INSTALL_RPATH)
15941623 return()
7979 SET(CMAKE_LIBTOOL ${CMAKE_LIBTOOL_val} CACHE FILEPATH "Libtool")
8080 message(STATUS "Using libtool ${CMAKE_LIBTOOL}")
8181 ENDIF()
82
83 IF(NOT CMAKE_CODESIGN)
84 execute_process(COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find codesign
85 OUTPUT_VARIABLE CMAKE_CODESIGN_val
86 ERROR_QUIET
87 OUTPUT_STRIP_TRAILING_WHITESPACE)
88 SET(CMAKE_CODESIGN ${CMAKE_CODESIGN_val} CACHE FILEPATH "Codesign")
89 message(STATUS "Using codesign ${CMAKE_CODESIGN}")
90 ENDIF()
91
92 IF(NOT CMAKE_CODESIGN_ALLOCATE)
93 execute_process(
94 COMMAND xcrun -sdk ${CMAKE_OSX_SYSROOT} -find codesign_allocate
95 OUTPUT_VARIABLE CMAKE_CODESIGN_ALLOCATE_val
96 ERROR_QUIET
97 OUTPUT_STRIP_TRAILING_WHITESPACE)
98 SET(CMAKE_CODESIGN_ALLOCATE ${CMAKE_CODESIGN_ALLOCATE_val} CACHE
99 FILEPATH "Codesign_Allocate")
100 message(STATUS "Using codesign_allocate ${CMAKE_CODESIGN_ALLOCATE}")
101 ENDIF()