iOS: Add support for Mac Catalyst

Issue: #20132
Signed-off-by: Raul Metsma <raul@metsma.ee>
This commit is contained in:
Raul Metsma
2024-07-02 10:59:00 +03:00
committed by Brad King
parent f709e6baaf
commit 2785364b7b
22 changed files with 107 additions and 10 deletions

View File

@@ -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:

View File

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

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()

View File

@@ -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");

View File

@@ -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;

View File

@@ -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;

View File

@@ -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
)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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)

View File

@@ -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)