From 54551c3f948145496a7cb503b7e0b64cbafee578 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Sat, 21 May 2022 12:05:49 +0100 Subject: [PATCH] Improve PIMORONI_PICO_PATH fallback Check for pimoroni-pico next to the pico sdk, then next to the project. If neither exist, fail with an error that tells the user to set PIMORONI_PICO_PATH. --- pimoroni_pico_import.cmake | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pimoroni_pico_import.cmake b/pimoroni_pico_import.cmake index f0bfd03f..3be8d4b9 100644 --- a/pimoroni_pico_import.cmake +++ b/pimoroni_pico_import.cmake @@ -2,16 +2,17 @@ # It will also set up the required include and module search paths. if (NOT PIMORONI_PICO_PATH) - set(PIMORONI_PICO_PATH "../../pimoroni-pico/") -endif() - -if(NOT IS_ABSOLUTE ${PIMORONI_PICO_PATH}) - get_filename_component( - PIMORONI_PICO_PATH - "${CMAKE_CURRENT_BINARY_DIR}/${PIMORONI_PICO_PATH}" - ABSOLUTE) + if (PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pimoroni-pico") + set(PIMORONI_PICO_PATH ${PICO_SDK_PATH}/../pimoroni-pico) + message("Defaulting PIMORONI_PICO_PATH as sibling of PICO_SDK_PATH: ${PIMORONI_PICO_PATH}") + elseif(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/../../pimoroni-pico/") + set(PIMORONI_PICO_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../pimoroni-pico/) + else() + message(FATAL_ERROR "Pimoroni Pico location was not specified. Please set PIMORONI_PICO_PATH.") + endif() endif() +get_filename_component(PIMORONI_PICO_PATH "${PIMORONI_PICO_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") if (NOT EXISTS ${PIMORONI_PICO_PATH}) message(FATAL_ERROR "Directory '${PIMORONI_PICO_PATH}' not found") endif ()