-
-
Save agirault/3244bf956c2cad7217b148291135f85e to your computer and use it in GitHub Desktop.
| # cmake /path/to/src \ | |
| # -GXcode \ # or Ninja | |
| # -DQt5_DIR=/path/to/Qt/5.13.0/ios/lib/cmake/Qt5 \ | |
| # -DCMAKE_SYSTEM_NAME=iOS \ | |
| # -DCMAKE_OSX_DEPLOYMENT_TARGET=11 \ | |
| # -DCMAKE_INSTALL_PREFIX=/usr/local/frameworks \ | |
| # -DCMAKE_OSX_ARCHITECTURES="arm64" \ # arm64 for device, x86_64 for simulator (but x86_64 not in installed Qt5 ios static libs?) | |
| cmake_minimum_required (VERSION 3.14 FATAL_ERROR) | |
| project (Foo VERSION 1.0 LANGUAGES C CXX) | |
| # Find QT | |
| set(QT5_MODULES | |
| Core | |
| Widgets | |
| Gui | |
| Quick | |
| Qml | |
| # other modules needed... | |
| ) | |
| find_package (Qt5 | |
| COMPONENTS ${QT5_MODULES} | |
| REQUIRED | |
| ) | |
| # Options for QT | |
| set (CMAKE_AUTOMOC ON) | |
| set (CMAKE_AUTORCC ON) | |
| set (CMAKE_AUTOUIC ON) | |
| # Set files | |
| set (PRIVATE_HEADER_DIRS | |
| # private include directories | |
| ) | |
| set (PUBLIC_HEADER_DIRS | |
| # public include directories | |
| ) | |
| set (PRIVATE_HEADERS | |
| # private include files | |
| ) | |
| set (PUBLIC_HEADERS | |
| # public include files | |
| ) | |
| set (SOURCES | |
| # source files (c, cpp, mm) | |
| ) | |
| set (RESOURCES | |
| # qrc files | |
| ) | |
| set (UIS | |
| # ui files | |
| ) | |
| # Create library | |
| add_library (${PROJECT_NAME} SHARED | |
| ${PUBLIC_HEADERS} # needed for set_target_properties to work for framework | |
| ${PRIVATE_HEADERS} # needed for set_target_properties to work for framework | |
| ${SOURCES} | |
| ${RESOURCES} | |
| ${UIS} | |
| ) | |
| # Find Qt targets for modules and plugins | |
| # Note: Missing more things? | |
| # Should be fixed in 5.14: https://bugreports.qt.io/browse/QTBUG-38913 | |
| set (QT5_TARGETS "") | |
| foreach (QT5_MODULE ${QT5_MODULES}) | |
| set (QT5_TARGET Qt5::${QT5_MODULE}) | |
| list (APPEND QT5_TARGETS ${QT5_TARGET}) | |
| set (QT5_MODULE_PLUGINS ${Qt5${QT5_MODULE}_PLUGINS}) | |
| if (QT5_MODULE_PLUGINS) | |
| list(APPEND QT5_TARGETS ${QT5_MODULE_PLUGINS}) | |
| endif() | |
| endforeach() | |
| # Link | |
| target_link_libraries (${PROJECT_NAME} | |
| PUBLIC | |
| ${QT5_TARGETS} | |
| # other dependency targets | |
| ) | |
| # Include directories | |
| # Note: not needed if not exporting since we are already creating a framework? | |
| target_include_directories (${PROJECT_NAME} | |
| PRIVATE ${PRIVATE_HEADER_DIRS} | |
| PUBLIC ${PUBLIC_HEADER_DIRS} | |
| ) | |
| # Add BITCODE for other generators than Xcode | |
| # Note: Does not seem to last in install tree | |
| target_compile_options(${PROJECT_NAME} | |
| PUBLIC | |
| "-fembed-bitcode" | |
| ) | |
| # Framework | |
| set_target_properties (${PROJECT_NAME} PROPERTIES | |
| FRAMEWORK TRUE | |
| INSTALL_NAME_DIR "@rpath" # Note: did not seem to work with MACOSX_RPATH TRUE instead. Needed to embed the framework in an iOS app | |
| # BUILD_WITH_INSTALL_NAME_DIR TRUE # Needed to set install_name to @rpath in build tree also | |
| PRIVATE_HEADER "${PRIVATE_HEADERS}" # Needed for set_target_properties to work for framework | |
| PUBLIC_HEADER "${PUBLIC_HEADERS}" # Needed for set_target_properties to work for framework | |
| MACOSX_FRAMEWORK_IDENTIFIER "com.your-organization.${PROJECT_NAME}" #CFBundleIdentifier | |
| MACOSX_FRAMEWORK_SHORT_VERSION_STRING "${PROJECT_VERSION}" #CFBundleShortVersionString | |
| #MACOSX_FRAMEWORK_BUNDLE_VERSION B001 #CFBundleVersion | |
| #XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer" | |
| ) | |
| # Install | |
| install (TARGETS ${PROJECT_NAME} | |
| FRAMEWORK DESTINATION . # relative to CMAKE_INSTALL_PREFIX | |
| PRIVATE_HEADER | |
| PUBLIC_HEADER | |
| ) |
I have installed Qt 6.8.2 through the installer.
And see the QtCore.framework %
eugenefoley@Eugenes-MBP QtCore.framework % pwd
/Users/eugenefoley/QtIOS2/6.8.2/ios/lib/QtCore.framework
eugenefoley@Eugenes-MBP QtCore.framework % ls
Headers PrivacyInfo.xcprivacy QtCore_debug
Info.plist QtCore Versions
eugenefoley@Eugenes-MBP QtCore.framework %
The QtCore is static library and the framework appears to be formatted properly:
file QtCore
QtCore: Mach-O universal binary with 2 architectures: [x86_64:current ar archive] [arm64]
QtCore (for architecture x86_64): current ar archive
QtCore (for architecture arm64): current ar archive
Is it possible to embed this framework straight into and iOS Frontend Executable?
@agirault were you ever able to get to a point where you could just embed the QtCore.framework into an ios project.
For those who got here in desperate search of answer...
qt_import_plugins(${PROJECT_NAME} EXCLUDE_BY_TYPE platforms)
this disables linking of the platform plugin in Qt6::Gui, therefore solving the error.
Because most probably you link the module in order to work with colours or something like this.
The qt_import_plugins can be even more refined. If you are interested, just google it.