Skip to content

Commit

Permalink
Fix building of objc module on Catalyst, excluding Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Nov 20, 2020
1 parent 6c4c256 commit 5a55be0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
10 changes: 7 additions & 3 deletions modules/objc/generator/templates/cmakelists.template
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platforms/apple/build_xcframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
12 changes: 8 additions & 4 deletions platforms/ios/build_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions platforms/osx/build_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a55be0

Please sign in to comment.