conan: [bug] ObjC ARC compile flag isn't passed to objc files when building with CMake+Ninja

Describe the bug

I’m trying to build an ObjC library that requires ARC with CMake+Ninja. Adding tools.apple:enable_arc=True to the [conf] section doesn’t help - the -fobjc-arc flag isn’t passed when compiling objc files. In the generated toolchain file I see that the flag is set only for C and C++ files, but ARC actually apples only to objc and objc++ files:

# ARC ON
set(FOBJC_ARC "-fobjc-arc")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES")
#Check if Xcode generator is used, since that will handle these flags automagically
if(CMAKE_GENERATOR MATCHES "Xcode")
  message(DEBUG "Not setting any manual command-line buildflags, since Xcode is selected as generator.")
else()
    string(APPEND CONAN_C_FLAGS " ${BITCODE} ${VISIBILITY} ${FOBJC_ARC}")
    string(APPEND CONAN_CXX_FLAGS " ${BITCODE} ${VISIBILITY} ${FOBJC_ARC}")
endif()

One workaround is:

tc.variables["CMAKE_OBJC_FLAGS"] = "-fobjc-arc"

env: macOS 13 Python 3.9 Conan 2.17 Xcode 15.2 (Apple-clang 15) CMake 4.0.2

How to reproduce it

  1. have a CMake project that contains objc files requiring ARC
  2. set tools.apple:enable_arc=True conf
  3. try to build it with Ninja (non-Xcode actually)
  4. observe errors like:
FAILED: CMakeFiles/CocoaLumberjack.dir/src/Sources/CocoaLumberjack/DDFileLogger.m.o 
/usr/bin/clang  -I/Users/kambala/.conan2/p/b/cocoa2181430922f78/b/src/Sources/CocoaLumberjack/include -x objective-c -O3 -DNDEBUG -std=gnu17 -arch arm64 -isysroot /Applications/Xcode-15.2.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk -miphoneos-version-min=12.0 -fPIC -MD -MT CMakeFiles/CocoaLumberjack.dir/src/Sources/CocoaLumberjack/DDFileLogger.m.o -MF CMakeFiles/CocoaLumberjack.dir/src/Sources/CocoaLumberjack/DDFileLogger.m.o.d -o CMakeFiles/CocoaLumberjack.dir/src/Sources/CocoaLumberjack/DDFileLogger.m.o -c /Users/kambala/.conan2/p/b/cocoa2181430922f78/b/src/Sources/CocoaLumberjack/DDFileLogger.m
/Users/kambala/.conan2/p/b/cocoa2181430922f78/b/src/Sources/CocoaLumberjack/DDFileLogger.m:17:2: error: This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
 ^
/Users/kambala/.conan2/p/b/cocoa2181430922f78/b/src/Sources/CocoaLumberjack/DDFileLogger.m:705:1: warning: method possibly missing a [super dealloc] call [-Wobjc-missing-super-calls]
}
^
/Users/kambala/.conan2/p/b/cocoa2181430922f78/b/src/Sources/CocoaLumberjack/DDFileLogger.m:844:5: error: cannot create __weak reference in file using manual reference counting
    __weak __auto_type weakSelf = self;
    ^

P.S. Gave the whole ARC thing a second thought. I think Conan handles it completely incorrectly: it’s a project “property” that is configured on project / target / individual file level, not something a user / consumer can adjust to his liking (unlike visibility or bitcode). So it must be specified on build system level, as incorrect configuration will result in either build errors (like above) or memory leaks at runtime. I strongly recommend to remove ARC handling from Conan: absolute majority of Apple projects use ARC and don’t allow selecting build “mode” by consumer.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (23 by maintainers)

Commits related to this issue

Most upvoted comments

do you want me to open a separate issue about this? As this one is basically about a bug in existing functionality that may affect someone.

No, I think we can cite those other people in this ticket, we just need to check history to check about who to cite.