[test-suite] r372241 - Support for codesigning executables on Darwin
Chris Matthews via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 11:11:25 PDT 2019
Author: cmatthews
Date: Wed Sep 18 11:11:25 2019
New Revision: 372241
URL: http://llvm.org/viewvc/llvm-project?rev=372241&view=rev
Log:
Support for codesigning executables on Darwin
Mirror LLVM's cmake llvm_codesign function into the test-suite and apply
to all executables.
Modified:
test-suite/trunk/CMakeLists.txt
test-suite/trunk/cmake/modules/Host.cmake
test-suite/trunk/cmake/modules/TestSuite.cmake
test-suite/trunk/tools/CMakeLists.txt
Modified: test-suite/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/CMakeLists.txt?rev=372241&r1=372240&r2=372241&view=diff
==============================================================================
--- test-suite/trunk/CMakeLists.txt (original)
+++ test-suite/trunk/CMakeLists.txt Wed Sep 18 11:11:25 2019
@@ -25,6 +25,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TE
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
+set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING
+ "Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")
+
add_definitions(-DNDEBUG)
option(TEST_SUITE_SUPPRESS_WARNINGS "Suppress all warnings" ON)
if(${TEST_SUITE_SUPPRESS_WARNINGS})
Modified: test-suite/trunk/cmake/modules/Host.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/Host.cmake?rev=372241&r1=372240&r2=372241&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/Host.cmake (original)
+++ test-suite/trunk/cmake/modules/Host.cmake Wed Sep 18 11:11:25 2019
@@ -31,4 +31,6 @@ function(llvm_add_host_executable target
)
add_custom_target(${targetname}
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${exename}")
+ llvm_codesign(${targetname}
+ BUNDLE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${exename}")
endfunction()
Modified: test-suite/trunk/cmake/modules/TestSuite.cmake
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/cmake/modules/TestSuite.cmake?rev=372241&r1=372240&r2=372241&view=diff
==============================================================================
--- test-suite/trunk/cmake/modules/TestSuite.cmake (original)
+++ test-suite/trunk/cmake/modules/TestSuite.cmake Wed Sep 18 11:11:25 2019
@@ -58,6 +58,7 @@ function(llvm_test_executable_no_test ta
append_target_flags(LINK_LIBRARIES ${target} -fprofile-instr-use=${target_path}.profdata)
endif()
+ llvm_codesign(${target})
set_property(GLOBAL APPEND PROPERTY TEST_SUITE_TARGETS ${target})
test_suite_add_build_dependencies(${target})
endfunction()
@@ -125,3 +126,53 @@ function(append_target_flags propertynam
set_target_properties(${target} PROPERTIES ${propertyname} "${new_flags}")
endif()
endfunction()
+
+# Usage: llvm_codesign(name [FORCE] [ENTITLEMENTS file] [BUNDLE_PATH path])
+function(llvm_codesign name)
+ cmake_parse_arguments(ARG "FORCE" "ENTITLEMENTS;BUNDLE_PATH" "" ${ARGN})
+ if(NOT LLVM_CODESIGNING_IDENTITY)
+ return()
+ endif()
+
+ if(CMAKE_GENERATOR STREQUAL "Xcode")
+ set_target_properties(${name} PROPERTIES
+ XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${LLVM_CODESIGNING_IDENTITY}
+ )
+ if(DEFINED ARG_ENTITLEMENTS)
+ set_target_properties(${name} PROPERTIES
+ XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS ${ARG_ENTITLEMENTS}
+ )
+ endif()
+ elseif(APPLE AND CMAKE_HOST_SYSTEM_NAME MATCHES Darwin)
+ 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()
+ if(DEFINED ARG_ENTITLEMENTS)
+ set(pass_entitlements --entitlements ${ARG_ENTITLEMENTS})
+ endif()
+
+ if (NOT ARG_BUNDLE_PATH)
+ set(ARG_BUNDLE_PATH $<TARGET_FILE:${name}>)
+ endif()
+
+ if(ARG_FORCE)
+ set(force_flag "-f")
+ endif()
+
+ add_custom_command(
+ TARGET ${name} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E
+ env CODESIGN_ALLOCATE=${CMAKE_CODESIGN_ALLOCATE}
+ ${CMAKE_CODESIGN} -s ${LLVM_CODESIGNING_IDENTITY}
+ ${pass_entitlements} ${force_flag} ${ARG_BUNDLE_PATH}
+ COMMENT "Codesign ${name}"
+ )
+ endif()
+endfunction()
Modified: test-suite/trunk/tools/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/tools/CMakeLists.txt?rev=372241&r1=372240&r2=372241&view=diff
==============================================================================
--- test-suite/trunk/tools/CMakeLists.txt (original)
+++ test-suite/trunk/tools/CMakeLists.txt Wed Sep 18 11:11:25 2019
@@ -8,6 +8,7 @@
include(Host)
add_executable(fpcmp-target ${CMAKE_CURRENT_SOURCE_DIR}/fpcmp.c)
+llvm_codesign(fpcmp-target)
add_executable(build-fpcmp-target ALIAS fpcmp-target)
llvm_add_host_executable(build-fpcmp fpcmp fpcmp.c)
@@ -34,6 +35,7 @@ if(TEST_SUITE_USE_PERF)
add_custom_target(build-timeit-target DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/timeit-target)
else()
add_executable(timeit-target ${CMAKE_CURRENT_SOURCE_DIR}/timeit.c)
+ llvm_codesign(timeit-target)
add_executable(build-timeit-target ALIAS timeit-target)
llvm_add_host_executable(build-timeit timeit timeit.c)
endif()
More information about the llvm-commits
mailing list