Works for me.You can try it. Afterwards, run cmake in a command prompt from the same directory the *.cmake file resides. The cmake file should print a message if the `if` branch is taken.I found it doesn't, which lead to this question.Code:
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")endif ()
This is my 'CMakeLists.txt' file in full, basically your code with a 'project' item added to stop CMake complaints of it not being present, and an "[XYZZY]" added to the message to prove it is my message and not anything else CMake may produce -
Code:
project(test)if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) message("[XYZZY] Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")endif ()
Code:
pi@Pi3B:/tmp $ cmake .[XYZZY} Using PICO_SDK_PATH from environment ('/home/pi/pico/pico-sdk')-- Configuring done-- Generating done-- Build files have been written to: /tmppi@Pi3B:/tmp $
Code:
c:\Tmp>cmake .[XYZZY] Using PICO_SDK_PATH from environment ('C:\Program Files\Raspberry Pi\Pico SDK v1.5.1\pico-sdk')-- Configuring done-- Generating done-- Build files have been written to: C:/Tmpc:\Tmp>
Code:
c:\Tmp>echo %PICO_SDK_PATH%C:\Program Files\Raspberry Pi\Pico SDK v1.5.1\pico-sdk
I would suggest adding these two lines to your CMake file and report what they show -
Code:
message("[1] >>>${PICO_SDK_PATH}<<<")message("[2] >>>$ENV{PICO_SDK_PATH}<<<")
Code:
[1] >>><<<[2] >>>C:\Program Files\Raspberry Pi\Pico SDK v1.5.1\pico-sdk<<<
Perhaps the reason you don't see it working is that the '.cmake' file is never invoked ? If it isn't you won't ever see the message inside your 'if' test.
But my money would be on having a 'set(PICO_SDK_PATH ....)' somewhere in your 'CMakeLists.txt' or a '.cmake' you are using.
Or you are using VS Code and have configured 'PICO_SDK_PATH' in the 'CMake Tools' extension.
Or your VS Code isn't running with the same environment variable settings as when you are at the command line.
Or VS Code has got confused and isn't using those environment variables - I had that happen to me.
What actual problem did you encounter which set you off on your adventure ?
Statistics: Posted by hippy — Wed Mar 06, 2024 2:45 pm