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

picotool 2.0.0 executable is not found during cmake -G

Open shabaz123 opened this issue 6 months ago • 9 comments

Environment: Windows 11, SDK 2.0.0, trying to build a project for the Pico.

The issue is that when trying to perform a cmake -G "NMake Makefiles" .. or cmake -G "Ninja" .. there is a message that picotool is not found and will be built from source.

If the user already has a v2.0.0 picotool executable, it is not detected by the pico-sdk/tools/Findpicotool.cmake file.

I cannot use the Pico Setup for Windows installer, because that is version 1.5.

I believe I have a solution (also described at raspberrypi forum here). The solution is to place the prebuilt picotool.exe into any desired folder, and then set a Windows System environment variable called PICOTOOL_OVERRIDE_DIR to that folder path which contains picotool.exe.

Then, I added the following into the pico-sdk/tools/Findpicotool.cmake file, at the top (after the cmake_minimum_required(VERSION 3.17) line:

# if PICOTOOL_OVERRIDE_DIR system environment variable is set,
# then use that as the folder for the picotool executable
if (DEFINED ENV{PICOTOOL_OVERRIDE_DIR})
    message("PICOTOOL_OVERRIDE_DIR env var is set to '$ENV{PICOTOOL_OVERRIDE_DIR}'")
    add_executable(picotool IMPORTED GLOBAL)
    set_property(TARGET picotool PROPERTY IMPORTED_LOCATION $ENV{PICOTOOL_OVERRIDE_DIR}/picotool)
    # check the picotool version:
    execute_process(COMMAND $ENV{PICOTOOL_OVERRIDE_DIR}/picotool version
                    OUTPUT_VARIABLE PICOTOOL_VERSION
                    OUTPUT_STRIP_TRAILING_WHITESPACE)
    string(REGEX MATCH "^picotool v${picotool_VERSION_REQUIRED}" PICOTOOL_VERSION_MATCH ${PICOTOOL_VERSION})
    if (NOT PICOTOOL_VERSION_MATCH)
        message("picotool version response was: ${PICOTOOL_VERSION}")
        message(FATAL_ERROR "PICOTOOL_OVERRIDE_DIR is set to '$ENV{PICOTOOL_OVERRIDE_DIR}', but the version of picotool found is not ${picotool_VERSION_REQUIRED}")
    endif()
endif ()

What the above does, is if the PICOTOOL_OVERRIDE_DIR system env var is set, it uses the picotool executable in there, tests if it is the correct version, and if so, then simply uses that.

I have tested by doing a build, and can see that the .uf2 file was successfully created. I have attached the output showing that.

In case it is acceptable, I'll create a PR and reference this issue.

nmake_output.txt cmake_g_nmake_makefile_output.txt

shabaz123 avatar Aug 14 '24 17:08 shabaz123