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.89k stars 448 forks source link

Fix setting of CMAKE_SYSTEM_NAME #205

Open EduMenges opened 3 months ago

EduMenges commented 3 months ago

As stated on CMake's documentation:

This variable will be set to true by CMake if the CMAKE_SYSTEM_NAME variable has been set manually (i.e. in a toolchain file or as a cache entry from the cmake command line).

This is problematic when building on a mac for a mac because CMAKE_CROSSCOMPILING will be enabled, causing wonky behavior when building projects that relies on this variable, such as gRPC.

By firstly assigning the CMAKE_SYSTEM_NAME to a variable and checking it against CMAKE_HOST_SYSTEM_NAME, we prevent this behavior and CMAKE_CROSSCOMPILING will only be set when it is actually necessary.

EduMenges commented 3 months ago

There is an issue I've noticed tho, when compiling for a different architecture. CMAKE_SYSTEM_NAME wouldn't get replaced when an x86_64 mac is trying to compile for an aarch64 mac, which wouldn't turn CMAKE_CROSSCOMPILING on (I think?). I could add an extra check, but it seems more of a workaround than a definite solution.

leetal commented 2 months ago

Please rebase your changes on the latest origin/master. I'd completely missed the deprecation of the macos-11 runner that many of the tests were relying on :/ Sorry for the inconvenience.