Swift compiler check fails on cmake >= 3.16 with Ninja generator when cross compiling for IOS
Since version 3.16, swift compiler detection no longer work for Ninja in case of cross compilation
It can be reproduced with a very simple CMakeLists.txt
cmake ../ -GNinja -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_ARCHITECTURES="armv7;arm64" -DCMAKE_OSX_DEPLOYMENT_TARGET=9.3
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Swift compiler identification is Apple 5.0.1
-- Check for working Swift compiler: /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
-- Check for working Swift compiler: /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -- broken
CMake Error at /usr/local/Cellar/cmake/3.16.1/share/cmake/Modules/CMakeTestSwiftCompiler.cmake:41 (message):
The Swift compiler
"/Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /tmp/build2/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/local/bin/ninja cmTC_6cd27 && [1/1] Linking Swift executable cmTC_6cd27.app/cmTC_6cd27
FAILED: cmTC_6cd27.app/cmTC_6cd27 CMakeFiles/cmTC_6cd27.dir/main.swift.o cmTC_6cd27.swiftmodule
: && /Applications/Xcode10.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -output-file-map CMakeFiles/cmTC_6cd27.dir/output-file-map.json -incremental -j 8 -emit-executable -o cmTC_6cd27.app/cmTC_6cd27 -emit-module -emit-module-path cmTC_6cd27.swiftmodule -emit-dependencies -sdk /Applications/Xcode10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk -sdk /Applications/Xcode10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk main.swift && :
<unknown>:0: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX'
<unknown>:0: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX'
ld: warning: ignoring file /Applications/Xcode10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk/usr/lib/libobjc.tbd, missing required architecture x86_64 in file /Applications/Xcode10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk/usr/lib/libobjc.tbd (4 slices)
ld: warning: ignoring file /Applications/Xcode10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk/usr/lib/libSystem.tbd, missing required architecture x86_64 in file /Applications/Xcode10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.4.sdk/usr/lib/libSystem.tbd (4 slices)
ld: symbol dyld_stub_binder not found (normally in libSystem.dylib). Needed to perform lazy binding to function _$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:36 (enable_language)
-- Configuring incomplete, errors occurred!
See also "/tmp/build2/CMakeFiles/CMakeOutput.log".
See also "/tmp/build2/CMakeFiles/CMakeError.log".