kilograham
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 876
Joined: Fri Apr 12, 2019 11:00 am
Location: austin tx

Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

Sat Jul 24, 2021 4:22 pm

In a huge amount of code I see posted, I see people setting PICO_SDK_PATH in their CMakeLists.txt

The intentions that you NOT set it there (otherwise people will have to change it when they check out your project), but just include pico_sdk_import.cmake which takes care of the stuff below:

You can configure the location it via -DPICO_SDK_PATH to CMake (or set it in the appropriate section of your IDE), or it will be automatically picked up from the PICO_SDK_PATH environment variable when you run CMake. Is this not well documented? it does say effectively this in the README for the SDK here: https://github.com/raspberrypi/pico-sdk.

Same goes for PICO_EXTRAS_PATH / pico_extras_import.cmake (although that also looks for a sibling of your pico-sdk directory called pico-extras)

pidd
Posts: 2511
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

Sat Jul 24, 2021 4:55 pm

So is the recommendation not to have the following in your .bashrc file?

Code: Select all

export PICO_SDK_PATH=/home/pi/pico/pico-sdk
export PICO_EXAMPLES_PATH=/home/pi/pico/pico-examples
export PICO_EXTRAS_PATH=/home/pi/pico/pico-extras
export PICO_PLAYGROUND_PATH=/home/pi/pico/pico-playground
The sdk shell installer added those (again) only recently

lurk101
Posts: 902
Joined: Mon Jan 27, 2020 2:35 pm
Location: Cumming, GA (US)

Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

Sat Jul 24, 2021 5:13 pm

pidd wrote:
Sat Jul 24, 2021 4:55 pm
So is the recommendation not to have the following in your .bashrc file?

Code: Select all

export PICO_SDK_PATH=/home/pi/pico/pico-sdk
export PICO_EXAMPLES_PATH=/home/pi/pico/pico-examples
export PICO_EXTRAS_PATH=/home/pi/pico/pico-extras
export PICO_PLAYGROUND_PATH=/home/pi/pico/pico-playground
The sdk shell installer added those (again) only recently
I would think that having those symbols defined externally would make CMakeLists files more portable.

But yeah, I've had to delete a few duplicate exports from .bashrc after a second SDK install. The only time that was needed was for the 1.2 upgrade.

hippy
Posts: 10554
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

Sat Jul 24, 2021 5:34 pm

kilograham wrote:
Sat Jul 24, 2021 4:22 pm
In a huge amount of code I see posted, I see people setting PICO_SDK_PATH in their CMakeLists.txt
Perhaps the question to ask is; why are people doing this ?

It is, as you say, what is recommended, is very clearly stated and documented. Yet some have chosen to go against that recommendation.

ejolson
Posts: 8065
Joined: Tue Mar 18, 2014 11:47 am

Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

Sat Jul 24, 2021 5:44 pm

hippy wrote:
Sat Jul 24, 2021 5:34 pm
kilograham wrote:
Sat Jul 24, 2021 4:22 pm
In a huge amount of code I see posted, I see people setting PICO_SDK_PATH in their CMakeLists.txt
Perhaps the question to ask is; why are people doing this ?

It is, as you say, what is recommended, is very clearly stated and documented. Yet some have chosen to go against that recommendation.
I did it by following the principle of most local competent authority.
  • An environment variable defined at login ends up everywhere. That does not seem local enough.
    • Defining the variable on the command line for each build does not appear competent to me.
    If the SDK were installed in a standard location on all computers, for example /opt/pico-sdk, then CMakeLists.txt would not have to be edited by hand to work. That would be my preferred solution.

    hippy
    Posts: 10554
    Joined: Fri Sep 09, 2011 10:34 pm
    Location: UK

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sat Jul 24, 2021 6:45 pm

    There was only one driving force for me -

    1) It means one less file in my source directories.

    But plenty of reasons to justify doing it -

    1) I prefer it that way.

    2) It works.

    3) I don't have the time or resources to expend on finding out if there is some other way to achieve the same.

    4) It will work without problem for others if they followed the recommendation to place Pico SDK and related things under the '~/pico' directory

    5) It's easy enough for those who haven't followed the recommendation to change it if they need to.

    6) It works even if the PICO_SDK_PATH environment variable isn't set or is set wrong.

    7) If it doesn't work for a user it's easier to ask if the SDK is where I expect it to be rather then to ask how PICO_SDK_PATH is defined and if the SDK is there.

    8) I get to decide how I will do things.

    9) Users don't get to dictate what they are given.

    kilograham
    Raspberry Pi Engineer & Forum Moderator
    Raspberry Pi Engineer & Forum Moderator
    Posts: 876
    Joined: Fri Apr 12, 2019 11:00 am
    Location: austin tx

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sat Jul 24, 2021 7:43 pm

    pidd wrote:
    Sat Jul 24, 2021 4:55 pm
    So is the recommendation not to have the following in your .bashrc file?

    Code: Select all

    export PICO_SDK_PATH=/home/pi/pico/pico-sdk
    export PICO_EXAMPLES_PATH=/home/pi/pico/pico-examples
    export PICO_EXTRAS_PATH=/home/pi/pico/pico-extras
    export PICO_PLAYGROUND_PATH=/home/pi/pico/pico-playground
    
    The sdk shell installer added those (again) only recently
    that is 100% not what i said. putting them in your environment is fine

    pica200
    Posts: 281
    Joined: Tue Aug 06, 2019 10:27 am

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sat Jul 24, 2021 7:45 pm

    I guess i'm guilty. But i manually specify the path in pico_sdk_import.cmake. For me it's lazyness and i keep this bodge in mind. If i make my code public i will remove the bodge but unfortunately not everyone does.

    I second the idea of defining a standard location like "/opt/raspberrypi/pico-sdk".

    kilograham
    Raspberry Pi Engineer & Forum Moderator
    Raspberry Pi Engineer & Forum Moderator
    Posts: 876
    Joined: Fri Apr 12, 2019 11:00 am
    Location: austin tx

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sat Jul 24, 2021 7:55 pm

    I'm only making a suggestion (you don't have to do what I say), i only brought it up to hopefully make it easier for people to share their code.

    A few points about the "recommended way" i.e. copy pico_sdk_import.cmake into your project

    1) if PICO_SDK_PATH is not set, or set incorrectly you get an actually helpful error message with instructions
    2) IDEs or the cmake cache will remember the value for you anyway
    3) Storing one (fairly obviously explicit) variable in your environment does not seem like much of a hardship if that's the way you want to go (the variable is explicit and doesn't likely interfere with other things)
    4) FYI for those wary of time/effort seeking the information, it is in the (small) README in the root directory of the SDK.

    lurk101
    Posts: 902
    Joined: Mon Jan 27, 2020 2:35 pm
    Location: Cumming, GA (US)

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sat Jul 24, 2021 8:51 pm

    pica200 wrote:
    Sat Jul 24, 2021 7:45 pm
    I guess i'm guilty. But i manually specify the path in pico_sdk_import.cmake. For me it's lazyness and i keep this bodge in mind. If i make my code public i will remove the bodge but unfortunately not everyone does.

    I second the idea of defining a standard location like "/opt/raspberrypi/pico-sdk".
    Ah, but do that and others will insist it should be in /usr/local

    hippy
    Posts: 10554
    Joined: Fri Sep 09, 2011 10:34 pm
    Location: UK

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sun Jul 25, 2021 6:06 pm

    lurk101 wrote:
    Sat Jul 24, 2021 8:51 pm
    pica200 wrote:
    Sat Jul 24, 2021 7:45 pm
    I second the idea of defining a standard location like "/opt/raspberrypi/pico-sdk".
    Ah, but do that and others will insist it should be in /usr/local
    Some would say either would be better than '~/pico/pico-sdk'.

    jamesh
    Raspberry Pi Engineer & Forum Moderator
    Raspberry Pi Engineer & Forum Moderator
    Posts: 29345
    Joined: Sat Jul 30, 2011 7:41 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sun Jul 25, 2021 8:16 pm

    hippy wrote:
    Sun Jul 25, 2021 6:06 pm
    lurk101 wrote:
    Sat Jul 24, 2021 8:51 pm
    pica200 wrote:
    Sat Jul 24, 2021 7:45 pm
    I second the idea of defining a standard location like "/opt/raspberrypi/pico-sdk".
    Ah, but do that and others will insist it should be in /usr/local
    Some would say either would be better than '~/pico/pico-sdk'.
    And what about Windows? Not renowned for having either of those folders....

    Remember this is all multi platform stuff.
    Principal Software Engineer at Raspberry Pi (Trading) Ltd.
    Working in the Applications Team.

    hippy
    Posts: 10554
    Joined: Fri Sep 09, 2011 10:34 pm
    Location: UK

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Sun Jul 25, 2021 9:43 pm

    Windows apps and utilities would usually install under "Program Files".

    Another option is under "Documents and Settings" particularly something installed for a specific user rather than installed for everyone.

    A good guide to what one should perhaps be doing on Windows is to see what installing Windows versions of "cmake", "make", the ARM compilers, does, where it puts them.

    Installing to 'C:\pico\pico-sdk' is perfectly fine by me but it did feel rather old school, something everyone else left behind ages ago.

    lurk101
    Posts: 902
    Joined: Mon Jan 27, 2020 2:35 pm
    Location: Cumming, GA (US)

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Mon Jul 26, 2021 3:26 am

    hippy wrote:
    Sun Jul 25, 2021 6:06 pm
    lurk101 wrote:
    Sat Jul 24, 2021 8:51 pm
    pica200 wrote:
    Sat Jul 24, 2021 7:45 pm
    I second the idea of defining a standard location like "/opt/raspberrypi/pico-sdk".
    Ah, but do that and others will insist it should be in /usr/local
    Some would say either would be better than '~/pico/pico-sdk'.
    Some would. On the other hand having it in your home directory has it's advantages.

    pico-sdk, pico-examples, and that other one are git repos. You can manipulate them as such. I do checkouts, create new branches, commits, etc as a normal user. No need to sudo all the time.

    ejolson
    Posts: 8065
    Joined: Tue Mar 18, 2014 11:47 am

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Mon Jul 26, 2021 6:01 pm

    lurk101 wrote:
    Mon Jul 26, 2021 3:26 am
    hippy wrote:
    Sun Jul 25, 2021 6:06 pm
    lurk101 wrote:
    Sat Jul 24, 2021 8:51 pm

    Ah, but do that and others will insist it should be in /usr/local
    Some would say either would be better than '~/pico/pico-sdk'.
    Some would. On the other hand having it in your home directory has it's advantages.

    pico-sdk, pico-examples, and that other one are git repos. You can manipulate them as such. I do checkouts, create new branches, commits, etc as a normal user. No need to sudo all the time.
    In case it makes a difference, rather than leaving the SDK in ~/work/pico/pico-sdk where it might get damaged by user error or supply-chain hackers, I've now installed it in /usr/local/pico-sdk. If it weren't for the smoke from the fires, I'd be sleeping much better now that the SDK is safe from any of my clumsy attempts to fix atexit.

    It would be nice if there were a Raspberry Pi OS meta package such that

    apt install pico-dev

    would install the cross compiler, the SDK and keep them up to date. If fact, the reason I placed pico-sdk in /usr/local for now is in hope of such a package.

    jamesh
    Raspberry Pi Engineer & Forum Moderator
    Raspberry Pi Engineer & Forum Moderator
    Posts: 29345
    Joined: Sat Jul 30, 2011 7:41 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Mon Jul 26, 2021 6:15 pm

    ejolson wrote:
    Mon Jul 26, 2021 6:01 pm
    lurk101 wrote:
    Mon Jul 26, 2021 3:26 am
    hippy wrote:
    Sun Jul 25, 2021 6:06 pm

    Some would say either would be better than '~/pico/pico-sdk'.
    Some would. On the other hand having it in your home directory has it's advantages.

    pico-sdk, pico-examples, and that other one are git repos. You can manipulate them as such. I do checkouts, create new branches, commits, etc as a normal user. No need to sudo all the time.
    In case it makes a difference, rather than leaving the SDK in ~/work/pico/pico-sdk where it might get damaged by user error or supply-chain hackers, I've now installed it in /usr/local/pico-sdk. If it weren't for the smoke from the fires, I'd be sleeping much better now that the SDK is safe from any of my clumsy attempts to fix atexit.

    It would be nice if there were a Raspberry Pi OS meta package such that

    apt install pico-dev

    would install the cross compiler, the SDK and keep them up to date. If fact, the reason I placed pico-sdk in /usr/local for now is in hope of such a package.
    You can install it where you want, just ensure that the PICO_SDK_PATH points at it and Bob is your veritable uncle. I just stuff it in a project folder somewhere in home, not likely to damage it with user error, and not sure supply chain hackery is anything to worry about.
    Principal Software Engineer at Raspberry Pi (Trading) Ltd.
    Working in the Applications Team.

    lurk101
    Posts: 902
    Joined: Mon Jan 27, 2020 2:35 pm
    Location: Cumming, GA (US)

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Mon Jul 26, 2021 9:49 pm

    ejolson wrote:
    Mon Jul 26, 2021 6:01 pm
    If it weren't for the smoke from the fires, I'd be sleeping much better now that the SDK is safe from any of my clumsy attempts to fix atexit.
    Git was already keeping you safe.

    User avatar
    nick.mccloud
    Posts: 1280
    Joined: Sat Feb 04, 2012 4:18 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Tue Jul 27, 2021 9:29 pm

    ejolson wrote:
    Mon Jul 26, 2021 6:01 pm
    It would be nice if there were a Raspberry Pi OS meta package such that

    apt install pico-dev

    would install the cross compiler, the SDK and keep them up to date. If fact, the reason I placed pico-sdk in /usr/local for now is in hope of such a package.
    What's wrong with:

    Code: Select all

    wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh
    chmod +x pico_setup.sh
    ./pico_setup.sh
    ????
    Pico/RP2040 ≠ Arduino
    Pico = hot rod kit car, Arduino = hot rod kit car wrapped in cotton wool with buoyancy aids & parachute

    ejolson
    Posts: 8065
    Joined: Tue Mar 18, 2014 11:47 am

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Tue Jul 27, 2021 10:25 pm

    nick.mccloud wrote:
    Tue Jul 27, 2021 9:29 pm
    ejolson wrote:
    Mon Jul 26, 2021 6:01 pm
    It would be nice if there were a Raspberry Pi OS meta package such that

    apt install pico-dev

    would install the cross compiler, the SDK and keep them up to date. If fact, the reason I placed pico-sdk in /usr/local for now is in hope of such a package.
    What's wrong with:

    Code: Select all

    wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh
    chmod +x pico_setup.sh
    ./pico_setup.sh
    ????
    While that works, since Raspberry Pi OS is developed by the same company that created the Pico, I expected tighter integration between the two products. If that were the case, then

    $ sudo apt update
    $ sudo apt full-upgrade

    could be used to keep everything including the SDK up to date.

    It's obviously not a big deal.
    Last edited by ejolson on Tue Jul 27, 2021 10:58 pm, edited 1 time in total.

    pidd
    Posts: 2511
    Joined: Fri May 29, 2020 8:29 pm
    Location: Wirral, UK
    Contact: Website

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Tue Jul 27, 2021 10:57 pm

    I guess they realised there would/will be frequent updates at the beginning and maintaining an apt package would only slow things down.

    Maybe it will go that way in the future when it has stabilised - or maybe not.

    Installation and updating is reasonably tidy as it is, it isn't on my curse list - I've seen a lot worse.

    User avatar
    nick.mccloud
    Posts: 1280
    Joined: Sat Feb 04, 2012 4:18 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Tue Jul 27, 2021 11:01 pm

    ejolson wrote:
    Tue Jul 27, 2021 10:25 pm
    If that were the case, then

    $ sudo apt update
    $ sudo apt full-upgrade

    could be used to keep everything including the SDK up to date.
    :roll:
    Pico/RP2040 ≠ Arduino
    Pico = hot rod kit car, Arduino = hot rod kit car wrapped in cotton wool with buoyancy aids & parachute

    jamesh
    Raspberry Pi Engineer & Forum Moderator
    Raspberry Pi Engineer & Forum Moderator
    Posts: 29345
    Joined: Sat Jul 30, 2011 7:41 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Wed Jul 28, 2021 8:50 am

    ejolson wrote:
    Tue Jul 27, 2021 10:25 pm
    nick.mccloud wrote:
    Tue Jul 27, 2021 9:29 pm
    ejolson wrote:
    Mon Jul 26, 2021 6:01 pm
    It would be nice if there were a Raspberry Pi OS meta package such that

    apt install pico-dev

    would install the cross compiler, the SDK and keep them up to date. If fact, the reason I placed pico-sdk in /usr/local for now is in hope of such a package.
    What's wrong with:

    Code: Select all

    wget https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh
    chmod +x pico_setup.sh
    ./pico_setup.sh
    ????
    While that works, since Raspberry Pi OS is developed by the same company that created the Pico, I expected tighter integration between the two products. If that were the case, then

    $ sudo apt update
    $ sudo apt full-upgrade

    could be used to keep everything including the SDK up to date.

    It's obviously not a big deal.
    We did consider this, but there are downsides which meant we were not happy with it as the main install process.
    Principal Software Engineer at Raspberry Pi (Trading) Ltd.
    Working in the Applications Team.

    User avatar
    nick.mccloud
    Posts: 1280
    Joined: Sat Feb 04, 2012 4:18 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Wed Jul 28, 2021 9:11 am

    jamesh wrote:
    Wed Jul 28, 2021 8:50 am
    ejolson wrote:
    Tue Jul 27, 2021 10:25 pm
    $ sudo apt update
    $ sudo apt full-upgrade

    could be used to keep everything including the SDK up to date.

    It's obviously not a big deal.
    We did consider this, but there are downsides which meant we were not happy with it as the main install process.
    Just in case anyone is wondering, there is nothing like the joy of having TWO update mechanisms to document and support. And a Git Pull is almost test free, whereas packaging for a .deb would really need testing as well.
    Pico/RP2040 ≠ Arduino
    Pico = hot rod kit car, Arduino = hot rod kit car wrapped in cotton wool with buoyancy aids & parachute

    jamesh
    Raspberry Pi Engineer & Forum Moderator
    Raspberry Pi Engineer & Forum Moderator
    Posts: 29345
    Joined: Sat Jul 30, 2011 7:41 pm

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Wed Jul 28, 2021 10:24 am

    nick.mccloud wrote:
    Wed Jul 28, 2021 9:11 am
    jamesh wrote:
    Wed Jul 28, 2021 8:50 am
    ejolson wrote:
    Tue Jul 27, 2021 10:25 pm
    $ sudo apt update
    $ sudo apt full-upgrade

    could be used to keep everything including the SDK up to date.

    It's obviously not a big deal.
    We did consider this, but there are downsides which meant we were not happy with it as the main install process.
    Just in case anyone is wondering, there is nothing like the joy of having TWO update mechanisms to document and support. And a Git Pull is almost test free, whereas packaging for a .deb would really need testing as well.
    That is certainly one of the downsides. Time to make apt's, and keep them up to date is not insignificant, and the results is actually not as flexible as just have a git pull (e.g. how do you grab a different branch?). When you are such a small team, these are all things that need to be considered.
    Principal Software Engineer at Raspberry Pi (Trading) Ltd.
    Working in the Applications Team.

    hippy
    Posts: 10554
    Joined: Fri Sep 09, 2011 10:34 pm
    Location: UK

    Re: Setting PICO_SDK_PATH in your CMakeLists.txt (hint: dont)

    Wed Jul 28, 2021 11:23 am

    nick.mccloud wrote:
    Wed Jul 28, 2021 9:11 am
    jamesh wrote:
    Wed Jul 28, 2021 8:50 am
    ejolson wrote:
    Tue Jul 27, 2021 10:25 pm
    $ sudo apt update
    $ sudo apt full-upgrade

    could be used to keep everything including the SDK up to date.

    It's obviously not a big deal.
    We did consider this, but there are downsides which meant we were not happy with it as the main install process.
    Just in case anyone is wondering, there is nothing like the joy of having TWO update mechanisms to document and support. And a Git Pull is almost test free, whereas packaging for a .deb would really need testing as well.
    Here's the $64K question; should users bear the inconvenience of making things easier for the vendor or should the vendor bear the inconvenience of making things easier for the users ?

    Return to “SDK”