xref: /Kernel-v10.6.2/portable/ThirdParty/GCC/RP2040/pico_sdk_import.cmake (revision 9af72db3ec82993df2f50170bccdf2958ad19137)
1# Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
2#
3# SPDX-License-Identifier: BSD-3-Clause
4
5# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
6
7# This can be dropped into an external project to help locate this SDK
8# It should be include()ed prior to project()
9
10if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
11    set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
12    message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
13endif ()
14
15if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
16    set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
17    message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
18endif ()
19
20if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
21    set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
22    message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
23endif ()
24
25set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
26set(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")
27set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
28
29if (NOT PICO_SDK_PATH)
30    if (PICO_SDK_FETCH_FROM_GIT)
31        include(FetchContent)
32        set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
33        if (PICO_SDK_FETCH_FROM_GIT_PATH)
34            get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
35        endif ()
36        FetchContent_Declare(
37                pico_sdk
38                GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
39                GIT_TAG master
40        )
41        if (NOT pico_sdk)
42            message("Downloading Raspberry Pi Pico SDK")
43            FetchContent_Populate(pico_sdk)
44            set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
45        endif ()
46        set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
47    else ()
48        message(FATAL_ERROR
49                "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
50                )
51    endif ()
52endif ()
53
54get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
55if (NOT EXISTS ${PICO_SDK_PATH})
56    message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
57endif ()
58
59set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
60if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
61    message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
62endif ()
63
64set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
65
66include(${PICO_SDK_INIT_CMAKE_FILE})
67