pico_sdk_import.cmake 2.7 KB

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