Odd build errors after JUCE_ENABLE_MODULE_SOURCE_GROUPS

I’m trying to make JUCE module sources browsable in a generated Xcode project.

I’m including JUCE via CMake FetchContent, and using a combination of JUCE_ENABLE_MODULE_SOURCE_GROUPS, GLOB_RECURSE and the source_group function with TREE to show the JUCE module sources as they are on disk.

However, the last step, JUCE_ENABLE_MODULE_SOURCE_GROUPS, seems to break the build. I’m getting some odd build errors in the generated Xcode project.

Example project here: GitHub - adamski/juce-fetch-content

CMakeLists.txt:

cmake_minimum_required(VERSION 3.21)
project(JuceFetchContent)

set(CMAKE_CXX_STANDARD 17)

include(FetchContent

set(FETCHCONTENT_QUIET FALSE)

# Add all JUCE module sources so they are browsable in exported IDE projects
set_property(GLOBAL PROPERTY USE_FOLDERS YES)
option(JUCE_ENABLE_MODULE_SOURCE_GROUPS "Enable Module Source Groups" ON)

FetchContent_Declare(
        juce
        GIT_REPOSITORY https://github.com/juce-framework/JUCE.git
        GIT_PROGRESS TRUE
        GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(juce)

set(SOURCES_MAIN
        library.cpp
        )

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "Source" FILES ${SOURCES_MAIN})

message(${juce_SOURCE_DIR})

file(GLOB_RECURSE JUCE_MODULE_SOURCES
        "${juce_SOURCE_DIR}/modules/*"

source_group(TREE ${juce_SOURCE_DIR}/modules PREFIX "Modules" FILES ${JUCE_MODULE_SOURCES})

add_library(JuceFetchContent STATIC ${SOURCES_MAIN})

target_compile_definitions(JuceFetchContent PUBLIC
        JUCE_STANDALONE_APPLICATION=0
        )

target_link_libraries(JuceFetchContent
        PRIVATE
        # BinaryData            # If we'd created a binary data target, we'd link to it here
        juce::juce_audio_utils
        juce::juce_audio_formats
        PUBLIC
        juce::juce_recommended_config_flags
        juce::juce_recommended_lto_flags
        juce::juce_recommended_warning_flags)

The module source groups option only works with the juce_add_* functions. It does not work with add_executable and add_library. I’ll update the docs to make that clear.

would it be possible (or even make sense) to have a juce_add_library function?

1 Like

I’m not sure - I think the only purpose of this function would be to set up the source groups properly. Most (all?) of the other arguments that can be passed to the juce_add_ functions wouldn’t have any effect.

My main reservation is that I’m quite unhappy with the design of the source-groups feature to begin with. It’s very finnicky, and often causes weird build issues such as the ones you’re seeing. I’d prefer not to adapt the public-facing API too much just to work around this feature if at all possible - I’m still holding out hope that I’ll have a brainwave one of these days, and I’ll be able to rewrite the source grouping mechanism to be a bit more robust.

Maybe I could extract the source-group-fixup logic into a “private” (but still publicly-visible) function with some sort of disclaimer, explaining that the function might go away if I think of a better approach for the source grouping…

Ok, I see - perhaps I’ll try and replicate what JUCE_ENABLE_MODULE_SOURCE_GROUPS is doing.

I’ve extracted the source grouping mechanism into a standalone function here:

2 Likes