From 483db3de5612360a321f8de9247059bcf5567d00 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 19 Feb 2021 16:28:04 -0500 Subject: Tests: Clarify internal project name in RunCMake.GoogleTest cases --- Tests/RunCMake/GoogleTest/GoogleTest.cmake | 2 +- Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake | 2 +- Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake | 2 +- Tests/RunCMake/GoogleTest/GoogleTestXML.cmake | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake index 6aa2658..b41df47 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTest.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake @@ -1,4 +1,4 @@ -project(test_include_dirs LANGUAGES CXX) +enable_language(CXX) include(GoogleTest) enable_testing() diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake index df784fe..e50648c 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake @@ -1,4 +1,4 @@ -project(test_include_dirs LANGUAGES CXX) +enable_language(CXX) include(GoogleTest) enable_testing() diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake index 20e9d65..cc614de 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake @@ -1,4 +1,4 @@ -project(test_include_dirs LANGUAGES CXX) +enable_language(CXX) include(GoogleTest) enable_testing() diff --git a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake index fb91c0e..74b2c3f 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake @@ -1,4 +1,4 @@ -project(test_include_dirs LANGUAGES CXX) +enable_language(CXX) include(GoogleTest) enable_testing() -- cgit v0.12 From 8b22d9b3c305c63c706048704d4211b504f46457 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 22 Feb 2021 12:20:52 -0500 Subject: Tests: Remove explicit no-signing marks from BundleTest These were added by commit e29a92f525 (Xcode: Make BundleTests compatible with Xcode 11, 2019-09-01, v3.16.0-rc1~158^2). The real problem is that the `.app` is constructed with text files under the `.app/Contents/MacOS/` folder. Move those, and drop the special no-signing configuration. --- Tests/BundleTest/BundleLib.cxx | 4 ++-- Tests/BundleTest/BundleSubDir/CMakeLists.txt | 8 ++------ Tests/BundleTest/CMakeLists.txt | 8 ++------ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/Tests/BundleTest/BundleLib.cxx b/Tests/BundleTest/BundleLib.cxx index b7fd70d..d25ad27 100644 --- a/Tests/BundleTest/BundleLib.cxx +++ b/Tests/BundleTest/BundleLib.cxx @@ -52,8 +52,8 @@ int foo(char* exec) (void)br; int res1 = findBundleFile(exec, "Resources/randomResourceFile.plist"); - int res2 = findBundleFile(exec, "MacOS/SomeRandomFile.txt"); - int res3 = findBundleFile(exec, "MacOS/README.rst"); + int res2 = findBundleFile(exec, "Other/SomeRandomFile.txt"); + int res3 = findBundleFile(exec, "Other/README.rst"); if (!res1 || !res2 || !res3) { return 1; } diff --git a/Tests/BundleTest/BundleSubDir/CMakeLists.txt b/Tests/BundleTest/BundleSubDir/CMakeLists.txt index 5f91f20..ceb5216 100644 --- a/Tests/BundleTest/BundleSubDir/CMakeLists.txt +++ b/Tests/BundleTest/BundleSubDir/CMakeLists.txt @@ -16,7 +16,7 @@ set_source_files_properties( "${BundleTest_SOURCE_DIR}/SomeRandomFile.txt" "${BundleTest_SOURCE_DIR}/../../README.rst" PROPERTIES - MACOSX_PACKAGE_LOCATION MacOS + MACOSX_PACKAGE_LOCATION Other ) add_executable(SecondBundle @@ -35,11 +35,7 @@ install(TARGETS SecondBundle DESTINATION Applications) # installed into a location that uses this output name this will fail if the # bundle does not respect the name. Also the executable will not be found by # the test driver if this does not work. -set_target_properties(SecondBundle PROPERTIES - OUTPUT_NAME SecondBundleExe - XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" - XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO" - ) +set_target_properties(SecondBundle PROPERTIES OUTPUT_NAME SecondBundleExe) # Express one app bundle in terms of another's SOURCES to verify that # the generators do not expose the Info.plist of one to the other. diff --git a/Tests/BundleTest/CMakeLists.txt b/Tests/BundleTest/CMakeLists.txt index 1bedc70..9c36eec 100644 --- a/Tests/BundleTest/CMakeLists.txt +++ b/Tests/BundleTest/CMakeLists.txt @@ -19,7 +19,7 @@ set_source_files_properties( SomeRandomFile.txt "${BundleTest_SOURCE_DIR}/../../README.rst" PROPERTIES - MACOSX_PACKAGE_LOCATION MacOS + MACOSX_PACKAGE_LOCATION Other ) set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/foobar") @@ -56,11 +56,7 @@ install(TARGETS BundleTest DESTINATION Applications) # installed into a location that uses this output name this will fail if the # bundle does not respect the name. Also the executable will not be found by # the test driver if this does not work. -set_target_properties(BundleTest PROPERTIES - OUTPUT_NAME BundleTestExe - XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "" - XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO" - ) +set_target_properties(BundleTest PROPERTIES OUTPUT_NAME BundleTestExe) # Test executable versioning if it is supported. if(NOT XCODE) -- cgit v0.12 From 92418ac0efc1a0f9edebf6d26a9d2db97ea658d6 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 22 Feb 2021 13:29:07 -0500 Subject: Tests: Fix CTestTestCrash expected output on macOS arm64 --- Tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 4ed902c..8e7c04f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -2955,7 +2955,7 @@ if(BUILD_TESTING) PASS_REGULAR_EXPRESSION "Failed") else() set_tests_properties(CTestTestCrash PROPERTIES - PASS_REGULAR_EXPRESSION "(Illegal|SegFault|Subprocess aborted)") + PASS_REGULAR_EXPRESSION "(Illegal|SegFault|Subprocess aborted|SIGTRAP)") endif() configure_file( -- cgit v0.12 From 1c15eb39d22db769386301bb192ca6423060c08c Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 22 Feb 2021 13:04:34 -0500 Subject: 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 --- Tests/BundleTest/CMakeLists.txt | 9 +++++++++ Tests/BundleUtilities/CMakeLists.txt | 9 +++++++++ Tests/RunCMake/GoogleTest/GoogleTest.cmake | 6 ++++++ Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake | 3 +++ Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake | 3 +++ Tests/RunCMake/GoogleTest/GoogleTestXML.cmake | 3 +++ Tests/RunCMake/GoogleTest/xcode_sign_adhoc.cmake | 8 ++++++++ Tests/RunCMake/ObjectLibrary/LinkObjLHSShared.cmake | 6 ++++++ 8 files changed, 47 insertions(+) create mode 100644 Tests/RunCMake/GoogleTest/xcode_sign_adhoc.cmake diff --git a/Tests/BundleTest/CMakeLists.txt b/Tests/BundleTest/CMakeLists.txt index 9c36eec..c63461a 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 ") +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 6020644..4a95e2f 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 b41df47..8efd117 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 e50648c..2fae1e2 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 $<$:DEBUG=1>) gtest_discover_tests( diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake index cc614de..5c24d41 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 74b2c3f..53eedc0 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 0000000..d2dc530 --- /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 0a76932..3d60556 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) -- cgit v0.12