Auto-clone JUCE into build dir when not found

This commit is contained in:
Armin 2026-08-05 20:10:49 +02:00
commit c117906a7f

View file

@ -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=<path> 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=<path>.")
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=<path> 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=<path> or install Git.")
endif()
endif()
add_subdirectory("${JUCE_DIR}" juce_build)