Automatic Reference Counting (ARC) in user Juce modules

Hi Juce team!

The new CMake build system in Juce 6 is awesome. However, I have a question.

How do I enable automatic reference counting (ARC) for my Objective-C files in a user Juce module?

Say, my project is organised like this:

project (folder)

    - CMakeLists.txt (project CMakeLists file)

    - my_module (folder)

          - CMakeLists.txt (my_module CMakeLists file)

           - my_module (folder)

                - my_module.h

                - my_module.mm

In the CMakeList file in ‘my_module’ I include the user module like this ‘juce_add_modules(my_module)’.

I’ve tried using ‘set_source_files_properties( my_module/my_module.mm PROPERTIES COMPILE_FLAGS “-fobjc-arc”)’, which doesn’t work.

Hi,

set_source_files_properties() worked for me in the past - but I did it in the root CMake file and built the path to the file with ${CMAKE_SOURCE_DIR}/…/…/yadayada. Not sure if this makes a difference, I think it shouldn’t, but maybe it does.

Hi PixelPacker,

Thanks for your answer! I think, however, that putting the ‘set_source_files_properties(…)’ command in the root CMake file is not desirable, as I’d have to do this in every individual project that uses ‘my_module’. And later on, if I add an Objective C file to ‘my_module’, I have to update the CMake file in all projects that use ‘my_module’.

Yes, I completely agree. I just wanted to point out, that set_source_files_properties () worked for me under the circumstances I described - I don’t know if this actually required or not.

Edit: because I didn’t RTFM - here’s to @reuk for not resorting to guesgeneering like me :smiley:

According to the docs:

By default, source file properties are only visible to targets added in the same directory ( CMakeLists.txt ).

If you add your module in one subdirectory, and your dependent target in a different subdirectory, the flags will not be visible to the dependent target.

Unfortunately I can’t think of a straightforward way to get per-file flags working along with juce_add_modules. Might it be possible to convert your ARC-dependent code to a staticlib instead?

1 Like

Okay, thanks for your answer. I’ll give it a try with static libs.

Maybe, at some point, you should consider migrating the Juce Objective-C code to use ARC. Would be great!

1 Like