Xcode defaults ARC to off. CMake-based builds leak large amounts of memory.

I was working on a macOS ObjC++ tool that allocated and then replaced a single MTLTexture, and noted that all of the textures were leaked. This project was built with CMake, and I found out the Xcode defaults ARC to off.

ARC has been around long enough that I can't think of many ObjC or Swift projects that would work without it. This default should probably be changed.

The workaround for now, is in all CMakeLists.txt files, to set the following:

  XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
  
Xcode .pbxproj files have ARC enabled when you generate them using any of the Xcode project templates (this has been the case for a while). However, we can't guarantee that cmake generates the .pbxproj files the same way.

If you invoke clang from the command line, it does default to ARC being disabled and you must manually add the -fobjc-arc argument.
CMake says this needs to be fixed by Xcode team, and Xcode teams says the issue needs to be fixed by CMake. So until one side fixes this, I'll continue to use the workaround. But I let the CMake team know the response here. Defaulting ARC to off in a newly create xcodeproject seems incorrect for modern builds, and just having the GUI creation templates override the default value seems like a poor workaround to the underlying problem.
I think part of the problem is the Xcode itself (without the relevant properties in the project set), defaults to the disabled behavior. This is for backwards compatibility, so that an older project loaded into a newer Xcode don't suddenly have ARC enabled when it previously did not..

However, all Xcode projects generated by Xcode have ARC enabled. Unless, CMake somehow uses the Xcode template system to generate the project file (which is doubtful since this system isn't really documented), then CMake needs to generate the project by explicitly enabling the the "use ARC" property.

That said, for the same reason Xcode doesn't enable ARC by default, CMake probably shouldn't either; for backwards compatibility. My understanding is that developers use CMake to build an Xcode project every time their developer hits the build button. If CMake suddenly changes it's behavior in a new version, and a developer whose code doesn't use ARC upgrades to this new version, the project suddenly fail to build since ARC is now implicitly enabled.
Xcode defaults ARC to off. CMake-based builds leak large amounts of memory.
 
 
Q