From 5a55be07a17138a04dea1ba82282e9a49b8052b7 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Fri, 20 Nov 2020 14:27:30 -0800 Subject: [PATCH] Fix building of objc module on Catalyst, excluding Swift --- modules/objc/generator/templates/cmakelists.template | 10 +++++++--- platforms/apple/build_xcframework.py | 2 +- platforms/ios/build_framework.py | 12 ++++++++---- platforms/osx/build_framework.py | 7 +++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/objc/generator/templates/cmakelists.template b/modules/objc/generator/templates/cmakelists.template index 67cacbbfa474..75fc06f14d27 100644 --- a/modules/objc/generator/templates/cmakelists.template +++ b/modules/objc/generator/templates/cmakelists.template @@ -13,7 +13,13 @@ set (SUPPRESS_WARNINGS_FLAGS "-Wno-incomplete-umbrella") set (CMAKE_CXX_FLAGS "$${CMAKE_CXX_FLAGS} $${OBJC_COMPILE_FLAGS} $${SUPPRESS_WARNINGS_FLAGS}") # grab the files -file(GLOB_RECURSE objc_sources "objc/*\.h" "objc/*\.m" "objc/*\.mm" "objc/*\.swift" "objc/*\.modulemap") +if (SWIFT_DISABLED) + message("Swift wrapper disabled.") + file(GLOB_RECURSE objc_sources "objc/*\.h" "objc/*\.m" "objc/*\.mm" "objc/*\.modulemap") +else() + enable_language(Swift) + file(GLOB_RECURSE objc_sources "objc/*\.h" "objc/*\.m" "objc/*\.mm" "objc/*\.swift" "objc/*\.modulemap") +endif() file(GLOB_RECURSE objc_headers "*\.h") add_library($framework STATIC $${objc_sources}) @@ -29,8 +35,6 @@ endforeach() install(TARGETS $framework LIBRARY DESTINATION lib) -enable_language(Swift) - # Additional target properties if (CMAKE_XCODE_BUILD_SYSTEM GREATER_EQUAL 12) set_target_properties($framework PROPERTIES diff --git a/platforms/apple/build_xcframework.py b/platforms/apple/build_xcframework.py index ddddca0efd38..6c67d2bf5df5 100644 --- a/platforms/apple/build_xcframework.py +++ b/platforms/apple/build_xcframework.py @@ -36,7 +36,7 @@ def get_framework_build_command_for_platform(platform, destination, framework_na elif platform == 'ios-maccatalyst': # This is not a mistake. For Catalyst, we use the osx toolchain. # TODO: This is building with objc turned off due to an issue with CMake. See here for discussion: https://gitlab.kitware.com/cmake/cmake/-/issues/21436 - args += [osx_script_path, "--catalyst_archs", "x86_64,arm64", "--framework_name", framework_name, "--without=objc", "--build_only_specified_archs"] + args += [osx_script_path, "--catalyst_archs", "x86_64,arm64", "--framework_name", framework_name, "--build_only_specified_archs"] elif platform == 'ios': archs = "arm64" if only_64_bit else "arm64,armv7" args += [ios_script_path, "--iphoneos_archs", archs, "--framework_name", framework_name, "--build_only_specified_archs"] diff --git a/platforms/ios/build_framework.py b/platforms/ios/build_framework.py index db3df1176f9e..6eabe46b5947 100755 --- a/platforms/ios/build_framework.py +++ b/platforms/ios/build_framework.py @@ -113,7 +113,11 @@ def _build(self, outdir): cmake_flags.append("-DCMAKE_C_FLAGS=" + " ".join(c_flags)) cmake_flags.append("-DCMAKE_CXX_FLAGS=" + " ".join(c_flags)) cmake_flags.append("-DCMAKE_EXE_LINKER_FLAGS=" + " ".join(c_flags)) + + # CMake annot compile Swift for Catalyst https://gitlab.kitware.com/cmake/cmake/-/issues/21436 # cmake_flags.append("-DCMAKE_Swift_FLAGS=" + " " + target_flag) + cmake_flags.append("-DSWIFT_DISABLED=1") + cmake_flags.append("-DIOS=1") # Build the iOS codebase cmake_flags.append("-DMAC_CATALYST=1") # Set a flag for Mac Catalyst, just in case we need it cmake_flags.append("-DWITH_OPENCL=OFF") # Disable OpenCL; it isn't compatible with iOS @@ -129,10 +133,10 @@ def _build(self, outdir): self.makeFramework(outdir, dirs) if self.build_objc_wrapper: if self.run_tests: - check_call([sys.argv[0].replace("build_framework", "run_tests"), "--framework_dir=" + outdir, "--framework_name=" + self.framework_name, dirs[0] + "/modules/objc_bindings_generator/{}/test".format(self.getObjcTarget())]) + check_call([sys.argv[0].replace("build_framework", "run_tests"), "--framework_dir=" + outdir, "--framework_name=" + self.framework_name, dirs[0] + "/modules/objc_bindings_generator/{}/test".format(self.getObjcTarget(target[1]))]) else: print("To run tests call:") - print(sys.argv[0].replace("build_framework", "run_tests") + " --framework_dir=" + outdir + " --framework_name=" + self.framework_name + " " + dirs[0] + "/modules/objc_bindings_generator/{}/test".format(self.getObjcTarget())) + print(sys.argv[0].replace("build_framework", "run_tests") + " --framework_dir=" + outdir + " --framework_name=" + self.framework_name + " " + dirs[0] + "/modules/objc_bindings_generator/{}/test".format(self.getObjcTarget(target[1]))) if self.build_docs: check_call([sys.argv[0].replace("build_framework", "build_docs"), dirs[0] + "/modules/objc/framework_build"]) doc_path = os.path.join(dirs[0], "modules", "objc", "doc_build", "docs") @@ -214,7 +218,7 @@ def getBuildCommand(self, arch, target): def getInfoPlist(self, builddirs): return os.path.join(builddirs[0], "ios", "Info.plist") - def getObjcTarget(self): + def getObjcTarget(self, target): # Obj-C generation target return 'ios' @@ -286,7 +290,7 @@ def buildOne(self, arch, target, builddir, cmakeargs = []): execute(buildcmd + ["-target", "ALL_BUILD", "build"], cwd = builddir) execute(["cmake", "-DBUILD_TYPE=%s" % self.getConfiguration(), "-P", "cmake_install.cmake"], cwd = builddir) if self.build_objc_wrapper: - cmakecmd = self.makeCMakeCmd(arch, target, builddir + "/modules/objc_bindings_generator/{}/gen".format(self.getObjcTarget()), cmakeargs) + cmakecmd = self.makeCMakeCmd(arch, target, builddir + "/modules/objc_bindings_generator/{}/gen".format(self.getObjcTarget(target)), cmakeargs) # cmakecmd.append("-DCMAKE_Swift_FLAGS=" + "-target x86_64-apple-ios13.0-macabi") # cmakecmd.append("-DCMAKE_EXE_LINKER_FLAGS=" + "-target x86_64-apple-ios13.0-macabi") cmakecmd.append("-DBUILD_ROOT=%s" % builddir) diff --git a/platforms/osx/build_framework.py b/platforms/osx/build_framework.py index 499cd967e960..4aff1c87c601 100755 --- a/platforms/osx/build_framework.py +++ b/platforms/osx/build_framework.py @@ -16,9 +16,12 @@ class OSXBuilder(Builder): - def getObjcTarget(self): + def getObjcTarget(self, target): # Obj-C generation target - return 'osx' + if target == "Catalyst": + return 'ios' + else: + return 'osx' def getToolchain(self, arch, target): return None