-
Notifications
You must be signed in to change notification settings - Fork 1.1k
pico-sdk 2.1.0 Downloading Picotool runs always upon repeated CMake calls #2308
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
Comments
I think you’re misunderstanding how CMake works - the You do not need to manually build picotool using the picotoolBuild target - it will be automatically built as a dependency when you build your SDK project (ie when you run Alternatively, if you just want to run The best solution would be to follow the advice in the warning and build & install picotool separately systemwide - that way you’ll never be annoyed by “Downloading Picotool” again. |
Thanks, @will-v-pi :
I think my misunderstanding comes from not applying the configuration nature of CMake to build dependencies (and I consider picotool in this case to be a build dependency); otherwise I was of course aware that CMake only does configuration on the level of a project - and then I'd have to call the build tool, here I guess being in a situation of calling CMake multiple times in a row (without calling
Yeah - for some reason I lost this from sight, in spite of this not being the first time I compile a pico-sdk project with CMake.
Ok, I have to agree with this; I guess I only noticed this to begin with because of being put in a situation to run CMake multiple times in a row (to fix bugs in my modifications of
Nice - this seems like a decent workaround, if you need to run CMake multiple times (for instance to fix bugs or inspect variable values in a
I guess I thought that having separate versions of picotool for each project appealed to me, because projects would appear more isolated from each other, and plus I try to "install" source projects as rarely as possible (I either use package manager, or if building some tool from source, I try to call it with absolute path with the possible LD_LIBRARY_PATH and such - not sure where I picked up that habit) Anyways, thanks for helping me put things in perspective - I guess now I realize I don't really have much to ask for in this case, so I'll be closing this. |
I also arrived at a This is done by creating a "dummy" directory with
Otherwise, I think it works, because in the end, a Here is modified cmake_minimum_required(VERSION 3.13)
message("\n### prebuild picotool vvvvvvvvvv\n")
# https://crascit.com/2022/01/25/quoting-in-cmake/
file(WRITE ${CMAKE_BINARY_DIR}/pbptest/CMakeLists.txt [=[
cmake_minimum_required(VERSION 3.13...3.27)
include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake)
project(pbptest)
pico_sdk_init()
pico_init_picotool()
]=])
file(TOUCH ${CMAKE_BINARY_DIR}/pbptest/main.c)
message("Created ${CMAKE_BINARY_DIR}/pbptest/{CMakeLists.txt,main.c}")
message("Running `cmake -S pbptest -B . -G '${CMAKE_GENERATOR}'` in ${CMAKE_BINARY_DIR}")
execute_process(
COMMAND ${CMAKE_COMMAND} -S pbptest -B . -G ${CMAKE_GENERATOR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
message("Running `make picotoolBuild` in ${CMAKE_BINARY_DIR}")
execute_process(
COMMAND ${CMAKE_COMMAND} --build . --target picotoolBuild
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
execute_process(
COMMAND find . -name picotool*
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
message("Running `rm CMakeCache.txt` in ${CMAKE_BINARY_DIR} (for rest of original CMakeLists.txt)")
file(REMOVE "${CMAKE_BINARY_DIR}/CMakeCache.txt")
message("Running `rm -rf pbptest` in ${CMAKE_BINARY_DIR} (cleanup)")
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/pbptest")
message("\n### end prebuild picotool ^^^^^^\n")
# initialize the SDK directly
include($ENV{PICO_SDK_PATH}/pico_sdk_init.cmake)
project(my_project)
# initialize the Raspberry Pi Pico SDK
pico_sdk_init()
# rest of your project
add_executable(hello_world
main.c
)
# Add pico_stdlib library which aggregates commonly used features
target_link_libraries(hello_world pico_stdlib)
# create map/bin/hex/uf2 file in addition to ELF.
pico_add_extra_outputs(hello_world) And here is the output: cmake and make log (click to expand)
|
If you want to be able to use a "local" version of |
Thanks @lurch :
I had already seen
... and I couldn't parse - is that Finally got that resolved after perceiving https://github.com/raspberrypi/pico-sdk/blob/2.1.0/tools/Findpicotool.cmake#L78
so, indeed, |
https://github.com/raspberrypi/picotool?tab=readme-ov-file#usage-by-the-raspberry-pi-pico-sdk 😉 |
I noticed the same problem as in #2081 using pico-sdk 2.1.0.
Sometimes (like these days) I end up in a situation that where I exclusively work on CMakeLists.txt, and I have to run
cmake
multiple times - and that is how I managed up end up irritated with this: because every time I run CMake, I get this "Downloading Picotool"! (Even worse, I work with a structure with multiple subfolders inside./build
, so every time I runcmake
(even when I run that command repeatedly after each other), I have to see through multiple times "Downloading Picotool" !!Also, now that I see "Downloading Picotool" which ends up in my project, I'd prefer using that downloaded
picotool
locally for my project.I would argue that this is a documentation problem, because nowhere in https://github.com/raspberrypi/picotool/blob/develop/README.md#usage-by-the-raspberry-pi-pico-sdk (or #2081) is neither implied nor explicitly stated, that if I get "Downloading Picotool" during CMake configuration, and I choose to use that downloaded one in my project, I have to build it myself manually. Also, I'd like a method to have this build done automatically (have a comment on this at end)
Here is an example to demonstrate (note, done in MINGW64 (MSYS2)
bash
shell of Windows 10):main.c
right from the README.mdCMakeLists.txt
also right from the README.mdI put these in
/tmp/test
, then I setup to run CMake:OK, so I've got the "Downloading Picotool" message, and apparently I've got
picotool
downloaded in my project build folder now? Let's check:So, we got a bunch of files and directories with "picotool" in the name - however, no
.exe
files, and onlypicotoolConfig.cmake
is present.Let's run
cmake
again:Oh, damn it - there it is, "Downloading Picotool" again! So picotool may have been downloaded, but it was never built!
Ok, so how do we build it? Turns out, in the
Makefile
that thiscmake
run produces, there is a targetpicotoolBuild
- so, as I'm still in the./build
subfolder, let's try it:Ah - that's more like it; note also at end of
make picotoolBuild
, we got a message "Install the project".Let's now check what sort of
picotool*
files we got in the./build
subfolder:Ahh, finally:
picotool.exe
,picotoolConfig.cmake
andpicotoolTargets.cmake
are all present.And now, if we run CMake for a third time:
... finally, there is no "Downloading Picotool" step anymore!
So, in order to get the build process to use the
picotool
obtained by the "Downloading Picotool" CMake step, I had to buildpicotool
myself, by manually issuing themake picotoolBuild
command.Now, I would prefer NOT having to do this manual build of
picotool
- instead, I'd prefer setting up something in my project'sCMakeLists.txt
, so that ifcmake
is ran from an empty./build
subfolder (or generally, a build state which triggers the "Downloading Picotool" step), thenpicotool
should be automatically built right after the "Downloading Picotool" step - so I never see (and wait for) this step again if I have to runcmake
again afterwards.I'm aware that "Downloading Picotool" comes from Findpicotool.cmake, which is triggered by the CMake function
pico_init_picotool()
in pico-sdk/tools/CMakeLists.txt.So, I thought that I could somehow force a call to
make picotoolBuild
from my own project'sCMakeLists.txt
at start (so all the other points in myCMakeLists.txt
that would otherwise trigger "Downloading Picotool" would see the builtpicotool
, and avoid running the download unnecessarily) - provided I callpico_init_picotool()
beforehand. However, https://stackoverflow.com/questions/79452002/force-cmake-to-generate-build-files-makefile-at-arbitrary-point-in-cmakelists implies that such an approach would not really be possible.So, what other options do I have, to setup the CMake configuration -- so that
picotool
gets automatically built, right after the very first time "Downloading Picotool" is triggered?The text was updated successfully, but these errors were encountered: