0

I am developing program for Raspberry Pi Pico. I am using Raspberry Pi Pico C/C++ SDK which uses cmake to build project.

I am developing the program on both Windows machine and on Raspberry Pi 4 (Linux).

In my CMakeLists.txt I wish to programmatically switch the PICO_SDK_PATH depending on type of machine I am using.

Windows Path

set(PICO_SDK_PATH "C:/Pico/pico-sdk")

Linux (Raspbian on raspberry Pi 4) Path

set(PICO_SDK_PATH "/home/xxx/Pico/pico-sdk")

I wish to do something like

#ifdef _Windows //depening on development machine
   set(PICO_SDK_PATH "C:/Pico/pico-sdk")
#else
   set(PICO_SDK_PATH "/home/xxx/Pico/pico-sdk")

How can I achieve the same.

Dark Sorrow
  • 1,681
  • 14
  • 37
  • Not familiat with this pico sdk, but depending on the functionality it provides a find/package configuration script could be appropriate (to allow using `find_package` to locate the files). Maybe those files even exist already. Usually hardcoding paths that are not part of your project is not a good idea: If you ever want to build the project on a machine where the sdk is installed at `/home/yyy/Pico/pico-sdk` you cannot do so without modifying your project. I recommend passing this kind of option via `-D` option during cmake configuration (or preferably going with the cmake config script). – fabian Aug 19 '22 at 16:55

1 Answers1

2

On Windows, the WIN32 CMake variable is defined. You can use something like the following to set the variable:

if(WIN32)
  set(PICO_SDK_PATH "C:/Pico/pico-sdk")
else()
  set(PICO_SDK_PATH "/home/xxx/Pico/pico-sdk")
endif()
Lindydancer
  • 25,428
  • 4
  • 49
  • 68
  • This does exactly what the op asked for but ignores the fact that hardcoding those paths severely limits the scenarios where this project can be used: The sdk needs to be installed in a specific location and on linux you may not even have the permissions to create `/home/xxx`... – fabian Aug 19 '22 at 16:59
  • @fabian What is the alternative to hardcoding these paths in cmake? – Dark Sorrow Aug 21 '22 at 02:54
  • 1
    Passing the info in via cache variable during configuration or possibly even using `find_package`... If there"s a standard set of machines you're working with the values could be hardcoded into `CMakeUserPresets.json`. – fabian Aug 21 '22 at 08:32