User modules, CMake & Projucer Question

I decided to try and port one of my projects to CMake. I am new to CMake and for the most part have had no issues. Is it possible to support both CMake and Projucer in a single project that contains a user module? I am getting duplicate symbol errors for the module code.

Attached is a simple sample app.
I generated the build with cmake . -B build -DCMAKE_OSX_ARCHITECTURES="x86_64"
and compiled with cmake --build build

I realize the duplicate symbols are caused by the module cpp including the implementation cpp.

Matt (12.2 KB)

It looks like the module-source-groups feature doesn’t work as expected when modules are added after a call to juce_add_*. In this case, moving the call to juce_add_module before juce_add_gui_app solves the issue.

I’m not sure whether we can make this more robust in JUCE. The source groups feature is quite finicky and needs all non-built files to be marked with the HEADER_FILE_ONLY property. At the moment, the juce_add_* functions set this property on all the files in all modules that have been added up until that point. However, this won’t work properly if a module is added after a call to juce_add_*. Perhaps we could add a special-purpose function to set up the file properties, but I think this would potentially be quite a confusing API. I’ll have a think.

In the meantime, hopefully just rearranging the CMakeLists is a viable solution.

Thanks for the quick response! Moved the modules as you suggested and it works fine now.
My opinion is that this is fine as long as it is documented.