pico-sdk icon indicating copy to clipboard operation
pico-sdk copied to clipboard

Wrong value for PICO_SDK_PATH after automatic download from git

Open stefanschober opened this issue 1 year ago • 2 comments

I'm configuring pico_sdk from my project with the following settings:

  • PICO_SDK_FETCH_FROM_GIT set to TRUE
  • PICO_SDK_FETCH_FROM_GIT_PATH set to the absolute target path for the pico_sdk

When configuring the project, pico_sdk is downloaded into ${PICO_SDK_FETCH_FROM_GIT_PATH}/pico_sdk-src. The value of PICO_SDK_PATH is however set to ${PICO_SDK_FETCH_FROM_GIT_PATH}.

I fixed this like so:

--- ../pico-sdk/pico_sdk-src/external/pico_sdk_import.cmake     2024-02-19 10:23:26.764972800 +0100
+++ cmake/pico_sdk_import.cmake 2024-02-19 11:47:44.588034900 +0100
@@ -58,14 +59,20 @@
     endif ()
 endif ()

-get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
+file(REAL_PATH "${PICO_SDK_PATH}" PICO_SDK_PATH BASE_DIRECTORY "${CMAKE_BINARY_DIR}")
 if (NOT EXISTS ${PICO_SDK_PATH})
     message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
 endif ()

-set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
+find_file(PICO_SDK_INIT_CMAKE_FILE pico_sdk_init.cmake
+    HINTS ${PICO_SDK_PATH}
+    PATH_SUFFIXES pico_sdk-src
+)
+# set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
 if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
     message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
+else()
+    cmake_path(GET PICO_SDK_INIT_CMAKE_FILE PARENT_PATH PICO_SDK_PATH)
 endif ()

 set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)

stefanschober avatar Feb 19 '24 11:02 stefanschober

happens when re-configuring the project using cmake ... --fresh

stefanschober avatar Feb 21 '24 11:02 stefanschober