Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmake handling of paths with spaces #164

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TankedThomas
Copy link

My Pico SDK filepath uses spaces, which caused problems with the cmake files. I know it's not ideal to have pathname spaces, but putting double quotes around all the variables in the cmake files should fix this.

I'm not aware of any downsides to this change but I'm no expert on the subject. I did test compiling after the changes and it seems to work fine.

There are two commits because I forgot to include the other two cmake files initially.

include(FreeRTOS_Kernel_import.cmake)

project(debugprobe)

pico_sdk_init()

if (${PICO_SDK_VERSION_MAJOR} LESS 2)
if ("${PICO_SDK_VERSION_MAJOR}" LESS 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably there'll never be a space in PICO_SDK_VERSION_MAJOR ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely. It was just quicker and easier to replace everything with quotations, and shouldn't (as far as I know) make an impact either way. Quotations should help with some special characters too, though this probably isn't a problem here.

if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
# GIT_SUBMODULES_RECURSE was added in 3.17
if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0")
if ("${CMAKE_VERSION}" VERSION_GREATER_EQUAL "3.17.0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I suspect there'll never be a space in CMAKE_VERSION ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, and given cmake's version numbering, I doubt it.

message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()

if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
set(PICO_SDK_FETCH_FROM_GIT "$ENV{PICO_SDK_FETCH_FROM_GIT}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PICO_SDK_FETCH_FROM_GIT is a BOOL value, so will never contain a space (AFAIK)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, and as far as I can think, no, a boolean won't ever contain a space.

endif()
if (_ACTUAL_PATH STREQUAL _POSSIBLE_PATH)
get_filename_component(FREERTOS_KERNEL_PATH ${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH} REALPATH)
get_filename_component(FREERTOS_KERNEL_PATH "${CMAKE_CURRENT_LIST_DIR}/${FREERTOS_KERNEL_RP2040_BACK_PATH}" REALPATH)
message("Setting FREERTOS_KERNEL_PATH to ${FREERTOS_KERNEL_PATH} based on location of FreeRTOS-Kernel-import.cmake")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth adding single-quotes around the path in the message? (e.g. see line 60)
message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' based on location of FreeRTOS-Kernel-import.cmake")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered it but I'm not sure how the expansion would work (and I didn't touch the other messages because of it). Single quotes should produce a literal output of the variable, whereas double quotes will interpret it.
For example, C:\Program Files would end up as C:\Program\ Files in single quotes (or C:/Program/ Files under *nix systems).
I can test it if necessary. I'll come back to this later when I have more time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I'd kinda assumed that CMake-quoting was a bit like shell-quoting, where only the outer-most quote characters matter? So I was assuming that:

message("Setting FREERTOS_KERNEL_PATH to '${FREERTOS_KERNEL_PATH}' based on location of FreeRTOS-Kernel-import.cmake")

would result in e.g. Setting FREERTOS_KERNEL_PATH to 'C:\Program Files' based on location of FreeRTOS-Kernel-import.cmake, but perhaps CMake is more complicated than that? 🤷 (I'm not very familiar with CMake myself)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the wait. Yep, confirmed that it's fine, so I've updated the file accordingly.

@lurch
Copy link
Contributor

lurch commented Mar 6, 2025

@TankedThomas
Copy link
Author

Okay, latest commit should mean this is ready to merge. Only question left is whether we should keep double quotes for PICO_SDK_VERSION_MAJOR and CMAKE_VERSION (would make it more consistent) or remove them (since they're not necessary). I can make another commit to change this before merge if required.
If necessary, I can make pull requests for upstream afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants