CMake linking to juce modules

@reuk I’m using Cmake to create a static library as part of a juce project I’m working on atm but I’m having problems linking to juce modules. When I try to link to any of the built in juce modules, it ends up trying to compile every single one of the .cpp files within the module directory, and this is failing because the appropriate headers aren’t included.

This is what I’ve got in my CMakeLists.txt for the static library. The juce library is added before this directory in in a parent CMakeLists.txt.

add_library(common
    STATIC
        file/encrypted_file_loader.cpp
        json/parser_helpers.cpp)

target_include_directories(common
    PUBLIC
         # all public facing headers
        )

target_link_libraries(common
    PRIVATE
        juce::juce_core)

Am I missing something obvious? I’m using Clion if it makes any difference!

I think you’re probably running into the issue detailed here:

In short, the source grouping mechanism interacts poorly with target types not created with the juce_add_* functions.

I’d strongly recommend turning off source grouping if you can live without it. It won’t make any difference in Clion (afaik).

If you need to leave source groups enabled for some reason, you can call _juce_fixup_module_source_groups after adding your static library target, and this should sort things out, at the expense of making the build script a bit untidy.

Ah yeah that’s got it, thanks Reuben!

That option doesn’t affect CLion, so I’m all good, but some of my colleagues will be using Xcode unfortunately. So I think I’ll have to try your workaround there, but I’ll come back to that later.