From Projucer to CMake

Hey Carlo! Big fan of your plugins :slight_smile:

Xcode is a bit of a special cookie. I’ve abandoned it for CLion, which has fantastic CMake integration, but before that, I spent many hours tweaking it to display JUCE projects decently.

A fair amount of that work is in my plugin template here: GitHub - sudara/pamplejuce: A JUCE Plugin CI template. JUCE 7 & Catch2 with macOS notarization and Windows EV code signing on Github Actions

I also can’t find a way to organize the files in folders, instead, the Xcode project generated by CMake has all the .cpp listed in Source Files and all the .h in Header Files

This and the excessive amount of targets are the current problems with Xcode+JUCE. It’s been a while, but here’s what I do in my projects (globs are dead, long live globs!)

# Why yes, we'd like all our Source files to be in our Source dir...
file(GLOB_RECURSE SourceFiles CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Source/*.h")
target_sources("${PROJECT_NAME}" PRIVATE ${SourceFiles})

# Grab our modules from the Module dir, while we are at it
file(GLOB_RECURSE ModuleFiles CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/modules/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/modules/*.h")
target_sources("${PROJECT_NAME}" PRIVATE ${moduleFiles})

# Our file tree should uhhh, still look like our file tree
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/Source PREFIX "" FILES ${SourceFiles})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/modules PREFIX "" FILES ${ModuleFiles})

I wrote up an article on cmake with JUCE, maybe it can help with the transition. How to use CMake with JUCE · Melatonin

Also @benvining is doing a cmake series on the Audio Programmer’s youtube channel right now. (He might show up and say that the CMake devs (still) warn against using globs, even with CONFIGURE_DEPENDS but so far I haven’t run into any real world problems with them).

4 Likes