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!

2 Likes