Closed snej closed 4 years ago
My colleague @borrrden has found that building our entire program for iOS with CMake doesn't produce these errors; they only happen when invoking CMake inside an Xcode build. So it may be that Clang is picking up an environment variable set by Xcode and getting mixed up...
I think the actual problem may be here:
https://github.com/leetal/ios-cmake/blob/8f7c16a462d17eba7124aba921153382605df288/ios.toolchain.cmake#L461-L464
We're on CMake 3.9.1, so we hit this line because MODERN_CMAKE
is false. Setting CMAKE_SYSTEM_NAME
to Darwin
tells CMake this is a macOS build, hence CMake emits a -mmacosx-version-min
flag.
It appears the logic for setting CMAKE_SYSTEM_NAME
needs to happen on older versions of CMake too, at least back to 3.9.1. I've modified the script as follows and it works now:
diff --git a/ios.toolchain.cmake b/ios.toolchain.cmake
index 170f1fb..4842572 100644
--- a/ios.toolchain.cmake
+++ b/ios.toolchain.cmake
@@ -442,25 +442,22 @@ execute_process(COMMAND uname -r
OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
-# CMake 3.14+ support building for iOS, watchOS and tvOS out of the box.
-if(MODERN_CMAKE)
- if(SDK_NAME MATCHES "iphone")
- set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE})
- elseif(SDK_NAME MATCHES "appletv")
- set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE})
- elseif(SDK_NAME MATCHES "watch")
- set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE})
- endif()
+if(SDK_NAME MATCHES "iphone")
+ set(CMAKE_SYSTEM_NAME iOS CACHE INTERNAL "" ${FORCE_CACHE})
+elseif(SDK_NAME MATCHES "appletv")
+ set(CMAKE_SYSTEM_NAME tvOS CACHE INTERNAL "" ${FORCE_CACHE})
+elseif(SDK_NAME MATCHES "watch")
+ set(CMAKE_SYSTEM_NAME watchOS CACHE INTERNAL "" ${FORCE_CACHE})
+endif()
+
+if(MODERN_CMAKE)
# Provide flags for a combined FAT library build on newer CMake versions
if(PLATFORM_INT MATCHES ".*COMBINED")
set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO CACHE INTERNAL "" ${FORCE_CACHE})
set(CMAKE_IOS_INSTALL_COMBINED YES CACHE INTERNAL "" ${FORCE_CACHE})
message(STATUS "Will combine built (static) artifacts into FAT lib...")
endif()
-else()
- # Legacy code path prior to CMake 3.14
- set(CMAKE_SYSTEM_NAME Darwin CACHE INTERNAL "" ${FORCE_CACHE})
endif()
# Standard settings.
set(CMAKE_SYSTEM_VERSION ${SDK_VERSION} CACHE INTERNAL "")
Thanks for these findings! I'll see if I can reproduce this tomorrow :) I finally have some time over to give the toolchain some love again.
One thing to note is that our project will set the CMAKE_OSX_SYSROOT
to macosx
if it is not set. I'm not sure if this will affect the toolchain or not (I thought that all of that was settled before starting the CMakeLists.txt parsing). The official iOS support for CMake seemed to choke on this and report to me that "macosx is not an iOS SDK" but this toolchain does not have the same issue.
I have now spent some time digging through old CMake docs and come to the conclusion that older (uncertain of HOW old), the "Darwin" option was sufficient, but at least on 3.8, specifying "iOS" indeed seems to be the correct way. I'll modify the toolchain with the changes provided since they seem to be more correct. Of course won't "appletv" or "watch" work on older CMake versions, but that error is up to the user to handle in that case. CMake will throw descriptive errors in those cases.
I have now pushed some changes to master. Please test with that and see if that resolves your issues.
Closing due to lack of activity
I'm using CMake with ios-cmake (3.1.0) inside an Xcode Run Script build phase, to build a 3rd party static library my target links with. However, Clang immediately fails with:
clang: error: invalid argument '-mmacosx-version-min=9.0' not allowed with '-mios-simulator-version-min=9.0'
The problem appears to be caused by this statement in ios.toolchain.cmake:
https://github.com/leetal/ios-cmake/blob/8f7c16a462d17eba7124aba921153382605df288/ios.toolchain.cmake#L545-L546
If I comment out those two lines, everything builds fine. It seems wrong for the script to be forcing a macOS deployment target when it's not building for macOS, but somehow I'm the only one having trouble as a result...
Here's the full CMake output: