Qt project CMake settings when using Swift-CPP interoperability for iOS. How?
-
Hello all!
Got created example of using Swift-CPP interoperability for MacOS (tested with Qt 6.2.13 and 6.8.1) https://youtu.be/W5yZj6xkDDg for now trying to make it working for iOS. There are troubles with iOS SDK when trying to build it. Directly in XCode, when using native XCode project for iOS - all is working https://youtu.be/_gRCUNPJt6Q. It means version of XCode and developer tools is Ok with interoperability.
When trying to build it with iOS settings in Qt Creator have this error:
PhaseScriptExecution Generate\ include/SwiftCPP.h /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingCPPSwiftInterop/UsingCPPSwiftInterop_v1/build/Qt_6_2_13_for_iOS_Simulator/build/UsingCPPSwiftInterop_v1.build/Debug-iphonesimulator/appUsingCPPSwiftInterop_v1_autogen.build/Script-341AB4FC67ADB191BD7DCA2B.sh (in target 'appUsingCPPSwiftInterop_v1_autogen' from project 'UsingCPPSwiftInterop_v1') cd /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingCPPSwiftInterop/UsingCPPSwiftInterop_v1 /bin/sh -c /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingCPPSwiftInterop/UsingCPPSwiftInterop_v1/build/Qt_6_2_13_for_iOS_Simulator/build/UsingCPPSwiftInterop_v1.build/Debug-iphonesimulator/appUsingCPPSwiftInterop_v1_autogen.build/Script-341AB4FC67ADB191BD7DCA2B.sh <unknown>:0: warning: no such sysroot directory: 'iphonesimulator' <unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx14.0' warning: ONLY_ACTIVE_ARCH=YES requested with multiple ARCHS and no active architecture could be computed; building for all applicable architectures (in target 'ZERO_CHECK' from project 'UsingCPPSwiftInterop_v1') note: Run script build phase 'Generate CMakeFiles/ZERO_CHECK' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'ZERO_CHECK' from project 'UsingCPPSwiftInterop_v1') warning: ONLY_ACTIVE_ARCH=YES requested with multiple ARCHS and no active architecture could be computed; building for all applicable architectures (in target 'appUsingCPPSwiftInterop_v1_autogen' from project 'UsingCPPSwiftInterop_v1') note: Run script build phase 'Generate CMakeFiles/appUsingCPPSwiftInterop_v1_autogen' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'appUsingCPPSwiftInterop_v1_autogen' from project 'UsingCPPSwiftInterop_v1') warning: ONLY_ACTIVE_ARCH=YES requested with multiple ARCHS and no active architecture could be computed; building for all applicable architectures (in target 'ALL_BUILD' from project 'UsingCPPSwiftInterop_v1') note: Run script build phase 'Generate CMakeFiles/ALL_BUILD' will be run during every build because the option to run the script phase "Based on dependency analysis" is unchecked. (in target 'ALL_BUILD' from project 'UsingCPPSwiftInterop_v1') ** BUILD FAILED ** The following build commands failed: PhaseScriptExecution Generate\ include/SwiftCPP.h /Users/alexandr/Projects/arboreus/arboreus_examples/qt6/CMake/UsingCPPSwiftInterop/UsingCPPSwiftInterop_v1/build/Qt_6_2_13_for_iOS_Simulator/build/UsingCPPSwiftInterop_v1.build/Debug-iphonesimulator/appUsingCPPSwiftInterop_v1_autogen.build/Script-341AB4FC67ADB191BD7DCA2B.sh (in target 'appUsingCPPSwiftInterop_v1_autogen' from project 'UsingCPPSwiftInterop_v1')
When were researching this troubles found that for MacOS and for iOS value of "CMAKE_OSX_SYSROOT" is different in principal. When MacOS it is full path to MacOS SDK, when iOS or iOS sumulator - just one word 'iphoneos' or 'iphonesimuator'
Is it Qt bug or it's Qt special settings or it CMake settings? How to make it working on iOS?
The source code of the test project here. Important notice for building ti for MacOS - use only XCode generator instead of Ninja. When used Ninja error on Swift files.
-
This exact issue haven't solved yet. But found solution to run Swift-CPP interoperability in iOS application with Qt 6 and CMake - it's using static library developed in XCode project where interoperability functionality switched on:
-- Create static library for iOS and choose base language Objective-C in settings
-- When project created delete all of Objective-C templates
-- Switch on C++/Objective-C functionality in build settings
-- Add Swift and C++ code, if needed embed all used frameworks
-- Build *.a for any platform you need
-- Add to Qt 6 CMake project with includesCode samples published here https://github.com/ArboreusSystems/arboreus_examples/tree/master/qt6/CMake/UsingCPPSwiftInterop/UsingCPPSwiftInterop_v2 The recorded video of this sample here https://youtu.be/dZOchNsASHA
Happy coding everyone!
-
2/2