Merge pull request #18637 from komakai:build-for-distribution

Add support for Swift version independence

* Build for distribution (Swift version independence) when new Xcode build system is available

* Add module map and set "Defines Modules" flag
pull/18652/head
Giles Payne 4 years ago committed by GitHub
parent bd40952097
commit 72dfd4846e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      modules/objc/generator/gen_objc.py
  2. 38
      modules/objc/generator/templates/cmakelists.template

@ -1347,7 +1347,17 @@ typedef NS_ENUM(int, {2}) {{
def finalize(self, output_objc_path):
opencv_header_file = os.path.join(output_objc_path, framework_name + ".h")
self.save(opencv_header_file, '\n'.join(['#import "%s"' % os.path.basename(f) for f in self.header_files]))
opencv_header = "#import <Foundation/Foundation.h>\n\n"
opencv_header += "// ! Project version number\nFOUNDATION_EXPORT double " + framework_name + "VersionNumber;\n\n"
opencv_header += "// ! Project version string\nFOUNDATION_EXPORT const unsigned char " + framework_name + "VersionString[];\n\n"
opencv_header += "\n".join(["#import <" + framework_name + "/%s>" % os.path.basename(f) for f in self.header_files])
self.save(opencv_header_file, opencv_header)
opencv_modulemap_file = os.path.join(output_objc_path, framework_name + ".modulemap")
opencv_modulemap = "framework module " + framework_name + " {\n"
opencv_modulemap += " umbrella header \"" + framework_name + ".h\"\n"
opencv_modulemap += "\n".join([" header \"%s\"" % os.path.basename(f) for f in self.header_files])
opencv_modulemap += "\n export *\n module * {export *}\n}\n"
self.save(opencv_modulemap_file, opencv_modulemap)
cmakelist_template = read_contents(os.path.join(SCRIPT_DIR, 'templates/cmakelists.template'))
cmakelist = Template(cmakelist_template).substitute(modules = ";".join(modules), framework = framework_name)
self.save(os.path.join(dstdir, "CMakeLists.txt"), cmakelist)

@ -13,32 +13,52 @@ 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")
file(GLOB_RECURSE objc_sources "objc/*\.h" "objc/*\.m" "objc/*\.mm" "objc/*\.swift" "objc/*\.modulemap")
file(GLOB_RECURSE objc_headers "*\.h")
add_library(opencv_objc_framework STATIC $${objc_sources})
add_library($framework STATIC $${objc_sources})
set_target_properties(opencv_objc_framework PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties($framework PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(opencv_objc_framework PRIVATE "$${BUILD_ROOT}")
target_include_directories(opencv_objc_framework PRIVATE "$${BUILD_ROOT}/install/include")
target_include_directories(opencv_objc_framework PRIVATE "$${BUILD_ROOT}/install/include/opencv2")
target_include_directories($framework PRIVATE "$${BUILD_ROOT}")
target_include_directories($framework PRIVATE "$${BUILD_ROOT}/install/include")
target_include_directories($framework PRIVATE "$${BUILD_ROOT}/install/include/opencv2")
foreach(m $${MODULES})
target_include_directories(opencv_objc_framework PRIVATE "$${BUILD_ROOT}/modules/objc/gen/objc/$${m}")
target_include_directories($framework PRIVATE "$${BUILD_ROOT}/modules/objc/gen/objc/$${m}")
endforeach()
install(TARGETS opencv_objc_framework LIBRARY DESTINATION lib)
install(TARGETS $framework LIBRARY DESTINATION lib)
enable_language(Swift)
# Additional target properties
set_target_properties(opencv_objc_framework PROPERTIES
if (CMAKE_XCODE_BUILD_SYSTEM GREATER_EQUAL 12)
set_target_properties($framework PROPERTIES
OUTPUT_NAME "$framework"
ARCHIVE_OUTPUT_DIRECTORY "$${BUILD_ROOT}/lib"
XCODE_ATTRIBUTE_SWIFT_VERSION 5.0
XCODE_ATTRIBUTE_DEFINES_MODULE YES
XCODE_ATTRIBUTE_BUILD_LIBRARY_FOR_DISTRIBUTION YES
XCODE_ATTRIBUTE_OTHER_SWIFT_FLAGS "-Xcc $${SUPPRESS_WARNINGS_FLAGS}"
XCODE_ATTRIBUTE_MODULEMAP_FILE objc/$framework.modulemap
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER org.opencv.$framework
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.opencv.$framework
PUBLIC_HEADER "$${objc_headers}"
DEFINE_SYMBOL CVAPI_EXPORTS
)
else()
set_target_properties($framework PROPERTIES
OUTPUT_NAME "$framework"
ARCHIVE_OUTPUT_DIRECTORY "$${BUILD_ROOT}/lib"
XCODE_ATTRIBUTE_SWIFT_VERSION 5.0
XCODE_ATTRIBUTE_DEFINES_MODULE YES
XCODE_ATTRIBUTE_OTHER_SWIFT_FLAGS "-Xcc $${SUPPRESS_WARNINGS_FLAGS}"
XCODE_ATTRIBUTE_MODULEMAP_FILE objc/$framework.modulemap
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER org.opencv.$framework
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER org.opencv.$framework
PUBLIC_HEADER "$${objc_headers}"
DEFINE_SYMBOL CVAPI_EXPORTS
)
endif()

Loading…
Cancel
Save