From c117906a7fd713fcf57150215f1551b4e094d4eb Mon Sep 17 00:00:00 2001 From: Armin Date: Wed, 5 Aug 2026 20:10:49 +0200 Subject: [PATCH] Auto-clone JUCE into build dir when not found --- CMakeLists.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5c480..c30ed14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,27 @@ if(NOT DEFINED JUCE_DIR) endif() if(NOT EXISTS "${JUCE_DIR}/CMakeLists.txt") - message(FATAL_ERROR "JUCE not found at ${JUCE_DIR}. Pass -DJUCE_DIR= or clone it next to this project.") + if(Git_FOUND) + set(JUCE_CLONE_DIR "${CMAKE_CURRENT_BINARY_DIR}/juce") + if(EXISTS "${JUCE_CLONE_DIR}/CMakeLists.txt") + message(STATUS "Using JUCE from previous clone at ${JUCE_CLONE_DIR}") + set(JUCE_DIR "${JUCE_CLONE_DIR}") + elseif(EXISTS "${JUCE_CLONE_DIR}") + message(FATAL_ERROR "${JUCE_CLONE_DIR} exists but is not a JUCE checkout. Remove it and re-run, or pass -DJUCE_DIR=.") + else() + message(STATUS "JUCE not found at ${JUCE_DIR}; cloning into ${JUCE_CLONE_DIR}...") + execute_process( + COMMAND ${GIT_EXECUTABLE} clone --depth 1 https://github.com/juce-framework/JUCE.git "${JUCE_CLONE_DIR}" + RESULT_VARIABLE JUCE_CLONE_RESULT + ) + if(NOT JUCE_CLONE_RESULT EQUAL 0) + message(FATAL_ERROR "Failed to clone JUCE. Pass -DJUCE_DIR= to point at an existing checkout.") + endif() + set(JUCE_DIR "${JUCE_CLONE_DIR}") + endif() + else() + message(FATAL_ERROR "JUCE not found at ${JUCE_DIR} and Git is unavailable. Pass -DJUCE_DIR= or install Git.") + endif() endif() add_subdirectory("${JUCE_DIR}" juce_build)