leetal / ios-cmake

A CMake toolchain file for iOS/iPadOS, visionOS, macOS, watchOS & tvOS C/C++/Obj-C++ development
BSD 3-Clause "New" or "Revised" License
1.91k stars 450 forks source link

Add support for visionOS #176

Closed knight556 closed 4 months ago

knight556 commented 1 year ago

Feature request Please add support for the xrOS platform and simulator.

leetal commented 1 year ago

Please have a look at the PR @ #175 :)

floppyhammer commented 1 year ago
clang: error: cannot specify '-mtargetos=xros1.0' along with '-target arm64-apple-xros1.0'

The latest toolchain file doesn't work for me. I'm using a nightly version of CMake (cmake-3.27.20230807) with the PR supportting visionOS merged.

floppyhammer commented 1 year ago

Okay, I found a solution. You just cannot specify both of -mtargetos (which is specified in Apple-Clang.cmake) and -target. Commenting the lines to set APPLE_TARGET_TRIPLE_INT around here https://github.com/leetal/ios-cmake/blob/b0e8b29da5025cc728b442b3f6b88e1f923b885b/ios.toolchain.cmake#L500C1-L507C10 works for me.

floppyhammer commented 1 year ago

It turned out the above-mentioned solution doesn't work. You can get the library to compile this way, but you cannot link it with other libraries built with Xcode.

error: binaries with multiple platforms are not supported

It's probably due to the wrong build target given by CMake.

I ended up leaving the toolchain file and modifying Apple-Clang.cmake instead.

  elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XROS")
  #  set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtargetos=xros")
  elseif(_CMAKE_OSX_SYSROOT_PATH MATCHES "/XRSimulator")
  #  set(CMAKE_${lang}_OSX_DEPLOYMENT_TARGET_FLAG "-mtargetos=xros")

Now it links without a problem.

leetal commented 1 year ago

The "poor-mans-choice workaround" could be to actually filter any -mtargetos=xros from the C[XX]_FLAGS prior to building (if building visionOS) with the toolchain. But then we'd be "breaking" (read fix) the upstream features which i really don't want either.. Hard one to crack..

danoli3 commented 9 months ago

Remove APPLE_TARGET_TRIPLE_INT for successful compile

paulocoutinhox commented 9 months ago

+1

knight556 commented 8 months ago

Any progress on this ticket?

danoli3 commented 8 months ago

Yes this actually is still a problem when linking the XROS Sim and XROS causing issues.

Problem still occurring. Looking into

  Run Build Command(s): /opt/homebrew/Cellar/cmake/3.28.1/bin/cmake -E env VERBOSE=1 /usr/bin/make -f Makefile cmTC_cf39d/fast
    /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/cmTC_cf39d.dir/build.make CMakeFiles/cmTC_cf39d.dir/build
    Building C object CMakeFiles/cmTC_cf39d.dir/testCCompiler.c.o
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang   --target=-apple-xros1.0   -fvisibility=hidden -fvisibility-inlines-hidden   -std=gnu17 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/XROS.platform/Developer/SDKs/XROS1.0.sdk -mtargetos=xros1.0 -fPIC -MD -MT CMakeFiles/cmTC_cf39d.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_cf39d.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_cf39d.dir/testCCompiler.c.o -c /Users/~/SOURCE/openFrameworksmacOS/scripts/apothecary/apothecary/build/zlib/build_xros_VISIONOS/CMakeFiles/CMakeScratch/TryCompile-BLvmqO/testCCompiler.c
    clang: error: cannot specify '-mtargetos=xros1.0' along with '--target=-apple-xros1.0'
    make[1]: *** [CMakeFiles/cmTC_cf39d.dir/testCCompiler.c.o] Error 1
    make: *** [cmTC_cf39d/fast] Error 

Yeah essentially need to remove the "-mtargetos=xros1.0"

danoli3 commented 8 months ago

Okay looks like CMake are on the case: https://gitlab.kitware.com/cmake/cmake/-/issues/25188

Fix in Cmake 3.28.4

danoli3 commented 7 months ago

https://github.com/Kitware/CMake/commit/361e5fd441e2282bc1415c31a7bcf4901941ae79

Merged in Cmake 3.29.0 just released today!

leetal commented 4 months ago

Yep, the tests added to the toolchain does indeed now work for the xrOS (visionOS) platform. Closing this issue.