raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.26k stars 838 forks source link

Wrong value for PICO_SDK_PATH after automatic download from git #1639

Open stefanschober opened 4 months ago

stefanschober commented 4 months ago

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

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 commented 4 months ago

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