aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Matthews <cmatthews5@apple.com>2019-09-18 18:11:25 +0000
committerChris Matthews <cmatthews5@apple.com>2019-09-18 18:11:25 +0000
commit8f3667acb3a6438c8088302b94a8bdbf7662623f (patch)
tree0435734c53e4709f381045534af9683515896cc4
parent52d4b12f6e5833eb4eec7ee2e57120b34c87550b (diff)
downloadtest-suite-8f3667acb3a6438c8088302b94a8bdbf7662623f.tar.gz
Support for codesigning executables on Darwin
Mirror LLVM's cmake llvm_codesign function into the test-suite and apply to all executables. git-svn-id: https://llvm.org/svn/llvm-project/test-suite/trunk@372241 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CMakeLists.txt3
-rw-r--r--cmake/modules/Host.cmake2
-rw-r--r--cmake/modules/TestSuite.cmake51
-rw-r--r--tools/CMakeLists.txt2
4 files changed, 58 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2d058770..edb3167d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,6 +25,9 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
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})
diff --git a/cmake/modules/Host.cmake b/cmake/modules/Host.cmake
index 6a00b301..ef81deeb 100644
--- a/cmake/modules/Host.cmake
+++ b/cmake/modules/Host.cmake
@@ -31,4 +31,6 @@ function(llvm_add_host_executable targetname exename)
)
add_custom_target(${targetname}
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${exename}")
+ llvm_codesign(${targetname}
+ BUNDLE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${exename}")
endfunction()
diff --git a/cmake/modules/TestSuite.cmake b/cmake/modules/TestSuite.cmake
index b87a06ce..e09a85eb 100644
--- a/cmake/modules/TestSuite.cmake
+++ b/cmake/modules/TestSuite.cmake
@@ -58,6 +58,7 @@ function(llvm_test_executable_no_test target)
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 propertyname target)
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()
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 20f35a7b..e0f3f1b8 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -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()