Xcode: Objective C linking adds -fobjc-link-runtime
Hello,
With 3.16 we use the new support for Objective-C/C++ and we noticed that the Xcode generator failed to configure with the following error:
-- Check for working OBJC compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - broken
CMake Error at /Users/tobias/.conan_plex/.conan/data/cmake/3.16.0-01169386-0/plex/stable/package/b9cf9bf841aca97ce334c83f6fb7c40f3bd8db7d/share/cmake-3.16/Modules/CMakeTestOBJCCompiler.cmake:57 (message):
The Objective-C compiler
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_08d46 -configuration Debug -hideShellScriptEnvironment && User defaults from command line:
HideShellScriptEnvironment = YES
Prepare build
note: Using legacy build system
=== BUILD TARGET cmTC_08d46 OF PROJECT CMAKE_TRY_COMPILE WITH CONFIGURATION Debug ===
Check dependencies
Write auxiliary files
/bin/mkdir -p /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64
write-file /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/cmTC_08d46.LinkFileList
CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/testOBJCCompiler.o testOBJCCompiler.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
cd /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -target x86_64-apple-macos10.9 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-implicit-atomic-properties -Wno-objc-interface-ivars -Wno-arc-repeated-use-of-weak -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DCMAKE_INTDIR=\"Debug\" -DOBJC_OLD_DISPATCH_PROTOTYPES=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-semicolon-before-method-body -I/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/Debug/include -I/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/DerivedSources-normal/x86_64 -I/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/DerivedSources/x86_64 -I/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/Debug -MMD -MT dependencies -MF /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/testOBJCCompiler.d --serialize-diagnostics /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/testOBJCCompiler.dia -c /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/testOBJCCompiler.m -o /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/testOBJCCompiler.o
Ld Debug/cmTC_08d46 normal x86_64
cd /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-macos10.9 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -L/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/Debug -F/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/Debug -filelist /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/cmTC_08d46.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/cmTC_08d46_lto.o -Xlinker -no_deduplicate -fobjc-link-runtime -Wl,-no_weak_imports -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Xlinker -dependency_info -Xlinker /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_08d46.build/Objects-normal/x86_64/cmTC_08d46_dependency_info.dat -o /Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeTmp/Debug/cmTC_08d46
ld: weak import of symbol '_objc_autoreleasePoolPush' not supported because of option: -no_weak_imports for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
The following build commands failed:
Ld Debug/cmTC_08d46 normal x86_64
(1 failure)
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeOutput.log".
See also "/Users/tobias/Code/objc-xcode/b/CMakeFiles/CMakeError.log".
This is obviously because we pass -DCMAKE_EXE_LINKER_FLAGS="-Wl,-no_weak_imports"
- but using the correct deployment target should fix this: -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9
and it doesn't.
This doesn't happen with the Ninja generator.
I did a small test cmakefile:
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(test-objc C OBJC)
then invoke it with:
cmake -GXcode -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 -DCMAKE_EXE_LINKER_FLAGS="-Wl,-no_weak_imports" ..
and
cmake -GNinja -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 -DCMAKE_EXE_LINKER_FLAGS="-Wl,-no_weak_imports" ..
and only the Xcode one fails.