Skip to content

Commit

Permalink
Merge pull request #18 from MichaelBell/fix-update-import
Browse files Browse the repository at this point in the history
Update to latest pimoroni pico import cmake file
  • Loading branch information
Gadgetoid authored Feb 9, 2024
2 parents 301f550 + 0467f96 commit 4ac6796
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.12)
# Change your executable name to something creative!
set(NAME pico-boilerplate) # <-- Name your project/executable here!

include(pimoroni_pico_import.cmake)
include(pico_sdk_import.cmake)
include(pimoroni_pico_import.cmake)

# Gooey boilerplate
project(${NAME} C CXX ASM)
Expand Down
44 changes: 36 additions & 8 deletions pimoroni_pico_import.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
# This file can be dropped into a project to help locate the Pimoroni Pico libraries
# 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 (DEFINED ENV{PIMORONI_PICO_FETCH_FROM_GIT} AND (NOT PIMORONI_PICO_FETCH_FROM_GIT))
set(PIMORONI_PICO_FETCH_FROM_GIT $ENV{PIMORONI_PICO_FETCH_FROM_GIT})
message("Using PIMORONI_PICO_FETCH_FROM_GIT from environment ('${PIMORONI_PICO_FETCH_FROM_GIT}')")
endif ()

if(NOT IS_ABSOLUTE ${PIMORONI_PICO_PATH})
get_filename_component(
PIMORONI_PICO_PATH
"${CMAKE_CURRENT_BINARY_DIR}/${PIMORONI_PICO_PATH}"
ABSOLUTE)
if (DEFINED ENV{PIMORONI_PICO_FETCH_FROM_GIT_PATH} AND (NOT PIMORONI_PICO_FETCH_FROM_GIT_PATH))
set(PIMORONI_PICO_FETCH_FROM_GIT_PATH $ENV{PIMORONI_PICO_FETCH_FROM_GIT_PATH})
message("Using PIMORONI_PICO_FETCH_FROM_GIT_PATH from environment ('${PIMORONI_PICO_FETCH_FROM_GIT_PATH}')")
endif ()

if (NOT PIMORONI_PICO_PATH)
if (PIMORONI_PICO_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PIMORONI_PICO_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PIMORONI_PICO_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pimoroni_pico
GIT_REPOSITORY https://github.com/pimoroni/pimoroni-pico
GIT_TAG main
)
if (NOT pimoroni_pico)
message("Downloading PIMORONI_PICO SDK")
FetchContent_Populate(pimoroni_pico)
set(PIMORONI_PICO_PATH ${pimoroni_pico_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
elseif(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 ()
Expand Down

0 comments on commit 4ac6796

Please sign in to comment.