diff options
author | Brad King <brad.king@kitware.com> | 2021-02-22 13:04:34 -0500 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-02-22 15:47:13 -0800 |
commit | 1c15eb39d22db769386301bb192ca6423060c08c (patch) | |
tree | 9799feef63ae450b074de2034548452c94d26d15 | |
parent | 92418ac0efc1a0f9edebf6d26a9d2db97ea658d6 (diff) | |
download | cmake-1c15eb39d22db769386301bb192ca6423060c08c.tar.gz |
Tests: Suppress failures on macOS arm64 due to separate Xcode signing phase
Some tests fail because Xcode runs `POST_BUILD` commands before signing
the binaries they run. Tell the linker to perform ad-hoc codesign even
though Xcode normally tells it not to.
Other tests fail because `install_name_tool` does not revise ad-hoc
signatures without the codesign `linker-signed` flag. Add that flag
ourselves where needed by our tests.
For now these changes help our test suite pass so we can use it to cover
everything else. Both of these cases may need further investigation to
update CMake to help projects in general.
Issue: #21845, #21854
-rw-r--r-- | Tests/BundleTest/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/BundleUtilities/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/GoogleTest.cmake | 6 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/GoogleTestXML.cmake | 3 | ||||
-rw-r--r-- | Tests/RunCMake/GoogleTest/xcode_sign_adhoc.cmake | 8 | ||||
-rw-r--r-- | Tests/RunCMake/ObjectLibrary/LinkObjLHSShared.cmake | 6 |
8 files changed, 47 insertions, 0 deletions
diff --git a/Tests/BundleTest/CMakeLists.txt b/Tests/BundleTest/CMakeLists.txt index 9c36eec545..c63461a2c5 100644 --- a/Tests/BundleTest/CMakeLists.txt +++ b/Tests/BundleTest/CMakeLists.txt @@ -3,6 +3,15 @@ project(BundleTest) set(MACOSX_BUNDLE_INFO_STRING "bundle_info_string") set(CMAKE_MacOSX_Content_COMPILE_OBJECT "\"${CMAKE_COMMAND}\" -E copy_if_different <SOURCE> <OBJECT>") +if(CMAKE_GENERATOR STREQUAL "Xcode" AND + "${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64") + # Tell Xcode to pretend the linker signed binaries so that + # editing with install_name_tool preserves ad-hoc signatures. + # See CMake Issue 21854. + # This option is supported by codesign on macOS 11 or higher. + set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed") +endif() + add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/randomResourceFile.plist" COMMAND /bin/cp diff --git a/Tests/BundleUtilities/CMakeLists.txt b/Tests/BundleUtilities/CMakeLists.txt index 60206448ef..4a95e2fd4a 100644 --- a/Tests/BundleUtilities/CMakeLists.txt +++ b/Tests/BundleUtilities/CMakeLists.txt @@ -1,6 +1,15 @@ cmake_minimum_required(VERSION 2.8.12) project(BundleUtilities) +if(CMAKE_GENERATOR STREQUAL "Xcode" AND + "${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64") + # Tell Xcode to pretend the linker signed binaries so that + # editing with install_name_tool preserves ad-hoc signatures. + # See CMake Issue 21854. + # This option is supported by codesign on macOS 11 or higher. + set(CMAKE_XCODE_ATTRIBUTE_OTHER_CODE_SIGN_FLAGS "-o linker-signed") +endif() + ###### the various types of dependencies we can have # a shared library diff --git a/Tests/RunCMake/GoogleTest/GoogleTest.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake index b41df47e6d..8efd1171de 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTest.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake @@ -3,7 +3,10 @@ include(GoogleTest) enable_testing() +include(xcode_sign_adhoc.cmake) + add_executable(fake_gtest fake_gtest.cpp) +xcode_sign_adhoc(fake_gtest) gtest_discover_tests( fake_gtest @@ -22,6 +25,7 @@ gtest_discover_tests( ) add_executable(no_tests_defined no_tests_defined.cpp) +xcode_sign_adhoc(no_tests_defined) gtest_discover_tests( no_tests_defined @@ -33,6 +37,7 @@ gtest_discover_tests( # 3.10.3 and later behavior, old behavior added in 3.10.1 # is not supported. add_executable(property_timeout_test timeout_test.cpp) +xcode_sign_adhoc(property_timeout_test) target_compile_definitions(property_timeout_test PRIVATE sleepSec=10) gtest_discover_tests( @@ -50,6 +55,7 @@ gtest_discover_tests( ) add_executable(skip_test skip_test.cpp) +xcode_sign_adhoc(skip_test) gtest_discover_tests( skip_test diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake index e50648c718..2fae1e2332 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake @@ -3,7 +3,10 @@ include(GoogleTest) enable_testing() +include(xcode_sign_adhoc.cmake) + add_executable(configuration_gtest configuration_gtest.cpp) +xcode_sign_adhoc(configuration_gtest) target_compile_definitions(configuration_gtest PRIVATE $<$<CONFIG:Debug>:DEBUG=1>) gtest_discover_tests( diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake index cc614de44f..5c24d41186 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake @@ -3,7 +3,10 @@ include(GoogleTest) enable_testing() +include(xcode_sign_adhoc.cmake) + add_executable(discovery_timeout_test timeout_test.cpp) +xcode_sign_adhoc(discovery_timeout_test) target_compile_definitions(discovery_timeout_test PRIVATE discoverySleepSec=10) gtest_discover_tests( discovery_timeout_test diff --git a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake index 74b2c3f8fb..53eedc0414 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake @@ -3,6 +3,8 @@ include(GoogleTest) enable_testing() +include(xcode_sign_adhoc.cmake) + # This creates the folder structure for the paramterized tests # to avoid handling missing folders in C++ # @@ -15,6 +17,7 @@ enable_testing() file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/GoogleTestXMLSpecial/cases.case") add_executable(xml_output xml_output.cpp) +xcode_sign_adhoc(xml_output) gtest_discover_tests( xml_output XML_OUTPUT_DIR ${CMAKE_BINARY_DIR} diff --git a/Tests/RunCMake/GoogleTest/xcode_sign_adhoc.cmake b/Tests/RunCMake/GoogleTest/xcode_sign_adhoc.cmake new file mode 100644 index 0000000000..d2dc5305bb --- /dev/null +++ b/Tests/RunCMake/GoogleTest/xcode_sign_adhoc.cmake @@ -0,0 +1,8 @@ +function(xcode_sign_adhoc target) + if(CMAKE_GENERATOR STREQUAL "Xcode" AND + "${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64") + # Xcode runs POST_BUILD before signing, so let the linker use ad-hoc signing. + # See CMake Issue 21845. + target_link_options(${target} PRIVATE LINKER:-adhoc_codesign) + endif() +endfunction() diff --git a/Tests/RunCMake/ObjectLibrary/LinkObjLHSShared.cmake b/Tests/RunCMake/ObjectLibrary/LinkObjLHSShared.cmake index 0a76932ec5..3d60556bfc 100644 --- a/Tests/RunCMake/ObjectLibrary/LinkObjLHSShared.cmake +++ b/Tests/RunCMake/ObjectLibrary/LinkObjLHSShared.cmake @@ -12,4 +12,10 @@ add_executable(LinkObjLHSShared LinkObjLHSShared.c) target_link_libraries(LinkObjLHSShared AnObjLib) # Verify that our dependency on OtherLib generated its versioning symlinks. +if(CMAKE_GENERATOR STREQUAL "Xcode" AND + "${CMAKE_SYSTEM_NAME};${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "Darwin;arm64") + # Xcode runs POST_BUILD before signing, so let the linker use ad-hoc signing. + # See CMake Issue 21845. + target_link_options(LinkObjLHSShared PRIVATE LINKER:-adhoc_codesign) +endif() add_custom_command(TARGET LinkObjLHSShared POST_BUILD COMMAND LinkObjLHSShared) |