Skip to content

Commit ea8309f

Browse files
committedApr 19, 2024
fix:add forgotten pico_sdk cmake file
1 parent 891e0e3 commit ea8309f

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
 

‎pico_sdk_import.cmake

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
2+
3+
# This can be dropped into an external project to help locate this SDK
4+
# It should be include()ed prior to project()
5+
6+
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
7+
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
8+
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
9+
endif ()
10+
11+
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
12+
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
13+
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
14+
endif ()
15+
16+
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
17+
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
18+
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
19+
endif ()
20+
21+
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
22+
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
23+
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
24+
25+
if (NOT PICO_SDK_PATH)
26+
if (PICO_SDK_FETCH_FROM_GIT)
27+
include(FetchContent)
28+
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
29+
if (PICO_SDK_FETCH_FROM_GIT_PATH)
30+
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
31+
endif ()
32+
# GIT_SUBMODULES_RECURSE was added in 3.17
33+
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
34+
FetchContent_Declare(
35+
pico_sdk
36+
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
37+
GIT_TAG master
38+
GIT_SUBMODULES_RECURSE FALSE
39+
)
40+
else ()
41+
FetchContent_Declare(
42+
pico_sdk
43+
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
44+
GIT_TAG master
45+
)
46+
endif ()
47+
48+
if (NOT pico_sdk)
49+
message("Downloading Raspberry Pi Pico SDK")
50+
FetchContent_Populate(pico_sdk)
51+
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
52+
endif ()
53+
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
54+
else ()
55+
message(FATAL_ERROR
56+
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
57+
)
58+
endif ()
59+
endif ()
60+
61+
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
62+
if (NOT EXISTS ${PICO_SDK_PATH})
63+
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
64+
endif ()
65+
66+
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
67+
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
68+
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
69+
endif ()
70+
71+
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
72+
73+
include(${PICO_SDK_INIT_CMAKE_FILE})

0 commit comments

Comments
 (0)
Please sign in to comment.