Comments (9)
I found these two out by looking at the CMake repo, and most of the changes on the iOS build code of CMake come from @ruslo.
The state of this feature is a little bit messy because in fact iOS platform is still not officially supported by CMake :) As far as I know there is some progress there, see this pull request: https://gitlab.kitware.com/cmake/cmake/issues/17870
In practice this feature will not work for random iOS toolchain and require some agreements (e.g. it will work only for Xcode and CMAKE_OSX_SYSROOT
should be set to iphoneos
), see hints in tests:
- https://github.com/Kitware/CMake/blob/v3.12.2/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedPrune.cmake
- https://github.com/Kitware/CMake/blob/v3.12.2/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombined.cmake
- https://github.com/Kitware/CMake/blob/v3.12.2/Tests/RunCMake/XcodeProject/XcodeIOSInstallCombinedSingleArch.cmake
You can find the real-world toolchains in this collection: https://github.com/ruslo/polly
For example:
- https://github.com/ruslo/polly/blob/master/ios-11-4-dep-9-3.cmake
- https://github.com/ruslo/polly/blob/master/os/iphone.cmake
from ios-cmake.
For those interested, here is the CMakeIOSInstallCombined module source code.
from ios-cmake.
Great find! :D
Looking at the CMake tests it actually looks like this has in some form worked since CMake 3.3+ even. At least during development releases.
from ios-cmake.
Ok, so I ended up getting my build to run googletests on iOS XCode (complicated, if you're interested, PM me), but as expected, while my basic build and test targets work as expected, I can't get the install to work correctly. I need to figure it out but it seems that the standard CMake target install with CMAKE_IOS_INSTALL_COMBINED
enabled to true with the toolchain conflict with each other. I'll try to see what I can do to fix it.
For people interested, here's my error output (paths stubbed out):
[exec]
[exec] === BUILD AGGREGATE TARGET ALL_BUILD OF PROJECT ${PROJECTNAME} WITH CONFIGURATION Release ===
[exec]
[exec] Check dependencies
[exec]
[exec] Write auxiliary files
[exec] write-file /Users${ROOT}/build/${PROJECTNAME}.build/Release-iphonesimulator/ALL_BUILD.build/Script-B6C1EA717ACC4EB7AD6F7296.sh
[exec] chmod 0755 /Users${ROOT}/build/${PROJECTNAME}.build/Release-iphonesimulator/ALL_BUILD.build/Script-B6C1EA717ACC4EB7AD6F7296.sh
[exec]
[exec] PhaseScriptExecution CMake\ Rules build/${PROJECTNAME}.build/Release-iphonesimulator/ALL_BUILD.build/Script-B6C1EA717ACC4EB7AD6F7296.sh
[exec] cd /Users${ROOT}
[exec] /bin/sh -c /Users${ROOT}/build/${PROJECTNAME}.build/Release-iphonesimulator/ALL_BUILD.build/Script-B6C1EA717ACC4EB7AD6F7296.sh
[exec] echo ""
[exec]
[exec] echo Build\ all\ projects
[exec] Build all projects
[exec]
[exec] === BUILD AGGREGATE TARGET install OF PROJECT ${PROJECTNAME} WITH CONFIGURATION Release ===
[exec]
[exec] Check dependencies
[exec]
[exec] Write auxiliary files
[exec] write-file /Users${ROOT}/build/${PROJECTNAME}.build/Release-iphonesimulator/install.build/Script-1325F327E42D4B51B08E2D23.sh
[exec] chmod 0755 /Users${ROOT}/build/${PROJECTNAME}.build/Release-iphonesimulator/install.build/Script-1325F327E42D4B51B08E2D23.sh
[exec]
[exec] PhaseScriptExecution CMake\ PostBuild\ Rules build/${PROJECTNAME}.build/Release-iphonesimulator/install.build/Script-1325F327E42D4B51B08E2D23.sh
[exec] cd /Users${ROOT}
[exec] /bin/sh -c /Users${ROOT}/build/${PROJECTNAME}.build/Release-iphonesimulator/install.build/Script-1325F327E42D4B51B08E2D23.sh
[exec] /usr/local/Cellar/cmake/3.12.0/bin/cmake -DBUILD_TYPE=Release -DEFFECTIVE_PLATFORM_NAME=-iphonesimulator -P cmake_install.cmake
[exec] -- Install configuration: "Release"
[exec] -- Installing: /Users${ROOT}/dist/${PROJECTNAME}-ios/ios/lib/lib${PROJECTNAME}Blas.a
[exec] [iOS combined] Target: ${PROJECTNAME}Blas
[exec] [iOS combined] Config: Release
[exec] [iOS combined] Destination: /Users${ROOT}/dist/${PROJECTNAME}-ios/ios/lib/lib${PROJECTNAME}Blas.a
[exec] [iOS combined] Architectures (iphoneos): arm64 armv7 armv7s
[exec] [iOS combined] Architectures (iphonesimulator): i386 x86_64
[exec] [iOS combined] Build `${PROJECTNAME}Blas` for `iphoneos`
[exec] Build settings from command line:
[exec] SDKROOT = iphoneos11.4
[exec] TOOLCHAINS = com.apple.dt.toolchain.XcodeDefault
[exec]
[exec] === BUILD AGGREGATE TARGET ZERO_CHECK OF PROJECT ${PROJECTNAME} WITH CONFIGURATION Release ===
[exec]
[exec] Check dependencies
[exec]
[exec] Write auxiliary files
[exec] write-file ${BUILD_PATH}/ZERO_CHECK.build/Script-250BDD78B55149C3B04C39C3.sh
[exec] chmod 0755 ${BUILD_PATH}/ZERO_CHECK.build/Script-250BDD78B55149C3B04C39C3.sh
[exec]
[exec] PhaseScriptExecution CMake\ Rules build/${PROJECTNAME}.build/Release-iphoneos/ZERO_CHECK.build/Script-250BDD78B55149C3B04C39C3.sh
[exec] cd /Users${ROOT}
[exec] /bin/sh -c ${BUILD_PATH}/ZERO_CHECK.build/Script-250BDD78B55149C3B04C39C3.sh
[exec] echo ""
[exec]
[exec] make -f /Users${ROOT}/build/CMakeScripts/ReRunCMake.make
[exec] make[2]: `/Users${ROOT}/build/CMakeFiles/cmake.check_cache' is up to date.
[exec]
[exec] === BUILD TARGET ${PROJECTNAME}Blas OF PROJECT ${PROJECTNAME} WITH CONFIGURATION Release ===
[exec]
[exec] Check dependencies
[exec] No architectures to compile for (ARCHS=x86_64, VALID_ARCHS=arm64 armv7 armv7s).
[exec]
[exec] ** BUILD FAILED **
[exec]
[exec]
[exec] The following build commands failed:
[exec] Check dependencies
[exec] (1 failure)
[exec] ** BUILD FAILED **CMake Error at /usr/local/Cellar/cmake/3.12.0/share/cmake/Modules/CMakeIOSInstallCombined.cmake:127 (message):
[exec] Build failed
[exec] Call Stack (most recent call first):
[exec] /usr/local/Cellar/cmake/3.12.0/share/cmake/Modules/CMakeIOSInstallCombined.cmake:279 (_ios_install_combined_build)
[exec] cmake_install.cmake:49 (ios_install_combined)
[exec]
[exec]
[exec] make: *** [install_buildpart_0] Error 1
[exec] Command /bin/sh failed with exit code 2
Here are the arguments I fed into CMake:
-DCMAKE_TOOLCHAIN_FILE=${basedir}/cmake/toolchain/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR64 -DIOS=TRUE
from ios-cmake.
@leetal, I actually got this to work. I tested this by using -DIOS_PLATFORM=OS -DIOS_DEPLOYMENT_TARGET=8.0
:
I got this working by doing the following:
1. set CMAKE_OSX_DEVELOPMENT_TARGET
to match IOS_DEPLOYMENT_TARGET
CMAKE_OSX_DEVELOPMENT_TARGET
isn't set in the toolchain for some reason (prolly because you're using a CMake version older than 3.11 at your workplace), so whenever I ran theinstall
cmake target, cmake would force a rebuild and set the-mios-${platform}-version-min
to whatever the default iOS version is and ignore the one set in- Note that you no longer need to set that flag I was talking about anymore if using CMake 3.11 since this is automatically added by CMake via this CMake variable
2. You must add the simulator architectures as XCODE_ATTRIBUTES
(see below) into your CMakeLists.txt
:
if (CMAKE_IOS_INSTALL_COMBINED AND CMAKE_OSX_SYSROOT MATCHES "os")
set_target_properties(fooTarget bazTarget PROPERTIES
XCODE_ATTRIBUTE_ARCHS[sdk=iphonesimulator*] i386 x86_64
XCODE_ATTRIBUTE_VALID_ARCHS[sdk=iphonesimulator*] i386 x86_64
)
endif()
- This ensures that CMake's install target will pick up the correct architectures when running the
ios_install_combined
when running theinstall
target ios_install_combined
looks for both properties on the target- if you start with
-DIOS_PLATFORM=SIMULATOR[64]
, you will have to set the opposite on the targets. (but this will only build for 1 simulator architecutre, you can't build both simulator architectures with the toolchain, and I decided not to investigate this angle) - If setting the architectures on the same platform, I get a CRAPTON of linker errors if creating an executable from a library
- I don't fully understand why this works, but it does...
Doing these two things fixes the problems and I'm able to create a nice fat universal static library for the following architectures:
- arm64
- armv7
- armv7s
- i686
- x86_64
I found these two out by looking at the CMake repo, and most of the changes on the iOS build code of CMake come from @ruslo. I believe the code will run a config 2x, and it doesn't directly use the toolchain, but I'm sure it ends up using a lot of the cached values that the toolchain sets (I probably should investigate this, too, but I've spent over a week moving my team's code to use CMake, googletests to run on iOS, and also semi-understand ios_installed_combined
enough to make a universal static lib).
I believe (1) is easy to solve by adding 1 simple line to the toolchain (just add flag if cmake is 3.11 or higher, else fall back to current behavior, but this solution will only work for CMake 3.11+). However, (2) will probably only work by changing the documentation since this is dependent on users setting the correct architectures on their targets. Perhaps there is a better solution to this but TBH it's always best to set properties on CMake targets and in addition document the variables that we can set on it (unfortunately CMake doesn't).
This begs a bigger question if CMake should just have 1st party support for iOS like it has for Android. I believe your toolchain is definitely good enough especially if the code is cleaned for the newer versions of CMake. CMake really should clean up their documentation for modern practices, also.
from ios-cmake.
Hi! This question may fit well here. I see in @ruslo's link that the official cmake iOS support is coming along well, but it might not just be 100% there yet.
I'd like to ask, what are the main differences between @ruslo's polly iOS toolchain files, and @leetal's iOS toolchain files in this repository? Both look quite mature and well-working to me. Any hints on what the differences might be and when to best go for one or the other?
Thanks a lot!
from ios-cmake.
I see in @ruslo's link that the official cmake iOS support is coming along well, but it might not just be 100% there yet
I haven't tested it yet, I guess I will need to tweak few variables in Polly to match CMake 3.14 (?) iOS support. In general as far as I understand Polly, CMake iOS support and https://github.com/leetal/ios-cmake are independent things.
the main differences between @ruslo's polly iOS toolchain files, and @leetal's iOS toolchain files in this repository?
According to the README:
The resulting binary will consist of only one platform. To combine all
platforms into the same fat-library, use the LIPO tool. More information
on this is available on the net
It's not designed to use both simulator and device simultaneously, if you want such library you have to independently build simulator, then build device, then use lipo.
With Polly, simulator and device architectures can be mixed together without any extra steps (see CMAKE_IOS_INSTALL_COMBINED feature). E.g. build with ios-nocodesign-11-4-dep-9-3
toolchain:
Will produce the 5 architectures library:
> mkdir __temp && cd __temp
> wget https://github.com/ingenue/hunter-cache/releases/download/cache-19005d5/19005d5e7164d248ee51ba10ac03caf6d0d48645.tar.bz2
> tar xf 19005d5e7164d248ee51ba10ac03caf6d0d48645.tar.bz2
> lipo -info lib/libicui18n.a
Architectures in the fat file: lib/libicui18n.a are: i386 armv7 armv7s x86_64 arm64
This library produced by regular cmake --build _builds --target install
command and package can be injected to user code with regular find_package(... CONFIG REQUIRED)
.
from ios-cmake.
I see! So I would deduce from that that leetal/ios-cmake is quite a basic (while well-working) iOS toolchain file for CMake, while polly's iOS toolchain files offer many more options (like e.g. the mixing of architectures that you mentioned).
Thank you very much, that's a great answer.
from ios-cmake.
Fixed in v3.0.0 🔥 See #27 for more information to official docs.
from ios-cmake.
Related Issues (20)
- [bug] Should set ENABLE_STRICT_TRY_COMPILE TRUE by default HOT 5
- [bug] The platform OS64COMBINED generate Xcode project only for iOS HOT 1
- Feature: Add Support for Universal macOS builds (Apple Silicon + Intel) HOT 2
- [bug] build fail for SIMULATOR64 with xcode 14 HOT 2
- [question] Issue with APPLE_TARGET_TRIPLE (aarch64-apple-ios/arm64-apple-ios) HOT 5
- how to omit -G Xcode to use Makefile or use -G Ninjau HOT 2
- Honor CMAKE_FIND_FRAMEWORK if passed via command line
- [bug] Support for SIMULATORARM64_TVOS only HOT 2
- [bug] Support for OS only for armv7 HOT 2
- [bug] MacCatalyst x86_64 is building with macOS flags and not macabi HOT 5
- Add support for visionOS HOT 11
- [bug] Intermediate binaries compiled during cmake build are not signed when using ios.toolchain.cmake HOT 3
- command not found: cmake HOT 2
- how to show the duplicate symbols HOT 1
- Copy-if-different error while trying to build brainflow libraries using OS64COMBINED HOT 1
- ARM64 support for WATCHOS simulator is missing. HOT 2
- [bug] CMAKE_OSX_DEPLOYMENT_TARGET not CACHE HOT 2
- what's the different about release version and debug version? HOT 1
- the compiled framework contains only arm64
- [bug] building for iOS, but linking in object file built for iOS Simulator HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-cmake.