pico_sdk_import.cmake 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_TAG} AND (NOT PICO_SDK_FETCH_FROM_GIT_TAG))
  17. set(PICO_SDK_FETCH_FROM_GIT_TAG $ENV{PICO_SDK_FETCH_FROM_GIT_TAG})
  18. message("Using PICO_SDK_FETCH_FROM_GIT_TAG from environment ('${PICO_SDK_FETCH_FROM_GIT_TAG}')")
  19. endif ()
  20. if (PICO_SDK_FETCH_FROM_GIT AND NOT PICO_SDK_FETCH_FROM_GIT_TAG)
  21. set(PICO_SDK_FETCH_FROM_GIT_TAG "master")
  22. message("Using master as default value for PICO_SDK_FETCH_FROM_GIT_TAG")
  23. endif()
  24. set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
  25. 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")
  26. set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
  27. set(PICO_SDK_FETCH_FROM_GIT_TAG "${PICO_SDK_FETCH_FROM_GIT_TAG}" CACHE FILEPATH "release tag for SDK")
  28. if (NOT PICO_SDK_PATH)
  29. if (PICO_SDK_FETCH_FROM_GIT)
  30. include(FetchContent)
  31. set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
  32. if (PICO_SDK_FETCH_FROM_GIT_PATH)
  33. get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
  34. endif ()
  35. # GIT_SUBMODULES_RECURSE was added in 3.17
  36. if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
  37. FetchContent_Declare(
  38. pico_sdk
  39. GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
  40. GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
  41. GIT_SUBMODULES_RECURSE FALSE
  42. )
  43. else ()
  44. FetchContent_Declare(
  45. pico_sdk
  46. GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
  47. GIT_TAG ${PICO_SDK_FETCH_FROM_GIT_TAG}
  48. )
  49. endif ()
  50. if (NOT pico_sdk)
  51. message("Downloading Raspberry Pi Pico SDK")
  52. FetchContent_Populate(pico_sdk)
  53. set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
  54. endif ()
  55. set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
  56. else ()
  57. message(FATAL_ERROR
  58. "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
  59. )
  60. endif ()
  61. endif ()
  62. get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
  63. if (NOT EXISTS ${PICO_SDK_PATH})
  64. message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
  65. endif ()
  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. set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
  71. include(${PICO_SDK_INIT_CMAKE_FILE})