ソースを参照

FindXCTest: Fix output directory for test bundle with Xcode 12.5

The fix from commit eafe740ead (FindXCTest: Fix output directory for
test bundle with new build system, 2021-02-09, v3.19.5~5^2) is not
necessary with Xcode 12.5, which seems to have changed/fixed the
behaviour again.

Fixes: #22462
Yauheni Khnykin 4 年 前
コミット
0b5301a778

+ 2 - 1
Modules/FindXCTest.cmake

@@ -156,8 +156,9 @@ function(xctest_add_bundle target testee)
         XCODE_ATTRIBUTE_BUNDLE_LOADER "$(TEST_HOST)"
         XCODE_ATTRIBUTE_BUNDLE_LOADER "$(TEST_HOST)"
         XCODE_ATTRIBUTE_TEST_HOST "$<TARGET_FILE:${testee}>")
         XCODE_ATTRIBUTE_TEST_HOST "$<TARGET_FILE:${testee}>")
       if(XCODE_VERSION VERSION_GREATER_EQUAL 7.3)
       if(XCODE_VERSION VERSION_GREATER_EQUAL 7.3)
-        # CMAKE_XCODE_BUILD_SYSTEM equals 12 means that at least Xcode 11.x is used.
+        # The Xcode "new build system" used a different path until Xcode 12.5.
         if(CMAKE_XCODE_BUILD_SYSTEM EQUAL 12 AND
         if(CMAKE_XCODE_BUILD_SYSTEM EQUAL 12 AND
+           XCODE_VERSION VERSION_LESS 12.5 AND
            NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
            NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
           set(_output_directory "$<TARGET_BUNDLE_CONTENT_DIR:${testee}>")
           set(_output_directory "$<TARGET_BUNDLE_CONTENT_DIR:${testee}>")
         else()
         else()

+ 8 - 3
Tests/RunCMake/XcodeProject/RunCMakeTest.cmake

@@ -407,11 +407,16 @@ if (XCODE_VERSION VERSION_GREATER_EQUAL 7.3)
   if(XCODE_VERSION VERSION_GREATER_EQUAL 12)
   if(XCODE_VERSION VERSION_GREATER_EQUAL 12)
     xctest_add_bundle_test(Darwin macosx "1" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
     xctest_add_bundle_test(Darwin macosx "1" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
     xctest_add_bundle_test(Darwin macosx "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
     xctest_add_bundle_test(Darwin macosx "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
-    xctest_add_bundle_test(iOS iphoneos "1" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
-    xctest_add_bundle_test(iOS iphoneos "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>")
+    xctest_add_bundle_test(iOS iphonesimulator "1" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
+    if (XCODE_VERSION VERSION_LESS 12.5)
+      xctest_add_bundle_test(iOS iphonesimulator "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>")
+    else()
+      xctest_add_bundle_test(iOS iphonesimulator "12" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
+    endif()
   else()
   else()
     xctest_add_bundle_test(Darwin macosx "" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
     xctest_add_bundle_test(Darwin macosx "" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
-    xctest_add_bundle_test(iOS iphoneos "" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
+    xctest_add_bundle_test(iOS iphonesimulator "" "$<TARGET_BUNDLE_CONTENT_DIR:TestedApp>/PlugIns")
   endif()
   endif()
 endif()
 endif()
+
 # Please add macOS-only tests above before the device-specific tests.
 # Please add macOS-only tests above before the device-specific tests.

+ 7 - 2
Tests/RunCMake/XcodeProject/XCTestAddBundle.cmake

@@ -1,9 +1,14 @@
 enable_language(Swift)
 enable_language(Swift)
+
+set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
+set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+
 find_package(XCTest REQUIRED)
 find_package(XCTest REQUIRED)
 
 
-add_executable(TestedApp MACOSX_BUNDLE EXCLUDE_FROM_ALL foo.swift)
+add_executable(TestedApp MACOSX_BUNDLE dummy_main.swift)
 
 
-xctest_add_bundle(TestingAppBundle TestedApp foo.swift)
+xctest_add_bundle(TestingAppBundle TestedApp dummy_main.swift)
 
 
 get_target_property(_lib_output_dir TestingAppBundle LIBRARY_OUTPUT_DIRECTORY)
 get_target_property(_lib_output_dir TestingAppBundle LIBRARY_OUTPUT_DIRECTORY)
 
 

+ 18 - 0
Tests/RunCMake/XcodeProject/dummy_main.swift

@@ -0,0 +1,18 @@
+#if os(iOS)
+import UIKit
+
+@UIApplicationMain
+class MyApp: UIResponder, UIApplicationDelegate {
+}
+
+#elseif os(macOS)
+import SwiftUI
+
+@main
+struct MyApp: App {
+    var body: some Scene {
+        WindowGroup {
+        }
+    }
+}
+#endif