Explorar el Código

iOS: Add support for Mac Catalyst

Issue: #20132
Signed-off-by: Raul Metsma <[email protected]>
Raul Metsma hace 1 año
padre
commit
2785364b7b

+ 8 - 8
Help/manual/cmake-toolchains.7.rst

@@ -591,14 +591,14 @@ a different SDK (e.g. a simulator) can be selected by setting the
 necessary (see :ref:`Switching Between Device and Simulator` below).
 A list of available SDKs can be obtained by running ``xcodebuild -showsdks``.
 
-========  ================= ==================== ================
-OS        CMAKE_SYSTEM_NAME Device SDK (default) Simulator SDK
-========  ================= ==================== ================
-iOS       iOS               iphoneos             iphonesimulator
-tvOS      tvOS              appletvos            appletvsimulator
-visionOS  visionOS          xros                 xrsimulator
-watchOS   watchOS           watchos              watchsimulator
-========  ================= ==================== ================
+========  ================= ==================== ================ ============
+OS        CMAKE_SYSTEM_NAME Device SDK (default) Simulator SDK    Catalyst SDK
+========  ================= ==================== ================ ============
+iOS       iOS               iphoneos             iphonesimulator  macosx
+tvOS      tvOS              appletvos            appletvsimulator N/A
+visionOS  visionOS          xros                 xrsimulator      N/A
+watchOS   watchOS           watchos              watchsimulator   N/A
+========  ================= ==================== ================ ============
 
 For example, to create a CMake configuration for iOS, the following
 command is sufficient:

+ 6 - 0
Help/release/dev/ios-mac-catalyst.rst

@@ -0,0 +1,6 @@
+ios-mac-catalyst
+----------------
+
+* The :module:`CMakePackageConfigHelpers` module's
+  :command:`generate_apple_platform_selection_file` function
+  gained support iOS Mac Catalyst.

+ 7 - 0
Modules/CMakePackageConfigHelpers.cmake

@@ -219,6 +219,7 @@ Generating an Apple Platform Selection File
       [MACOS_INCLUDE_FILE <file>]
       [IOS_INCLUDE_FILE <file>]
       [IOS_SIMULATOR_INCLUDE_FILE <file>]
+      [IOS_CATALYST_INCLUDE_FILE <file>]
       [TVOS_INCLUDE_FILE <file>]
       [TVOS_SIMULATOR_INCLUDE_FILE <file>]
       [WATCHOS_INCLUDE_FILE <file>]
@@ -254,6 +255,11 @@ Generating an Apple Platform Selection File
   ``IOS_SIMULATOR_INCLUDE_FILE <file>``
     File to include if the platform is iOS Simulator.
 
+  ``IOS_CATALYST_INCLUDE_FILE <file>``
+    .. versionadded:: 3.31
+
+    File to include if the platform is iOS Catalyst.
+
   ``TVOS_INCLUDE_FILE <file>``
     File to include if the platform is tvOS.
 
@@ -507,6 +513,7 @@ function(generate_apple_platform_selection_file _output_file)
     MACOS_INCLUDE_FILE
     IOS_INCLUDE_FILE
     IOS_SIMULATOR_INCLUDE_FILE
+    IOS_CATALYST_INCLUDE_FILE
     TVOS_INCLUDE_FILE
     TVOS_SIMULATOR_INCLUDE_FILE
     WATCHOS_INCLUDE_FILE

+ 2 - 0
Modules/Internal/ApplePlatformSelection.cmake.in

@@ -27,6 +27,8 @@ elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)xrsimulator")
   @_branch_VISIONOS_SIMULATOR_INCLUDE_FILE@
 elseif(_CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)xros")
   @_branch_VISIONOS_INCLUDE_FILE@
+elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS" AND _CMAKE_OSX_SYSROOT_LOWER MATCHES "(^|/)macosx")
+  @_branch_IOS_CATALYST_INCLUDE_FILE@
 elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
   @_branch_MACOS_INCLUDE_FILE@
 else()

+ 2 - 0
Modules/Platform/Apple-Clang.cmake

@@ -44,6 +44,8 @@ macro(__apple_compiler_clang lang)
     set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mwatchos-version-min=")
   elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/WatchSimulator")
     set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mwatchos-simulator-version-min=")
+  elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/MacOSX" AND CMAKE_SYSTEM_NAME STREQUAL "iOS")
+    set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "--target=<ARCH>-apple-ios<VERSION_MIN>-macabi")
   else()
     set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mmacosx-version-min=")
   endif()

+ 1 - 1
Modules/Platform/iOS-Initialize.cmake

@@ -1,6 +1,6 @@
 include(Platform/Darwin-Initialize)
 
-if(NOT _CMAKE_OSX_SYSROOT_PATH MATCHES "/iPhone(OS|Simulator)")
+if(NOT _CMAKE_OSX_SYSROOT_PATH MATCHES "/(iPhoneOS|iPhoneSimulator|MacOSX)")
   message(FATAL_ERROR "${CMAKE_OSX_SYSROOT} is not an iOS SDK")
 endif()
 

+ 8 - 0
Source/cmMakefile.cxx

@@ -2621,6 +2621,14 @@ bool cmMakefile::PlatformIsAppleSimulator() const
     .count(this->GetAppleSDKType());
 }
 
+bool cmMakefile::PlatformIsAppleCatalyst() const
+{
+  std::string systemName;
+  systemName = this->GetSafeDefinition("CMAKE_SYSTEM_NAME");
+  systemName = cmSystemTools::LowerCase(systemName);
+  return systemName == "ios" && this->GetAppleSDKType() == AppleSDK::MacOS;
+}
+
 bool cmMakefile::PlatformSupportsAppleTextStubs() const
 {
   return this->IsOn("APPLE") && this->IsSet("CMAKE_TAPI");

+ 3 - 0
Source/cmMakefile.h

@@ -577,6 +577,9 @@ public:
   /** Return whether the target platform is an Apple simulator.  */
   bool PlatformIsAppleSimulator() const;
 
+  /** Return whether the target platform is an Apple catalyst.  */
+  bool PlatformIsAppleCatalyst() const;
+
   /** Return whether the target platform supports generation of text base stubs
      (.tbd file) describing exports (Apple specific). */
   bool PlatformSupportsAppleTextStubs() const;

+ 3 - 0
Source/cmXcFramework.cxx

@@ -173,6 +173,9 @@ const cmXcFrameworkPlistLibrary* cmXcFrameworkPlist::SelectSuitableLibrary(
   if (mf.PlatformIsAppleSimulator()) {
     systemVariant = cmXcFrameworkPlistSupportedPlatformVariant::simulator;
   }
+  if (mf.PlatformIsAppleCatalyst()) {
+    systemVariant = cmXcFrameworkPlistSupportedPlatformVariant::maccatalyst;
+  }
 
   for (auto const& lib : this->AvailableLibraries) {
     std::string supportedSystemName;

+ 42 - 1
Tests/RunCMake/XcFramework/RunCMakeTest.cmake

@@ -1,5 +1,11 @@
 include(RunCMake)
 
+if(RunCMake_GENERATOR STREQUAL "Xcode")
+  set(maybe_ios_catalyst "")
+else()
+  set(maybe_ios_catalyst ios-catalyst)
+endif()
+
 function(create_library type platform system_name archs sysroot)
   set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/create-${type}-${platform}-build)
   run_cmake_with_options(create-${type}-${platform} -DCMAKE_SYSTEM_NAME=${system_name} -DCMAKE_OSX_ARCHITECTURES=${archs} -DCMAKE_OSX_SYSROOT=${sysroot} -DCMAKE_INSTALL_PREFIX=${RunCMake_TEST_BINARY_DIR}/install)
@@ -12,6 +18,9 @@ endfunction()
 function(create_libraries type)
   create_library(${type} macos Darwin "${macos_archs_2}" macosx)
   create_library(${type} ios iOS "arm64" iphoneos)
+  if(maybe_ios_catalyst)
+    create_library(${type} ios-catalyst iOS "${macos_archs_2}" macosx)
+  endif()
   create_library(${type} tvos tvOS "arm64" appletvos)
   create_library(${type} watchos watchOS "armv7k\\\\;arm64_32" watchos)
   if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15.2)
@@ -58,6 +67,9 @@ endfunction()
 function(create_executables name type)
   create_executable(${name}-macos ${type} Darwin "${macos_archs_2}" macosx)
   create_executable(${name}-ios ${type} iOS "arm64" iphoneos)
+  if(maybe_ios_catalyst)
+    create_executable(${name}-ios-catalyst ${type} iOS "${macos_archs_2}" macosx)
+  endif()
   create_executable(${name}-tvos ${type} tvOS "arm64" appletvos)
   create_executable(${name}-watchos ${type} watchOS "armv7k\\\\;arm64_32" watchos)
   if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15.2)
@@ -71,7 +83,7 @@ function(create_executables name type)
   endif()
 endfunction()
 
-set(xcframework_platforms macos ios tvos watchos ios-simulator tvos-simulator watchos-simulator)
+set(xcframework_platforms macos ios ${maybe_ios_catalyst} tvos watchos ios-simulator tvos-simulator watchos-simulator)
 if(CMake_TEST_XCODE_VERSION VERSION_GREATER_EQUAL 15.2)
   list(APPEND xcframework_platforms visionos visionos-simulator)
 endif()
@@ -141,6 +153,20 @@ run_cmake_command(export-ios-install ${CMAKE_COMMAND} --install . ${_config_arg}
 unset(RunCMake_TEST_NO_CLEAN)
 unset(RunCMake_TEST_BINARY_DIR)
 
+if(maybe_ios_catalyst)
+  set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-ios-catalyst-build)
+  run_cmake_with_options(export-ios-catalyst -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=macosx "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/export-install)
+  set(RunCMake_TEST_NO_CLEAN 1)
+  set(_config_arg)
+  if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+    set(_config_arg --config Release)
+  endif()
+  run_cmake_command(export-ios-catalyst-build ${CMAKE_COMMAND} --build . ${_config_arg})
+  run_cmake_command(export-ios-catalyst-install ${CMAKE_COMMAND} --install . ${_config_arg})
+  unset(RunCMake_TEST_NO_CLEAN)
+  unset(RunCMake_TEST_BINARY_DIR)
+endif()
+
 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-ios-simulator-build)
 run_cmake_with_options(export-ios-simulator -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator "-DCMAKE_OSX_ARCHITECTURES=${macos_archs_1}" -DCMAKE_INSTALL_PREFIX=${RunCMake_BINARY_DIR}/export-install)
 set(RunCMake_TEST_NO_CLEAN 1)
@@ -175,6 +201,19 @@ else()
   set(src_dir "${RunCMake_SOURCE_DIR}")
   set(bld_dir "${RunCMake_BINARY_DIR}")
 endif()
+if(maybe_ios_catalyst)
+  set(maybe_ios_catalyst_mylib
+    -library ${bld_dir}/export-install/lib/ios-catalyst/libmylib.a
+    -headers ${src_dir}/mylib/include
+    )
+  set(maybe_ios_catalyst_mylib_genex
+    -library ${bld_dir}/export-install/lib/ios-catalyst/libmylib-genex.a
+    -headers ${src_dir}/mylib/include
+    )
+else()
+  set(maybe_ios_catalyst_mylib "")
+  set(maybe_ios_catalyst_mylib_genex "")
+endif()
 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/export-install)
 run_cmake_command(export-install-xcframework xcodebuild -create-xcframework
   -output ${bld_dir}/export-install/lib/mylib.xcframework
@@ -182,6 +221,7 @@ run_cmake_command(export-install-xcframework xcodebuild -create-xcframework
   -headers ${src_dir}/mylib/include
   -library ${bld_dir}/export-install/lib/ios/libmylib.a
   -headers ${src_dir}/mylib/include
+  ${maybe_ios_catalyst_mylib}
   -library ${bld_dir}/export-install/lib/ios-simulator/libmylib.a
   -headers ${src_dir}/mylib/include
   )
@@ -191,6 +231,7 @@ run_cmake_command(export-install-xcframework-genex xcodebuild -create-xcframewor
   -headers ${src_dir}/mylib/include
   -library ${bld_dir}/export-install/lib/ios/libmylib-genex.a
   -headers ${src_dir}/mylib/include
+  ${maybe_ios_catalyst_mylib_genex}
   -library ${bld_dir}/export-install/lib/ios-simulator/libmylib-genex.a
   -headers ${src_dir}/mylib/include
   )

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-framework-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-framework-link-phase-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable-link-phase.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-library-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-library-link-phase-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable-link-phase.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-target-framework-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable-target.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-target-framework-link-phase-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable-target-link-phase.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-target-library-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable-target.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-executable-target-library-link-phase-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-executable-target-link-phase.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-framework-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-framework.cmake)

+ 2 - 0
Tests/RunCMake/XcFramework/create-library-ios-catalyst.cmake

@@ -0,0 +1,2 @@
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(create-library.cmake)

+ 1 - 0
Tests/RunCMake/XcFramework/export-common.cmake

@@ -36,6 +36,7 @@ generate_apple_platform_selection_file(mylib-config-top.cmake
   INSTALL_DESTINATION lib/cmake/mylib
   MACOS_INCLUDE_FILE lib/macos/cmake/mylib/mylib-config.cmake
   IOS_INCLUDE_FILE lib/ios/cmake/mylib/mylib-config.cmake
+  IOS_CATALYST_INCLUDE_FILE lib/ios-catalyst/cmake/mylib/mylib-config.cmake
   IOS_SIMULATOR_INCLUDE_FILE lib/ios-simulator/cmake/mylib/mylib-config.cmake
   )
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/mylib-config-top.cmake DESTINATION lib/cmake/mylib RENAME mylib-config.cmake)

+ 4 - 0
Tests/RunCMake/XcFramework/export-ios-catalyst.cmake

@@ -0,0 +1,4 @@
+set(platform_name ios-catalyst)
+set(platform_arg IOS_CATALYST_INCLUDE_FILE)
+set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0")
+include(export-common.cmake)